[lammps-users] question on parallel programming

Hello everyone,

I have a general question on the way lammps is parallelized. For instance, from what I’ve seen in the code a general loop

for (int i = 1; i <= number; i++)
{
array[i] = i;
}

will be executed by all of the processors and the values of “array” will be owned by all of the processors. However, if the loop is written as:

MPI_Comm_rank(world,&me);
MPI_Comm_size(world,&nprocs);

mynum = number/nprocs;

mine = 1;
for (int i = me*mynum+1; i <= mynum; i++)
{
array[mine] = i;
mine++;
}

will every processor own a different version of “array” and each version will have “mynum” rows?

thanks
Jaime Sanchez

Hello everyone,

hello jaime,

I have a general question on the way lammps is parallelized. For instance,
from what I've seen in the code a general loop

for (int i = 1; i <= number; i++)
{
array[i] = i;
}

will be executed by all of the processors and the values of "array" will be
owned by all of the processors. However, if the loop is written as:

no! LAMMPS is parallelized with MPI which means a 'share nothing'
strategy. in this case every node will have an 'array' of the same
size and will operate on them in parallel.

MPI_Comm_rank(world,&me);
MPI_Comm_size(world,&nprocs);

mynum = number/nprocs;

mine = 1;
for (int i = me*mynum+1; i <= mynum; i++)
{
array[mine] = i;
mine++;
}

in this case, each processor will operate on a
smaller array (number/nprocs instead of number).

this is used for 'scattered' arrays. check out
any of the MPI tutorials around and look for
MPI_SCATTER and/or MPI_GATHER and MPI_REDUCE.

cheers,
  axel.

Hi Axel,

thanks for the prompt response. For the second case, if I wanted to collect all the arrays from each processor into one that had length “number” would this command be adequate?

MPI_Allgather(array,mynum,MPI_INT,array_all,number,MPI_INT,world);

The reason why I’m asking is because I actually have a similar situation as in the example 2 of my previous email, and I use MPI_Allgather to collect all the pieces of the array from each processor into one big array. When I print out the big array, all the rows are zero except for those owned by me = 0.

Thanks
Jaime

Hi Axel,

thanks for the prompt response. For the second case, if I wanted to collect
all the arrays from each processor into one that had length "number" would
this command be adequate?

MPI_Allgather(array,mynum,MPI_INT,array_all,number,MPI_INT,world);

The reason why I'm asking is because I actually have a similar situation as
in the example 2 of my previous email, and I use MPI_Allgather to collect
all the pieces of the array from each processor into one big array. When I
print out the big array, all the rows are zero except for those owned by me
= 0.

i would look carefully whether, a) the operation is actually performed
by all nodes (i.e. some parts of the code may only be executed on the
'me' node), or b) whether the information you use for computation has
been distributed across all nodes.

if you have limited experience with MPI, i would suggest to first
create something like a wrapper code around what you want to program
(just add some code to LAMMPS to dump the status of the relevant
variables/arrays to files and then write a minimal parallel code to
read in this information and program/debug what you want to do and
once it is working implant it back into LAMMPS.

cheers,
   axel.