[gmx-developers] using arrays of rvec[] (ie x, v, f, etc)

Nathan Moore nmoore at physics.umn.edu
Tue Jul 5 21:11:34 CEST 2005


> On Tue, 5 Jul 2005, Nathan Moore wrote:
>
>>I've figured out a possible fix.  I've defined temp_x in the following
>> way,
>>
>>    rvec *temp_x = (rvec *) malloc(array_length * sizeof(rvec));
>>
>>and then copied the array contents with,
>>
>>for (i = 0; i < array_length; i++) {
>>        x[i][0] = temp_x[i][0];
>>        x[i][1] = temp_x[i][1];
>>        x[i][2] = temp_x[i][2];
>>    }
>>
>>Comments?
>
> It should be possible without any copying, if you do Nprocs MPI calls on
> array segments. Copying and mallocing will kill any gain in performnce.

Do you see an obvious way around the malloc?  I can't see a static
"num_atoms" value that will allow me to define the temp_x array
statically.  I could of course define external variables in the mvxvf.c
function:

   int temp_x_array_declared=0;
   rvec *temp_x;

and then inside the function delcare the array conditionally, ie

   extern int temp_x_array_declared;
   extern rvec *temp_x;
   if(!temp_x_array_declared) {
      rvec *temp_x = (rvec *) malloc(array_length * sizeof(rvec));
      temp_x_array_declared=1;
   }

but that starts to get really busy for anyone who wants to read the code
in the future.  Do you see another way around this malloc?

Nathan






More information about the gromacs.org_gmx-developers mailing list