Merge pull request #4197 from rbberger/library_interface_update
library: add comm->procgrid to extract_global
This commit is contained in:
@ -891,7 +891,7 @@ class lammps(object):
|
||||
# set length of vector for items that are not a scalar
|
||||
vec_dict = { 'boxlo':3, 'boxhi':3, 'sublo':3, 'subhi':3,
|
||||
'sublo_lambda':3, 'subhi_lambda':3, 'periodicity':3,
|
||||
'special_lj':4, 'special_coul':4 }
|
||||
'special_lj':4, 'special_coul':4, 'procgrid':3 }
|
||||
if name in vec_dict:
|
||||
veclen = vec_dict[name]
|
||||
elif name == 'respa_dt':
|
||||
|
||||
@ -796,18 +796,16 @@ class PyLammps(object):
|
||||
comm = {}
|
||||
comm['nprocs'] = self.lmp.extract_setting("world_size")
|
||||
comm['nthreads'] = self.lmp.extract_setting("nthreads")
|
||||
comm['proc_grid'] = comm['procgrid'] = self.lmp.extract_global("procgrid")
|
||||
idx = self.lmp.extract_setting("comm_style")
|
||||
comm['comm_style'] = ('brick', 'tiled')[idx]
|
||||
idx = self.lmp.extract_setting("comm_style")
|
||||
comm['comm_layout'] = ('uniform', 'nonuniform', 'irregular')[idx]
|
||||
comm['ghost_velocity'] = self.lmp.extract_setting("ghost_velocity") == 1
|
||||
|
||||
for line in output:
|
||||
if line.startswith("MPI library"):
|
||||
comm['mpi_version'] = line.split(':')[1].strip()
|
||||
elif line.startswith("Comm style"):
|
||||
parts = self._split_values(line)
|
||||
comm['comm_style'] = self._get_pair(parts[0])[1]
|
||||
comm['comm_layout'] = self._get_pair(parts[1])[1]
|
||||
elif line.startswith("Processor grid"):
|
||||
comm['proc_grid'] = [int(x) for x in self._get_pair(line)[1].split('x')]
|
||||
elif line.startswith("Communicate velocities for ghost atoms"):
|
||||
comm['ghost_velocity'] = (self._get_pair(line)[1] == "yes")
|
||||
return comm
|
||||
|
||||
def _parse_element_list(self, output):
|
||||
|
||||
@ -1198,14 +1198,31 @@ internally by the :doc:`Fortran interface <Fortran>` and are not likely to be us
|
||||
* - triclinic
|
||||
- 1 if the the simulation box is triclinic, 0 if orthogonal.
|
||||
See :doc:`change_box`.
|
||||
|
||||
**Communication status**
|
||||
|
||||
.. list-table::
|
||||
:header-rows: 1
|
||||
:widths: auto
|
||||
|
||||
* - Keyword
|
||||
- Description / Return value
|
||||
* - universe_rank
|
||||
- MPI rank on LAMMPS' universe communicator (0 <= universe_rank < universe_size)
|
||||
* - universe_size
|
||||
- Number of ranks on LAMMPS' universe communicator (world_size <= universe_size)
|
||||
* - world_rank
|
||||
- MPI rank on LAMMPS' world communicator (0 <= world_rank < world_size)
|
||||
- MPI rank on LAMMPS' world communicator (0 <= world_rank < world_size, aka comm->me)
|
||||
* - world_size
|
||||
- Number of ranks on LAMMPS' world communicator
|
||||
- Number of ranks on LAMMPS' world communicator (aka comm->nprocs)
|
||||
* - comm_style
|
||||
- communication style (0 = BRICK, 1 = TILED)
|
||||
* - comm_layout
|
||||
- communication layout (0 = LAYOUT_UNIFORM, 1 = LAYOUT_NONUNIFORM, 2 = LAYOUT_TILED)
|
||||
* - comm_mode
|
||||
- communication mode (0 = SINGLE, 1 = MULTI, 2 = MULTIOLD)
|
||||
* - ghost_velocity
|
||||
- whether velocities are communicated for ghost atoms (0 = no, 1 = yes)
|
||||
|
||||
.. _extract_system_sizes:
|
||||
|
||||
@ -1310,6 +1327,10 @@ int lammps_extract_setting(void *handle, const char *keyword)
|
||||
if (strcmp(keyword,"world_rank") == 0) return lmp->comm->me;
|
||||
if (strcmp(keyword,"world_size") == 0) return lmp->comm->nprocs;
|
||||
if (strcmp(keyword,"nthreads") == 0) return lmp->comm->nthreads;
|
||||
if (strcmp(keyword,"comm_style") == 0) return lmp->comm->style;
|
||||
if (strcmp(keyword,"comm_layout") == 0) return lmp->comm->layout;
|
||||
if (strcmp(keyword,"comm_mode") == 0) return lmp->comm->mode;
|
||||
if (strcmp(keyword,"ghost_velocity") == 0) return lmp->comm->ghost_velocity;
|
||||
|
||||
if (strcmp(keyword,"nlocal") == 0) return lmp->atom->nlocal;
|
||||
if (strcmp(keyword,"nghost") == 0) return lmp->atom->nghost;
|
||||
@ -1386,6 +1407,7 @@ int lammps_extract_global_datatype(void * /*handle*/, const char *name)
|
||||
if (strcmp(name,"xy") == 0) return LAMMPS_DOUBLE;
|
||||
if (strcmp(name,"xz") == 0) return LAMMPS_DOUBLE;
|
||||
if (strcmp(name,"yz") == 0) return LAMMPS_DOUBLE;
|
||||
if (strcmp(name,"procgrid") == 0) return LAMMPS_INT;
|
||||
|
||||
if (strcmp(name,"natoms") == 0) return LAMMPS_BIGINT;
|
||||
if (strcmp(name,"nbonds") == 0) return LAMMPS_BIGINT;
|
||||
@ -1604,6 +1626,10 @@ report the "native" data type. The following tables are provided:
|
||||
- double
|
||||
- 1
|
||||
- triclinic tilt factor. See :doc:`Howto_triclinic`.
|
||||
* - procgrid
|
||||
- int
|
||||
- 3
|
||||
- processor count assigned to each dimension of 3d grid. See :doc:`processors`.
|
||||
|
||||
.. _extract_system_settings:
|
||||
|
||||
@ -1861,6 +1887,9 @@ void *lammps_extract_global(void *handle, const char *name)
|
||||
if (strcmp(name,"xy") == 0) return (void *) &lmp->domain->xy;
|
||||
if (strcmp(name,"xz") == 0) return (void *) &lmp->domain->xz;
|
||||
if (strcmp(name,"yz") == 0) return (void *) &lmp->domain->yz;
|
||||
if (((lmp->comm->layout == Comm::LAYOUT_UNIFORM) ||
|
||||
(lmp->comm->layout == Comm::LAYOUT_NONUNIFORM)) && (strcmp(name,"procgrid") == 0))
|
||||
return (void *) &lmp->comm->procgrid;
|
||||
|
||||
if (strcmp(name,"natoms") == 0) return (void *) &lmp->atom->natoms;
|
||||
if (strcmp(name,"ntypes") == 0) return (void *) &lmp->atom->ntypes;
|
||||
|
||||
@ -580,6 +580,37 @@ create_atoms 1 single &
|
||||
"Press" : 0.0}
|
||||
self.assertDictEqual(self.lmp.last_thermo(), ref)
|
||||
|
||||
def test_extract_setting(self):
|
||||
self.assertEqual(self.lmp.extract_setting("dimension"), 3)
|
||||
self.assertEqual(self.lmp.extract_setting("box_exist"), 0)
|
||||
self.assertEqual(self.lmp.extract_setting("kokkos_active"), 0)
|
||||
self.assertEqual(self.lmp.extract_setting("kokkos_nthreads"), 0)
|
||||
self.assertEqual(self.lmp.extract_setting("kokkos_ngpus"), 0)
|
||||
self.lmp.command("region box block -1 1 -2 2 -3 3")
|
||||
self.lmp.command("create_box 1 box")
|
||||
self.lmp.command("special_bonds lj 0.0 0.5 0.8 coul 0.1 0.5 1.0")
|
||||
self.assertEqual(self.lmp.extract_setting("newton_bond"), 1)
|
||||
self.assertEqual(self.lmp.extract_setting("newton_pair"), 1)
|
||||
self.assertEqual(self.lmp.extract_setting("triclinic"), 0)
|
||||
self.assertEqual(self.lmp.extract_setting("universe_rank"), 0)
|
||||
self.assertEqual(self.lmp.extract_setting("universe_size"), 1)
|
||||
self.assertEqual(self.lmp.extract_setting("world_rank"), 0)
|
||||
self.assertEqual(self.lmp.extract_setting("world_size"), 1)
|
||||
self.assertEqual(self.lmp.extract_setting("triclinic"), 0)
|
||||
self.assertEqual(self.lmp.extract_setting("comm_style"), 0)
|
||||
self.assertEqual(self.lmp.extract_setting("comm_layout"), 0)
|
||||
self.assertEqual(self.lmp.extract_setting("comm_mode"), 0)
|
||||
self.assertEqual(self.lmp.extract_setting("ghost_velocity"), 0)
|
||||
self.lmp.command("comm_style tiled")
|
||||
self.lmp.command("comm_modify vel yes")
|
||||
self.lmp.command("mass 1 1.0")
|
||||
self.lmp.command("run 0 post no")
|
||||
self.lmp.command("balance 0.1 rcb")
|
||||
self.assertEqual(self.lmp.extract_setting("comm_style"), 1)
|
||||
self.assertEqual(self.lmp.extract_setting("comm_layout"), 2)
|
||||
self.assertEqual(self.lmp.extract_setting("comm_mode"), 0)
|
||||
self.assertEqual(self.lmp.extract_setting("ghost_velocity"), 1)
|
||||
|
||||
def test_extract_global(self):
|
||||
self.lmp.command("region box block -1 1 -2 2 -3 3")
|
||||
self.lmp.command("create_box 1 box")
|
||||
@ -628,6 +659,13 @@ create_atoms 1 single &
|
||||
self.assertEqual(self.lmp.extract_global("sublo_lambda"), [0.0, 0.0, 0.0])
|
||||
self.assertEqual(self.lmp.extract_global("subhi_lambda"), [1.0, 1.0, 1.0])
|
||||
|
||||
# processor grid
|
||||
self.assertEqual(self.lmp.extract_global("procgrid"), [1,1,1])
|
||||
self.lmp.command("comm_style tiled")
|
||||
self.lmp.command("run 0 post no")
|
||||
self.lmp.command("balance 0.1 rcb")
|
||||
self.assertEqual(self.lmp.extract_global("procgrid"), None)
|
||||
|
||||
def test_create_atoms(self):
|
||||
self.lmp.command("boundary f p m")
|
||||
self.lmp.command("region box block 0 10 0 10 0 10")
|
||||
|
||||
@ -119,6 +119,10 @@ class PythonPyLammps(unittest.TestCase):
|
||||
self.assertEqual(self.pylmp.communication.comm_style,'brick')
|
||||
self.assertEqual(self.pylmp.communication.comm_layout,'uniform')
|
||||
self.assertEqual(self.pylmp.communication.nprocs,1)
|
||||
self.assertEqual(self.pylmp.communication.nthreads,1)
|
||||
self.assertEqual(self.pylmp.communication.procgrid,[1,1,1])
|
||||
self.assertEqual(self.pylmp.communication.proc_grid,[1,1,1])
|
||||
self.assertEqual(self.pylmp.communication.ghost_velocity,0)
|
||||
self.assertEqual(len(self.pylmp.computes),3)
|
||||
self.assertEqual(self.pylmp.computes[0]['name'], 'thermo_temp')
|
||||
self.assertEqual(self.pylmp.computes[0]['style'], 'temp')
|
||||
@ -137,6 +141,11 @@ class PythonPyLammps(unittest.TestCase):
|
||||
self.assertEqual(self.pylmp.fixes[0]['group'], 'all')
|
||||
self.pylmp.group('none','empty')
|
||||
self.assertEqual(len(self.pylmp.groups),2)
|
||||
self.pylmp.comm_style('tiled')
|
||||
self.pylmp.mass('*',1.0)
|
||||
self.pylmp.run('0','post','no')
|
||||
self.pylmp.balance(0.1,'rcb')
|
||||
self.assertEqual(self.pylmp.communication.procgrid,None)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user