[gmx-developers] Where can I define a truly global variable?

Axel Kohlmeyer akohlmey at cmm.chem.upenn.edu
Thu Aug 2 16:46:39 CEST 2007


On Thu, 2 Aug 2007, Lee-Ping wrote:

dear lee-ping,

global variables are generally a very bad idea and 
should be avoided at all costs. ...and then there is 
the issue with parallel or multithreaded runs etc.

it is hard to tell where you are actually working on,
but gromacs has a number of structures that maintain
information about the (sub)system and i would first 
look into adding some entry into one of them.

the real gromacs experts (i'm just hacking it to make
it work on some exotic(?) machines) can probably give
you some better suggestions.

also you may want to consider putting your new feature
into a separate function instead of messing with the
(well tuned) innerloops. that will make the maintenance
of your code _much_ simpler, particularly, since it seems
that you are not so much worried about performance.

cheers,
   axel.

LP> Dear community,
LP> 
LP> I'm trying to add a feature to GROMACS which involves a variable being
LP> passed between all of the bonded and nonbonded force functions (in the same
LP> way that the total potential energy is passed).  I thought of increasing the
LP> number of variables with which each function is declared, but that leads to
LP> an immense amount of errors since each piece of code is intimately linked to
LP> so many others.  Currently I'm working around this problem by having each
LP> force function print numbers to a file, but this involves printf statements
LP> in the inner loops, which the program is not very happy about (it slows down
LP> considerably).  The other solution is to make the variable truly global, so
LP> I don't need to pass it between functions, but where would I declare a
LP> variable so global that I can, for example, call it from
LP> nonbonded_kernel330_c.c if I declared it in md.c or force.c?  Is this even
LP> possible?  If not, is there anywhere I can declare such a global variable
LP> (maybe in a .h file?)  Your input is appreciated.  Thanks,
LP> 
LP> - Lee-Ping, a novice programmer
LP> 
LP> _______________________________________________
LP> gmx-developers mailing list
LP> gmx-developers at gromacs.org
LP> http://www.gromacs.org/mailman/listinfo/gmx-developers
LP> Please don't post (un)subscribe requests to the list. Use the 
LP> www interface or send it to gmx-developers-request at gromacs.org.
LP> 

-- 
=======================================================================
Axel Kohlmeyer   akohlmey at cmm.chem.upenn.edu   http://www.cmm.upenn.edu
   Center for Molecular Modeling   --   University of Pennsylvania
Department of Chemistry, 231 S.34th Street, Philadelphia, PA 19104-6323
tel: 1-215-898-1582,  fax: 1-215-573-6233,  office-tel: 1-215-898-5425
=======================================================================
If you make something idiot-proof, the universe creates a better idiot.




More information about the gromacs.org_gmx-developers mailing list