I will begin this post as I always do: I am a noob so I may describe things in a somewhat strange way… you have been warned :-)
A little bit of background: I am working in a research lab that is trying to model plant growth patterns using simple dynamical equations for plant biomass and nutrient and water concentration. When I came in they had all of their input variables scattered throughout about 500+ lines of code, some declared in multiple places (once for extern “C” and once for device functions). Being an engineer I couldn’t stand this, it seemed inefficient and too easy to forget to update all instances of a variable, so I pushed to have all the input variables put into a single header file that would be used by the host and device functions. The ultimate goal is to hve a header file initialize all of the variables, then have a .txt file that has their values so the model can be changed without remaking the source each time.
So I went through and moved ALL variables to a separate header file. This appeared to work, there were no complaints about variables not being initialized properly or whatnot. However, I noticed that the behavior of the code was not what we expected at all. It turned out that though the variables were being declared properly and given values, they were passing in null values to the functions. So I decided to take a step back and work on just one variable and make sure I fully understood what was happening before tackling all variables.
We have a variable called “ppt” which represents precipitation. It is used in one device function and one extern “C” function. I thought that declaring it in a header file as
__constant__ float ppt = 123.456;
would allow both functions to access it. In fact both could use it, but via a printf statement in the extern “C”, the value being passed in was ppt = 0.000000. I couldn’t get my cuPrintf to work, so I’m not sure what is being passed into the device function (that is another of my posts, it can be found here: http://forums.nvidia.com/index.php?showtopic=202551). Either way, it does not seem correct.
So I played around with different setups and I finally found that declaring two variables in a header file with the form
__device__ float dev_ppt = 123.456; float ppt = 123.456;
seemed to do the trick, the dynamics were working again. However, this messed up the graphics being displayed. BTW, we are using openGL for the graphics, I don’t know if that is pertinent to this issue or not. To figure out what the source of the issue was, I commented out the variable declarations in the header file and the functions themselves in turn to see at which point the graphics were messed up. It turned out that if I declare the host ppt in either place doesn’t make a difference, but declaring the device ppt in the header file is what caused the graphics to be strange. I tried using both device float and constant float and got the same results.
The correct graphics should look like this:
The messed up graphics are like this:
I tried to do a screen grab at about the same time, but as you can see the fps rate is pretty high, so don’t worry too much about the shade of orange that the dots are. The messed up part is that they look distorted, they should have clean, smooth edges.
Any ideas of what is going on and how to fix it? Also, any ideas on how to declare the variable once so the user doesn’t have to enter it twice? When I move things to a .txt file, this may become unimportant as I can just assign the same value from the text file to two separate variables in the code, but that doesn’t seem to be the best way about it…
Any help on this (or my other post) would be GREATLY appreciated!