From 514039ed62d588a7e94cc90ad32d36fd3e30ebbd Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 13 Jun 2024 11:59:39 -0600 Subject: [PATCH 1/9] library: add comm->procgrid to extract_global --- python/lammps/core.py | 2 +- python/lammps/pylammps.py | 3 +-- src/library.cpp | 9 +++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/python/lammps/core.py b/python/lammps/core.py index 9ab6661df5..497d8efc20 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -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, 'proc_grid':3 } if name in vec_dict: veclen = vec_dict[name] elif name == 'respa_dt': diff --git a/python/lammps/pylammps.py b/python/lammps/pylammps.py index 7dd3823bbf..4d0737ad79 100644 --- a/python/lammps/pylammps.py +++ b/python/lammps/pylammps.py @@ -796,6 +796,7 @@ class PyLammps(object): comm = {} comm['nprocs'] = self.lmp.extract_setting("world_size") comm['nthreads'] = self.lmp.extract_setting("nthreads") + comm['proc_grid'] = self.lmp.extract_global("proc_grid") for line in output: if line.startswith("MPI library"): @@ -804,8 +805,6 @@ class PyLammps(object): 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 diff --git a/src/library.cpp b/src/library.cpp index e5c3021954..73dc75ed9d 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -1386,6 +1386,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,"proc_grid") == 0) return LAMMPS_INT; if (strcmp(name,"natoms") == 0) return LAMMPS_BIGINT; if (strcmp(name,"nbonds") == 0) return LAMMPS_BIGINT; @@ -1604,6 +1605,10 @@ report the "native" data type. The following tables are provided: - double - 1 - triclinic tilt factor. See :doc:`Howto_triclinic`. + * - proc_grid + - int + - 3 + - processor count assigned to each dimension of 3d grid. See :doc:`processors`. .. _extract_system_settings: @@ -1861,6 +1866,10 @@ 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,"proc_grid") == 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; From 77b610a2bd62e152c806434d2355444ac13ef582 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 14 Jun 2024 20:04:21 -0400 Subject: [PATCH 2/9] also make comm->style, comm->layout, and comm->mode accessible through the library interface --- src/library.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/library.cpp b/src/library.cpp index 73dc75ed9d..c9836acab8 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -1198,14 +1198,29 @@ internally by the :doc:`Fortran interface ` 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) .. _extract_system_sizes: @@ -1310,6 +1325,9 @@ 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,"nlocal") == 0) return lmp->atom->nlocal; if (strcmp(keyword,"nghost") == 0) return lmp->atom->nghost; From 1ce94e47d82289c03cdffd80b163c512082b2fe6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 14 Jun 2024 20:20:53 -0400 Subject: [PATCH 3/9] also make "comm->ghost_velocity" accessible --- src/library.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/library.cpp b/src/library.cpp index c9836acab8..4fbfbe332b 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -1221,6 +1221,8 @@ internally by the :doc:`Fortran interface ` and are not likely to be us - 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: @@ -1328,6 +1330,7 @@ int lammps_extract_setting(void *handle, const char *keyword) 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; From cb3aa07287385930a3f9ac2ff92d562ee9e840b1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 14 Jun 2024 20:21:19 -0400 Subject: [PATCH 4/9] update PyLammps to use added properties directly instead of parsing them. --- python/lammps/pylammps.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/python/lammps/pylammps.py b/python/lammps/pylammps.py index 4d0737ad79..047d02bce0 100644 --- a/python/lammps/pylammps.py +++ b/python/lammps/pylammps.py @@ -797,16 +797,15 @@ class PyLammps(object): comm['nprocs'] = self.lmp.extract_setting("world_size") comm['nthreads'] = self.lmp.extract_setting("nthreads") comm['proc_grid'] = self.lmp.extract_global("proc_grid") + 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("Communicate velocities for ghost atoms"): - comm['ghost_velocity'] = (self._get_pair(line)[1] == "yes") return comm def _parse_element_list(self, output): From 9b52f66a5a48427660535d2cd769967f6a29ffa4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 15 Jun 2024 05:55:45 -0400 Subject: [PATCH 5/9] fix typos --- python/lammps/pylammps.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/lammps/pylammps.py b/python/lammps/pylammps.py index 047d02bce0..e213970c8b 100644 --- a/python/lammps/pylammps.py +++ b/python/lammps/pylammps.py @@ -797,9 +797,9 @@ class PyLammps(object): comm['nprocs'] = self.lmp.extract_setting("world_size") comm['nthreads'] = self.lmp.extract_setting("nthreads") comm['proc_grid'] = self.lmp.extract_global("proc_grid") - idx = self.lmp_extract_setting("comm_style") + idx = self.lmp.extract_setting("comm_style") comm['comm_style'] = ('brick', 'tiled')[idx] - idx = self.lmp_extract_setting("comm_style") + idx = self.lmp.extract_setting("comm_style") comm['comm_layout'] = ('uniform', 'nonuniform', 'irregular')[idx] comm['ghost_velocity'] = self.lmp_extract_setting("ghost_velocity") == 1 From ee0dd80cbee726ea05653a1b6bfa5cd5235876ca Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 15 Jun 2024 06:17:13 -0400 Subject: [PATCH 6/9] fix another typo --- python/lammps/pylammps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/lammps/pylammps.py b/python/lammps/pylammps.py index e213970c8b..519b1e323c 100644 --- a/python/lammps/pylammps.py +++ b/python/lammps/pylammps.py @@ -801,7 +801,7 @@ class PyLammps(object): 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 + comm['ghost_velocity'] = self.lmp.extract_setting("ghost_velocity") == 1 for line in output: if line.startswith("MPI library"): From d2ea3b1ac586c95ebd98c4572a83e6049fd34b5c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 15 Jun 2024 08:23:59 -0400 Subject: [PATCH 7/9] add some tests for new features --- unittest/python/python-commands.py | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/unittest/python/python-commands.py b/unittest/python/python-commands.py index f11ac11da9..c007cc8014 100644 --- a/unittest/python/python-commands.py +++ b/unittest/python/python-commands.py @@ -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("proc_grid"), [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("proc_grid"), 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") From 19a83135786765fecca1af73238bc359cfe29ac0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 18 Jun 2024 21:13:14 -0400 Subject: [PATCH 8/9] switch proc_grid to procgrid with backward compatibility for PyLammps --- python/lammps/core.py | 2 +- python/lammps/pylammps.py | 2 +- src/library.cpp | 9 ++++----- unittest/python/python-commands.py | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/python/lammps/core.py b/python/lammps/core.py index 497d8efc20..8966a77440 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -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, 'proc_grid':3 } + 'special_lj':4, 'special_coul':4, 'procgrid':3 } if name in vec_dict: veclen = vec_dict[name] elif name == 'respa_dt': diff --git a/python/lammps/pylammps.py b/python/lammps/pylammps.py index 519b1e323c..96384255c2 100644 --- a/python/lammps/pylammps.py +++ b/python/lammps/pylammps.py @@ -796,7 +796,7 @@ class PyLammps(object): comm = {} comm['nprocs'] = self.lmp.extract_setting("world_size") comm['nthreads'] = self.lmp.extract_setting("nthreads") - comm['proc_grid'] = self.lmp.extract_global("proc_grid") + 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") diff --git a/src/library.cpp b/src/library.cpp index 4fbfbe332b..71cf01eff2 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -1407,7 +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,"proc_grid") == 0) return LAMMPS_INT; + if (strcmp(name,"procgrid") == 0) return LAMMPS_INT; if (strcmp(name,"natoms") == 0) return LAMMPS_BIGINT; if (strcmp(name,"nbonds") == 0) return LAMMPS_BIGINT; @@ -1626,7 +1626,7 @@ report the "native" data type. The following tables are provided: - double - 1 - triclinic tilt factor. See :doc:`Howto_triclinic`. - * - proc_grid + * - procgrid - int - 3 - processor count assigned to each dimension of 3d grid. See :doc:`processors`. @@ -1887,9 +1887,8 @@ 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,"proc_grid") == 0)) + 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; diff --git a/unittest/python/python-commands.py b/unittest/python/python-commands.py index c007cc8014..3a222dde5a 100644 --- a/unittest/python/python-commands.py +++ b/unittest/python/python-commands.py @@ -660,11 +660,11 @@ create_atoms 1 single & self.assertEqual(self.lmp.extract_global("subhi_lambda"), [1.0, 1.0, 1.0]) # processor grid - self.assertEqual(self.lmp.extract_global("proc_grid"), [1,1,1]) + 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("proc_grid"), None) + self.assertEqual(self.lmp.extract_global("procgrid"), None) def test_create_atoms(self): self.lmp.command("boundary f p m") From 2a132dfe8fee25e36424c61dc5fdca2adca2fdb6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 18 Jun 2024 21:13:33 -0400 Subject: [PATCH 9/9] add tests for PyLammps to check new exports --- unittest/python/python-pylammps.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/unittest/python/python-pylammps.py b/unittest/python/python-pylammps.py index 9e691b1b8c..3a7f0dc9cf 100644 --- a/unittest/python/python-pylammps.py +++ b/unittest/python/python-pylammps.py @@ -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()