[gmx-developers] using arrays of rvec[] (ie x, v, f, etc)
Nathan Moore
nmoore at physics.umn.edu
Tue Jul 5 18:33:46 CEST 2005
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?
NT Moore
> I'm working to rewrite the move_x/move_f functions to allow for the use of
> an MPI_AllgatherV on an IBM BlueGene system. I'm struggling at present
> with the definition of the x and f arrays as "rvec[]" or "real variables.
> The code below fails on compile with errors:
>
> "mvxvf.c", line 196.25: 1506-019 (S) Expecting an array or a pointer to
> object type.
> "mvxvf.c", line 197.25: 1506-019 (S) Expecting an array or a pointer to
> object type.
> "mvxvf.c", line 198.25: 1506-019 (S) Expecting an array or a pointer to
> object type.
>
> I assume that the compiler doesn't like how I'm copying the temp_x array
> back to the x array after the MPI_Allgatherv. Any suggestions as to how
> this section should be written?
>
> Also, I'd like to lose the malloc definition of temp_x, but I'm not sure
> if there's a #define'd size for that array. ie, I'd like to say
> statically at the beginning of this function,
> real temp_x[N_ATOMS]
> Is the problem size (NUM_ATOMS or similar) defined outside of the
> (nsb->natoms)?
>
> thanks,
>
> NT Moore
>
>
> void move_x(FILE * log,
> int left, int right, rvec x[], t_nsborder * nsb, t_nrnb * nrnb)
> {
> int i;
>
> int NT_status; /* Did the send work? */
>
> int array_length; /* length of the whole x array */
> array_length = DIM * (nsb->natoms);
>
> int start_element; /* index of where this node's array
> begins*/
> start_element = nsb->index[nsb->nodeid];
>
> /* The number of elements each node sends */
> int *num_sent = (int *) malloc((nsb->nnodes) * sizeof(int));
> for (i = 0; i < (nsb->nnodes); i++) {
> num_sent[i] = nsb->homenr[i];
> }
>
> /* The starting index of each node's block of elements */
> /* note the obvious redundancy that
> start_element==starting_block[nsb->nodeid] */
> int *starting_block = (int *) malloc((nsb->nnodes) * sizeof(int));
> for (i = 0; i < (nsb->nnodes); i++) {
> starting_block[i] = nsb->index[i];
> }
>
> /* The temporary array where x elements are gathered to */
> real *temp_x = (real *) malloc(array_length * sizeof(real));
>
> /* pass the x array around */
> NT_status = MPI_Allgatherv(&x[start_element],
> num_sent[nsb->nodeid],
> MPI_REAL,
> &temp_x[0],
> &num_sent[0],
> &starting_block[0],
> MPI_REAL, MPI_COMM_WORLD);
>
> /* update the x array with the gathered temp_x array */
> 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];
> }
>
> free(num_sent);
> free(starting_block);
> free(temp_x);
>
> }
>
> _______________________________________________
> gmx-developers mailing list
> gmx-developers at gromacs.org
> http://www.gromacs.org/mailman/listinfo/gmx-developers
> Please don't post (un)subscribe requests to the list. Use the
> www interface or send it to gmx-developers-request at gromacs.org.
>
More information about the gromacs.org_gmx-developers
mailing list