python scatter in a atom variable SOLVED

Hi Steve,

I think I found a shortcoming in the scatter_atoms() (library.cpp)
coupling routine. This is why I got the problems with mpi computations.
To show that, I took a very simple example: after a few lammps step, I
compute an array of constant velocity in python v=0.005, and then
scatter_atoms() it to lammps.

   n3=3*natoms
   f=(n3*c_double)()

# Impulse

   if me == 0:

    for i in range(0,natoms):

       f[i*3]=0.005

       f[i*3+1]=0.005

       f[i*3+2]=0.005

   lmp.scatter_atoms("v",1,3,f)

When running in single processor the python program, the velocity is
correctly transmitted to all atoms. However, when I run a mpi
computation, for instance

mpiexec -np 4 plot.py in.lammps

Only the first processor eventually receive the scattered velocity (I
checked it with paraview afterwards)! The same stuff happens with my
scatter_property function (obviously because it is based on scatter_atoms())

I wonder it there is no need for a MPIAllreduce call at the end of the
scatter_atoms() routine to send data to all processor?...

Thanks,
Joris

I don't think there is any problem with the library function
scatter_atoms(). It does not need a MPI_Allreduce(). If
I modify and run the python/examples/demo script as
appended below, it gives the same answer on 1 and 4 procs,
which indicates that the velocities of all atoms have been
modified the same on 1 or 4 procs.

Steve

#!/usr/local/bin/python -i
# preceeding line should have path for Python on your machine

# demo.py
# Purpose: illustrate use of many library interface commands
# Syntax: demo.py
# uses in.demo as LAMMPS input script

import sys

# parse command line

argv = sys.argv
if len(argv) != 1:
  print "Syntax: demo.py"
  sys.exit()

me = 0
# uncomment if running in parallel via Pypar
import pypar
me = pypar.rank()
nprocs = pypar.size()

from lammps import lammps

lmp = lammps()

# test out various library functions after running in.demo

lmp.file("in.demo")

if me == 0: print "\nPython output:"

natoms = lmp.extract_global("natoms",0)
mass = lmp.extract_atom("mass",2)
x = lmp.extract_atom("x",3)
print "Natoms, mass, x[0][0] coord =",natoms,mass[1],x[0][0]

temp = lmp.extract_compute("thermo_temp",0,0)
print "Temperature from compute =",temp

eng = lmp.extract_variable("eng",None,0)
print "Energy from equal-style variable =",eng

vy = lmp.extract_variable("vy","all",1)
print "Velocity component from atom-style variable =",vy[1]

natoms = lmp.get_natoms()
print "Natoms from get_natoms =",natoms

#xc = lmp.gather_atoms("x",1,3)
v = lmp.gather_atoms("v",1,3)
#print "Global coords from gather_atoms =",xc[0],xc[1],xc[31]

#xc[0] = xc[0] + 1.0
#lmp.scatter_atoms("x",1,3,xc)

for i in xrange(natoms):
  v[3*i] = 100.0+i

lmp.scatter_atoms("v",1,3,v)

lmp.command("run 1");

#print "Changed x[0][0] via scatter_atoms =",x[0][0]

# uncomment if running in parallel via Pypar
print "Proc %d out of d procs has" (me,nprocs), lmp
pypar.finalize()

Ok, I found the problem: it was in the python code.
The scatter function was applied only on processor 0 (with if me==0), that's why.
Now ALL problems solved !

Jori