diff --git a/doc/src/fix_electrode.rst b/doc/src/fix_electrode.rst index 3d543f08d2..8a7a44454d 100644 --- a/doc/src/fix_electrode.rst +++ b/doc/src/fix_electrode.rst @@ -45,7 +45,7 @@ Syntax rng_v = integer used to initialize random number generator * zero or more keyword/value pairs may be appended -* keyword = *algo* or *symm* or *couple* or *etypes* or *ffield* or *write_mat* or *write_inv* or *read_mat* or *read_inv* +* keyword = *algo* or *symm* or *couple* or *etypes* or *ffield* or *write_mat* or *write_inv* or *read_mat* or *read_inv* or *qtotal* or *eta* .. parsed-literal:: @@ -68,6 +68,10 @@ Syntax filename = file from which to read elastance matrix *read_inv* value = filename filename = file from which to read inverted matrix + *qtotal* value = number or *v_* equal-style variable + add overall potential so that all electrode charges add up to *qtotal* + *eta* value = d_propname + d_propname = a custom double vector defined via fix property/atom Examples """""""" @@ -249,6 +253,26 @@ be enabled if any electrode particle has the same type as any electrolyte particle (which would be unusual in a typical simulation) and the fix will issue an error in that case. +.. versionadded:: TBD + +The keyword *qtotal* causes *fix electrode/conp* and *fix electrode/thermo* +to add an overall potential to all electrodes so that the total charge on +the electrodes is a specified amount (which may be an equal-style variable). +For example, if a user wanted to simulate a solution of excess cations +such that the total electrolyte charge is +2, setting *qtotal -2* would cause +the total electrode charge to be -2, so that the simulation box remains overall +electroneutral. Since *fix electrode/conq* constrains the total charges of +individual electrodes, and since *symm on* constrains the total charge of all +electrodes to be zero, either option is incompatible with the *qtotal* keyword +(even if *qtotal* is set to zero). + +.. versionadded:: TBD + +The keyword *eta* takes the name of a custom double vector defined via fix +property/atom. The values will be used instead of the standard eta value. The +property/atom fix must be for vector of double values and use the *ghost on* +option. + Restart, fix_modify, output, run start/stop, minimize info """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" diff --git a/examples/PACKAGES/electrode/madelung/eval.py b/examples/PACKAGES/electrode/madelung/eval.py index 2f5a355d9b..feda0e384e 100644 --- a/examples/PACKAGES/electrode/madelung/eval.py +++ b/examples/PACKAGES/electrode/madelung/eval.py @@ -1,7 +1,7 @@ #!/usr/env/python3 -import sys import os.path as op +import sys def rel_error(out, ref): @@ -49,5 +49,5 @@ for label, ref, out in out_lines: error = rel_error(out, ref) lines.append(f"{label}: {out:.5f}, {error:.5f}\n") -with open("madelung.txt", 'a') as f: +with open("madelung.txt", "a") as f: f.writelines(lines) diff --git a/examples/PACKAGES/electrode/madelung/in.eta b/examples/PACKAGES/electrode/madelung/in.eta new file mode 100644 index 0000000000..3a45bb1bf5 --- /dev/null +++ b/examples/PACKAGES/electrode/madelung/in.eta @@ -0,0 +1,14 @@ +boundary p p f +kspace_style ewald/electrode 1.0e-8 +kspace_modify slab 8.0 # ew3dc + +include "settings.mod" # styles, computes, groups and fixes + +thermo_style custom step pe c_qbot c_qtop +fix feta all property/atom d_eta ghost on +set group bot d_eta 2.0 +set group top d_eta 2.0 +fix conp bot electrode/conp 0 2 couple top 1 symm on eta d_eta write_inv inv.csv write_vec vec.csv + +run 0 + diff --git a/examples/PACKAGES/electrode/madelung/in.eta_cg b/examples/PACKAGES/electrode/madelung/in.eta_cg new file mode 100644 index 0000000000..5ac8cddf17 --- /dev/null +++ b/examples/PACKAGES/electrode/madelung/in.eta_cg @@ -0,0 +1,14 @@ +boundary p p f +kspace_style ewald/electrode 1.0e-8 +kspace_modify slab 8.0 # ew3dc + +include "settings.mod" # styles, computes, groups and fixes + +thermo_style custom step pe c_qbot c_qtop +fix feta all property/atom d_eta ghost on +set group bot d_eta 0.5 +set group top d_eta 3.0 +fix conp bot electrode/conp 0 2 couple top 1 symm on eta d_eta algo cg 1e-6 + +run 0 + diff --git a/examples/PACKAGES/electrode/madelung/in.eta_mix b/examples/PACKAGES/electrode/madelung/in.eta_mix new file mode 100644 index 0000000000..d00e008fa4 --- /dev/null +++ b/examples/PACKAGES/electrode/madelung/in.eta_mix @@ -0,0 +1,14 @@ +boundary p p f +kspace_style ewald/electrode 1.0e-8 +kspace_modify slab 8.0 # ew3dc + +include "settings.mod" # styles, computes, groups and fixes + +thermo_style custom step pe c_qbot c_qtop +fix feta all property/atom d_eta ghost on +set group bot d_eta 0.5 +set group top d_eta 3.0 +fix conp bot electrode/conp 0 2 couple top 1 symm on eta d_eta write_inv inv.csv write_vec vec.csv + +run 0 + diff --git a/examples/PACKAGES/electrode/madelung/log.19Feb2024.eta.g++.1 b/examples/PACKAGES/electrode/madelung/log.19Feb2024.eta.g++.1 new file mode 100644 index 0000000000..daf0563799 --- /dev/null +++ b/examples/PACKAGES/electrode/madelung/log.19Feb2024.eta.g++.1 @@ -0,0 +1,138 @@ +LAMMPS (21 Nov 2023 - Development - patch_21Nov2023-668-g5b6c0c6b56) + using 1 OpenMP thread(s) per MPI task +boundary p p f +kspace_style ewald/electrode 1.0e-8 +kspace_modify slab 8.0 # ew3dc + +include "settings.mod" # styles, computes, groups and fixes +# set boundary in main script because ffield is periodic +units real +# distribute electrode atoms among all processors: +if "$(extract_setting(world_size) % 2) == 0" then "processors * * 2" + +atom_style full +pair_style lj/cut/coul/long 12 + +read_data "data.au-elyt" +Reading data file ... + orthogonal box = (0 0 -10) to (1 1 10) + 1 by 1 by 1 MPI processor grid + reading atoms ... + 4 atoms +Finding 1-2 1-3 1-4 neighbors ... + special bond factors lj: 0 0 0 + special bond factors coul: 0 0 0 + 0 = max # of 1-2 neighbors + 0 = max # of 1-3 neighbors + 0 = max # of 1-4 neighbors + 1 = max # of special neighbors + special bonds CPU = 0.000 seconds + read_data CPU = 0.003 seconds + +group bot type 1 +1 atoms in group bot +group top type 2 +1 atoms in group top + +# get electrode charges +variable q atom q +compute qbot bot reduce sum v_q +compute qtop top reduce sum v_q + +compute compute_pe all pe +variable vpe equal c_compute_pe +variable charge equal c_qtop +fix fxprint all print 1 "${vpe}, ${charge}" file "out.csv" + +thermo_style custom step pe c_qbot c_qtop +fix feta all property/atom d_eta ghost on +set group bot d_eta 2.0 +Setting atom values ... + 1 settings made for d_eta +set group top d_eta 2.0 +Setting atom values ... + 1 settings made for d_eta +fix conp bot electrode/conp 0 2 couple top 1 symm on eta d_eta write_inv inv.csv write_vec vec.csv +2 atoms in group conp_group + +run 0 + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Your simulation uses code contributions which should be cited: + +- fix electrode command: + +@article{Ahrens2022 +author = {Ahrens-Iwers, Ludwig J.V. and Janssen, Mahijs and Tee, Shern R. and Mei{\ss}ner, Robert H.}, +doi = {10.1063/5.0099239}, +title = {{ELECTRODE: An electrochemistry package for LAMMPS}}, +journal = {The Journal of Chemical Physics}, +year = {2022} +volume = {157}, +pages = {084801}, +} +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +WARNING: No fixes with time integration, atoms won't move (src/verlet.cpp:60) +Ewald/electrode initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:342) +WARNING: For better accuracy use 'pair_modify table 0' (src/kspace.cpp:365) + G vector (1/distance) = 0.32261103 + estimated absolute RMS force accuracy = 3.8272011e-06 + estimated relative force accuracy = 1.1525502e-08 + KSpace vectors: actual max1d max3d = 52 50 515150 + kxmax kymax kzmax = 1 1 50 +Generated 3 of 3 mixed pair_coeff terms from geometric mixing rule +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 14 + ghost atom cutoff = 14 + binsize = 7, bins = 1 1 3 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair lj/cut/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/newton + stencil: half/bin/3d + bin: standard + (2) fix electrode/conp, perpetual, copy from (1) + attributes: half, newton on + pair build: copy + stencil: none + bin: none +WARNING: Proc sub-domain size < neighbor skin, could lead to lost atoms (src/domain.cpp:965) +139.943964815502, 0.279214485147238 +Per MPI rank memory allocation (min/avg/max) = 144.2 | 144.2 | 144.2 Mbytes + Step PotEng c_qbot c_qtop + 0 139.94396 -0.27921449 0.27921449 +Loop time of 2.191e-06 on 1 procs for 0 steps with 4 atoms + +91.3% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 0 | 0 | 0 | 0.0 | 0.00 +Bond | 0 | 0 | 0 | 0.0 | 0.00 +Kspace | 0 | 0 | 0 | 0.0 | 0.00 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0 | 0 | 0 | 0.0 | 0.00 +Output | 0 | 0 | 0 | 0.0 | 0.00 +Modify | 0 | 0 | 0 | 0.0 | 0.00 +Other | | 2.191e-06 | | |100.00 + +Nlocal: 4 ave 4 max 4 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 3596 ave 3596 max 3596 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 4790 ave 4790 max 4790 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 4790 +Ave neighs/atom = 1197.5 +Ave special neighs/atom = 0 +Neighbor list builds = 0 +Dangerous builds = 0 + +Total wall time: 0:00:00 diff --git a/examples/PACKAGES/electrode/madelung/log.19Feb2024.eta_cg.g++.1 b/examples/PACKAGES/electrode/madelung/log.19Feb2024.eta_cg.g++.1 new file mode 100644 index 0000000000..edb2e434e6 --- /dev/null +++ b/examples/PACKAGES/electrode/madelung/log.19Feb2024.eta_cg.g++.1 @@ -0,0 +1,139 @@ +LAMMPS (21 Nov 2023 - Development - patch_21Nov2023-668-g5b6c0c6b56) + using 1 OpenMP thread(s) per MPI task +boundary p p f +kspace_style ewald/electrode 1.0e-8 +kspace_modify slab 8.0 # ew3dc + +include "settings.mod" # styles, computes, groups and fixes +# set boundary in main script because ffield is periodic +units real +# distribute electrode atoms among all processors: +if "$(extract_setting(world_size) % 2) == 0" then "processors * * 2" + +atom_style full +pair_style lj/cut/coul/long 12 + +read_data "data.au-elyt" +Reading data file ... + orthogonal box = (0 0 -10) to (1 1 10) + 1 by 1 by 1 MPI processor grid + reading atoms ... + 4 atoms +Finding 1-2 1-3 1-4 neighbors ... + special bond factors lj: 0 0 0 + special bond factors coul: 0 0 0 + 0 = max # of 1-2 neighbors + 0 = max # of 1-3 neighbors + 0 = max # of 1-4 neighbors + 1 = max # of special neighbors + special bonds CPU = 0.000 seconds + read_data CPU = 0.003 seconds + +group bot type 1 +1 atoms in group bot +group top type 2 +1 atoms in group top + +# get electrode charges +variable q atom q +compute qbot bot reduce sum v_q +compute qtop top reduce sum v_q + +compute compute_pe all pe +variable vpe equal c_compute_pe +variable charge equal c_qtop +fix fxprint all print 1 "${vpe}, ${charge}" file "out.csv" + +thermo_style custom step pe c_qbot c_qtop +fix feta all property/atom d_eta ghost on +set group bot d_eta 0.5 +Setting atom values ... + 1 settings made for d_eta +set group top d_eta 3.0 +Setting atom values ... + 1 settings made for d_eta +fix conp bot electrode/conp 0 2 couple top 1 symm on eta d_eta algo cg 1e-6 +2 atoms in group conp_group + +run 0 + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Your simulation uses code contributions which should be cited: + +- fix electrode command: + +@article{Ahrens2022 +author = {Ahrens-Iwers, Ludwig J.V. and Janssen, Mahijs and Tee, Shern R. and Mei{\ss}ner, Robert H.}, +doi = {10.1063/5.0099239}, +title = {{ELECTRODE: An electrochemistry package for LAMMPS}}, +journal = {The Journal of Chemical Physics}, +year = {2022} +volume = {157}, +pages = {084801}, +} +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +WARNING: No fixes with time integration, atoms won't move (src/verlet.cpp:60) +Ewald/electrode initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:342) +WARNING: For better accuracy use 'pair_modify table 0' (src/kspace.cpp:365) + G vector (1/distance) = 0.32261103 + estimated absolute RMS force accuracy = 3.8272011e-06 + estimated relative force accuracy = 1.1525502e-08 + KSpace vectors: actual max1d max3d = 52 50 515150 + kxmax kymax kzmax = 1 1 50 +Generated 3 of 3 mixed pair_coeff terms from geometric mixing rule +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 14 + ghost atom cutoff = 14 + binsize = 7, bins = 1 1 3 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair lj/cut/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/newton + stencil: half/bin/3d + bin: standard + (2) fix electrode/conp, perpetual, copy from (1) + attributes: half, newton on + pair build: copy + stencil: none + bin: none +WARNING: Proc sub-domain size < neighbor skin, could lead to lost atoms (src/domain.cpp:965) +165.519373910316, 0.29521534552818 +Per MPI rank memory allocation (min/avg/max) = 144.2 | 144.2 | 144.2 Mbytes + Step PotEng c_qbot c_qtop + 0 165.51937 -0.29521535 0.29521535 +Loop time of 2.797e-06 on 1 procs for 0 steps with 4 atoms + +71.5% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 0 | 0 | 0 | 0.0 | 0.00 +Bond | 0 | 0 | 0 | 0.0 | 0.00 +Kspace | 0 | 0 | 0 | 0.0 | 0.00 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0 | 0 | 0 | 0.0 | 0.00 +Output | 0 | 0 | 0 | 0.0 | 0.00 +Modify | 0 | 0 | 0 | 0.0 | 0.00 +Other | | 2.797e-06 | | |100.00 + +Nlocal: 4 ave 4 max 4 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 3596 ave 3596 max 3596 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 4790 ave 4790 max 4790 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 4790 +Ave neighs/atom = 1197.5 +Ave special neighs/atom = 0 +Neighbor list builds = 0 +Dangerous builds = 0 + +Average conjugate gradient steps: 1 +Total wall time: 0:00:00 diff --git a/examples/PACKAGES/electrode/madelung/log.19Feb2024.eta_mix.g++.1 b/examples/PACKAGES/electrode/madelung/log.19Feb2024.eta_mix.g++.1 new file mode 100644 index 0000000000..51eda0d870 --- /dev/null +++ b/examples/PACKAGES/electrode/madelung/log.19Feb2024.eta_mix.g++.1 @@ -0,0 +1,138 @@ +LAMMPS (21 Nov 2023 - Development - patch_21Nov2023-668-g5b6c0c6b56) + using 1 OpenMP thread(s) per MPI task +boundary p p f +kspace_style ewald/electrode 1.0e-8 +kspace_modify slab 8.0 # ew3dc + +include "settings.mod" # styles, computes, groups and fixes +# set boundary in main script because ffield is periodic +units real +# distribute electrode atoms among all processors: +if "$(extract_setting(world_size) % 2) == 0" then "processors * * 2" + +atom_style full +pair_style lj/cut/coul/long 12 + +read_data "data.au-elyt" +Reading data file ... + orthogonal box = (0 0 -10) to (1 1 10) + 1 by 1 by 1 MPI processor grid + reading atoms ... + 4 atoms +Finding 1-2 1-3 1-4 neighbors ... + special bond factors lj: 0 0 0 + special bond factors coul: 0 0 0 + 0 = max # of 1-2 neighbors + 0 = max # of 1-3 neighbors + 0 = max # of 1-4 neighbors + 1 = max # of special neighbors + special bonds CPU = 0.000 seconds + read_data CPU = 0.003 seconds + +group bot type 1 +1 atoms in group bot +group top type 2 +1 atoms in group top + +# get electrode charges +variable q atom q +compute qbot bot reduce sum v_q +compute qtop top reduce sum v_q + +compute compute_pe all pe +variable vpe equal c_compute_pe +variable charge equal c_qtop +fix fxprint all print 1 "${vpe}, ${charge}" file "out.csv" + +thermo_style custom step pe c_qbot c_qtop +fix feta all property/atom d_eta ghost on +set group bot d_eta 0.5 +Setting atom values ... + 1 settings made for d_eta +set group top d_eta 3.0 +Setting atom values ... + 1 settings made for d_eta +fix conp bot electrode/conp 0 2 couple top 1 symm on eta d_eta write_inv inv.csv write_vec vec.csv +2 atoms in group conp_group + +run 0 + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Your simulation uses code contributions which should be cited: + +- fix electrode command: + +@article{Ahrens2022 +author = {Ahrens-Iwers, Ludwig J.V. and Janssen, Mahijs and Tee, Shern R. and Mei{\ss}ner, Robert H.}, +doi = {10.1063/5.0099239}, +title = {{ELECTRODE: An electrochemistry package for LAMMPS}}, +journal = {The Journal of Chemical Physics}, +year = {2022} +volume = {157}, +pages = {084801}, +} +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +WARNING: No fixes with time integration, atoms won't move (src/verlet.cpp:60) +Ewald/electrode initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:342) +WARNING: For better accuracy use 'pair_modify table 0' (src/kspace.cpp:365) + G vector (1/distance) = 0.32261103 + estimated absolute RMS force accuracy = 3.8272011e-06 + estimated relative force accuracy = 1.1525502e-08 + KSpace vectors: actual max1d max3d = 52 50 515150 + kxmax kymax kzmax = 1 1 50 +Generated 3 of 3 mixed pair_coeff terms from geometric mixing rule +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 14 + ghost atom cutoff = 14 + binsize = 7, bins = 1 1 3 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair lj/cut/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/newton + stencil: half/bin/3d + bin: standard + (2) fix electrode/conp, perpetual, copy from (1) + attributes: half, newton on + pair build: copy + stencil: none + bin: none +WARNING: Proc sub-domain size < neighbor skin, could lead to lost atoms (src/domain.cpp:965) +165.519373910316, 0.295215345528172 +Per MPI rank memory allocation (min/avg/max) = 144.2 | 144.2 | 144.2 Mbytes + Step PotEng c_qbot c_qtop + 0 165.51937 -0.29521535 0.29521535 +Loop time of 2.18e-06 on 1 procs for 0 steps with 4 atoms + +91.7% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 0 | 0 | 0 | 0.0 | 0.00 +Bond | 0 | 0 | 0 | 0.0 | 0.00 +Kspace | 0 | 0 | 0 | 0.0 | 0.00 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0 | 0 | 0 | 0.0 | 0.00 +Output | 0 | 0 | 0 | 0.0 | 0.00 +Modify | 0 | 0 | 0 | 0.0 | 0.00 +Other | | 2.18e-06 | | |100.00 + +Nlocal: 4 ave 4 max 4 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 3596 ave 3596 max 3596 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 4790 ave 4790 max 4790 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 4790 +Ave neighs/atom = 1197.5 +Ave special neighs/atom = 0 +Neighbor list builds = 0 +Dangerous builds = 0 + +Total wall time: 0:00:00 diff --git a/examples/PACKAGES/electrode/madelung/plate_cap.py b/examples/PACKAGES/electrode/madelung/plate_cap.py index 62d52fe102..fcca166869 100755 --- a/examples/PACKAGES/electrode/madelung/plate_cap.py +++ b/examples/PACKAGES/electrode/madelung/plate_cap.py @@ -3,7 +3,6 @@ import numpy as np from scipy.special import erf -ETA = 2 SQRT2 = np.sqrt(2) COULOMB = 332.06371 # Coulomb constant in Lammps 'real' units QE2F = 23.060549 @@ -17,14 +16,14 @@ def lattice(length): return np.array(np.meshgrid(x, y)).T.reshape(-1, 2) -def a_element(r): +def a_element(r, eta): """Coulomb contribution of two Gaussians""" - return erf(ETA / SQRT2 * r) / r + return erf(eta * r) / r -def b_element(r, q): +def b_element(r, q, eta): """Coulomb contribution of a Gaussian with a point charge""" - return q * erf(ETA * r) / r + return q * erf(eta * r) / r a = 1 # nearest neighbor distance i.e. lattice constant / sqrt(2) @@ -36,59 +35,65 @@ v = np.array([-0.5, 0.5]) * (QE2F / COULOMB) # distances to images within electrode and to opposite electrode distances = a * np.linalg.norm(lattice(LENGTH), axis=1) -opposite_distances = np.sqrt(np.square(distances) + distance_plates ** 2) +opposite_distances = np.sqrt(np.square(distances) + distance_plates**2) -# self interaction and within original box -A_11 = np.sqrt(2 / np.pi) * ETA -A_12 = erf(ETA * distance_plates / SQRT2) / distance_plates +for name, eta_elec in [("", [2.0, 2.0]), ("_eta_mix", [0.5, 3.0])]: + eta_mix = np.prod(eta_elec) / np.sqrt(np.sum(np.square(eta_elec))) + # self interaction and within original box + A_11 = np.sqrt(2 / np.pi) * eta_elec[0] + A_22 = np.sqrt(2 / np.pi) * eta_elec[1] + A_12 = erf(eta_mix * distance_plates) / distance_plates -# interaction with periodic images -A_11 += 4 * np.sum(a_element(distances)) -A_12 += 4 * np.sum(a_element(opposite_distances)) -A = np.array([[A_11, A_12], [A_12, A_11]]) -inv = np.linalg.inv(A) -e = np.array([1, 1]) -inv -= np.matmul(inv, np.matmul(np.outer(e, e), inv)) / np.dot(e, np.dot(inv, e)) + # interaction with periodic images + A_11 += 4 * np.sum(a_element(distances, eta_elec[0] / SQRT2)) + A_22 += 4 * np.sum(a_element(distances, eta_elec[1] / SQRT2)) + A_12 += 4 * np.sum(a_element(opposite_distances, eta_mix)) + A = np.array([[A_11, A_12], [A_12, A_22]]) + inv = np.linalg.inv(A) + e = np.array([1, 1]) + inv -= np.matmul(inv, np.matmul(np.outer(e, e), inv)) / np.dot(e, np.dot(inv, e)) -# electrode-electrolyte interaction -b = [] -for x in x_elec: - bi = 0 - for y, q in zip(x_elyt, q_elyt): - d = abs(y - x) - bi += b_element(d, q) - image_distances = np.sqrt(np.square(distances) + d ** 2) - bi += 4 * np.sum(b_element(image_distances, q)) - b.append(bi) -b = np.array(b) + # electrode-electrolyte interaction + b = [] + for x, eta in zip(x_elec, eta_elec): + bi = 0 + for y, q in zip(x_elyt, q_elyt): + d = abs(y - x) + bi += b_element(d, q, eta) + image_distances = np.sqrt(np.square(distances) + d**2) + bi += 4 * np.sum(b_element(image_distances, q, eta)) + b.append(bi) + b = np.array(b) -# electrolyte-electrolyte energy -elyt_11 = 4 * np.sum(1 / distances) -distance_elyt = x_elyt[1] - x_elyt[0] -elyt_12 = 1 / distance_elyt + 4 * np.sum( - 1 / np.sqrt(np.square(distances) + distance_elyt ** 2) -) -elyt = np.array([[elyt_11, elyt_12], [elyt_12, elyt_11]]) -energy_elyt = 0.5 * np.dot(q_elyt, np.dot(elyt, q_elyt)) - -# electrode charges and energy -q = np.dot(inv, v - b) -energy = COULOMB * (0.5 * np.dot(q, np.dot(A, q)) + np.dot(b, q) + energy_elyt) - -print( - "length, energy / kcal/mol, q1 / e, q2 / e, inv11 / A, inv12 / A, b1 / e/A, b2 / e/A" -) -print( - ", ".join( - [ - str(LENGTH), - f"{energy:.8f}", - f"{q[0]:.10f}", - f"{q[1]:.10f}", - f"{inv[0, 0]:.10f}", - f"{inv[0, 1]:.10f}", - f"{b[0]:.8f}", - f"{b[1]:.8f}", - ] + # electrolyte-electrolyte energy + elyt_11 = 4 * np.sum(1 / distances) + distance_elyt = x_elyt[1] - x_elyt[0] + elyt_12 = 1 / distance_elyt + 4 * np.sum( + 1 / np.sqrt(np.square(distances) + distance_elyt**2) ) -) + elyt = np.array([[elyt_11, elyt_12], [elyt_12, elyt_11]]) + energy_elyt = 0.5 * np.dot(q_elyt, np.dot(elyt, q_elyt)) + + # electrode charges and energy + q = np.dot(inv, v - b) + energy = COULOMB * (0.5 * np.dot(q, np.dot(A, q)) + np.dot(b, q) + energy_elyt) + + with open(f"plate_cap{name}.csv", "w") as f: + f.write( + "length, energy / kcal/mol, q1 / e, q2 / e, inv11 / A, inv12 / A, b1 / e/A, b2 / e/A\n" + ) + f.write( + ", ".join( + [ + str(LENGTH), + f"{energy:.8f}", + f"{q[0]:.10f}", + f"{q[1]:.10f}", + f"{inv[0, 0]:.10f}", + f"{inv[0, 1]:.10f}", + f"{b[0]:.8f}", + f"{b[1]:.8f}", + ] + ) + + "\n" + ) diff --git a/examples/PACKAGES/electrode/madelung/test.sh b/examples/PACKAGES/electrode/madelung/test.sh index edac04f5b1..a558ee6711 100644 --- a/examples/PACKAGES/electrode/madelung/test.sh +++ b/examples/PACKAGES/electrode/madelung/test.sh @@ -7,17 +7,27 @@ if [ ! -f $lmpbin ]; then fi ref_out="plate_cap.csv" -if [ ! -f $ref_out ]; then +ref_mix_out="plate_cap_eta_mix.csv" +if [ ! -f $ref_out ] || [ ! -f $ref_mix_out ]; then echo "Generating reference data" - python3 plate_cap.py > $ref_out + python3 plate_cap.py fi echo "Running Lammps inputs" +# w/o eta mixing rm -rf madelung.txt && touch madelung.txt -for file in in.*; do +for file in in.eta in.ewald-ew3dc in.ewald-ew2d in.pppm-ew3dc in.cg; do printf "\n$file\n" >> madelung.txt rm -f out.csv inv.csv vec.csv $lmpbin -i $file &> /dev/null python3 eval.py $ref_out out.csv inv.csv vec.csv done + +# with eta mixing +for file in in.eta_mix in.eta_cg; do + printf "\n$file\n" >> madelung.txt + rm -f out.csv inv.csv vec.csv + $lmpbin -i $file &> /dev/null + python3 eval.py $ref_mix_out out.csv inv.csv vec.csv +done cat madelung.txt diff --git a/src/ELECTRODE/README b/src/ELECTRODE/README new file mode 100644 index 0000000000..72a95b7fe9 --- /dev/null +++ b/src/ELECTRODE/README @@ -0,0 +1,17 @@ +This package provides the "fix electrode/*" commands which can be used in a +LAMMPS input script. These fixes implement the constant potential method, which +minimizes the energy of electrodes as a function of atom charges at given +electric potentials or electrode charges. + +See the doc page for the fix electrode/conp command to get started. There are +example scripts for using this package in examples/PACKAGES/electrode. + +This package uses an external library in lib/electrode which must be compiled +before making LAMMPS. For a CMake build, the location of the LAPACK library +should be linked automatically. Alternatively, the "USE_INTERNAL_LINALG" option +can be used to enable the bundled library. See the doc page on "Packages with +extra build options" for more information. + +The primary people who created this package are Ludwig Ahrens-Iwers, Shern Tee +(s.tee@griffith.edu.au) and Robert Meißner (robert.meissner@tuhh.de). Contact +them directly if you have questions. diff --git a/src/ELECTRODE/electrode_math.h b/src/ELECTRODE/electrode_math.h index 5992df2289..4a3cb7bac4 100644 --- a/src/ELECTRODE/electrode_math.h +++ b/src/ELECTRODE/electrode_math.h @@ -18,22 +18,20 @@ #ifndef LMP_ELECTRODE_MATH_H #define LMP_ELECTRODE_MATH_H +#include "ewald_const.h" #include "math_const.h" +#include + namespace LAMMPS_NS { +using namespace EwaldConst; namespace ElectrodeMath { - static constexpr double EWALD_P = 0.3275911; - static constexpr double A1 = 0.254829592; - static constexpr double A2 = -0.284496736; - static constexpr double A3 = 1.421413741; - static constexpr double A4 = -1.453152027; - static constexpr double A5 = 1.061405429; static constexpr double ERFCMAX = 5.8; // erfc(ERFCMAX) < machine epsilon(double) static double safe_erfc(double x) { - if (x > ERFCMAX) return 0.; + if (x > ERFCMAX) return 0.0; double expm2 = exp(-x * x); double t = 1.0 / (1.0 + EWALD_P * x); return t * (A1 + t * (A2 + t * (A3 + t * (A4 + t * A5)))) * expm2; @@ -42,14 +40,14 @@ namespace ElectrodeMath { static double safe_derfcr(double x, double &erfc) { if (x > ERFCMAX) { - erfc = 0.; - return 0.; + erfc = 0.0; + return 0.0; } double x2 = x * x; double expm2 = exp(-x2); double t = 1.0 / (1.0 + EWALD_P * x); erfc = t * (A1 + t * (A2 + t * (A3 + t * (A4 + t * A5)))) * expm2; - return -erfc - 2 * expm2 * x / MathConst::MY_PIS; + return -erfc - 2.0 * expm2 * x / MathConst::MY_PIS; } } // namespace ElectrodeMath diff --git a/src/ELECTRODE/electrode_matrix.cpp b/src/ELECTRODE/electrode_matrix.cpp index 86761742d4..9c2da1d13b 100644 --- a/src/ELECTRODE/electrode_matrix.cpp +++ b/src/ELECTRODE/electrode_matrix.cpp @@ -43,6 +43,7 @@ ElectrodeMatrix::ElectrodeMatrix(LAMMPS *lmp, int electrode_group, double eta) : groupbit = group->bitmask[igroup]; ngroup = group->count(igroup); this->eta = eta; + etaflag = false; tfflag = false; } @@ -72,6 +73,14 @@ void ElectrodeMatrix::setup_tf(const std::map &tf_types) /* ---------------------------------------------------------------------- */ +void ElectrodeMatrix::setup_eta(int index) +{ + etaflag = true; + eta_index = index; +} + +/* ---------------------------------------------------------------------- */ + void ElectrodeMatrix::compute_array(double **array, bool timer_flag) { // setting all entries of coulomb matrix to zero @@ -115,8 +124,6 @@ void ElectrodeMatrix::pair_contribution(double **array) int nlocal = atom->nlocal; int newton_pair = force->newton_pair; - double const etaij = eta * eta / sqrt(2.0 * eta * eta); // see mw ewald theory eq. (29)-(30) - // neighbor list will be ready because called from post_neighbor inum = list->inum; ilist = list->ilist; @@ -135,6 +142,7 @@ void ElectrodeMatrix::pair_contribution(double **array) xtmp = x[i][0]; ytmp = x[i][1]; ztmp = x[i][2]; + double const eta_i = etaflag ? atom->dvector[eta_index][i] : eta; itype = type[i]; jlist = firstneigh[i]; jnum = numneigh[i]; @@ -152,6 +160,9 @@ void ElectrodeMatrix::pair_contribution(double **array) jtype = type[j]; if (rsq < cutsq[itype][jtype]) { + double const eta_j = etaflag ? atom->dvector[eta_index][j] : eta; + double const etaij = eta_i * eta_j / sqrt(eta_i * eta_i + eta_j * eta_j); + r = sqrt(rsq); rinv = 1.0 / r; aij = rinv; @@ -178,7 +189,10 @@ void ElectrodeMatrix::self_contribution(double **array) const double preta = MY_SQRT2 / MY_PIS; for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit) { array[mpos[i]][mpos[i]] += preta * eta - selfint; } + if (mask[i] & groupbit) { + double const eta_i = etaflag ? atom->dvector[eta_index][i] : eta; + array[mpos[i]][mpos[i]] += preta * eta_i - selfint; + } } /* ---------------------------------------------------------------------- */ diff --git a/src/ELECTRODE/electrode_matrix.h b/src/ELECTRODE/electrode_matrix.h index 8499cfdb34..1c64d8a4c4 100644 --- a/src/ELECTRODE/electrode_matrix.h +++ b/src/ELECTRODE/electrode_matrix.h @@ -30,6 +30,7 @@ class ElectrodeMatrix : protected Pointers { ElectrodeMatrix(class LAMMPS *, int, double); void setup(const std::unordered_map &, class Pair *, class NeighList *); void setup_tf(const std::map &); + void setup_eta(int); void compute_array(double **, bool); int igroup; @@ -39,6 +40,8 @@ class ElectrodeMatrix : protected Pointers { double **cutsq; double g_ewald, eta; bool tfflag; + bool etaflag; + int eta_index; std::map tf_types; std::unordered_map tag_to_iele; bool assigned; diff --git a/src/ELECTRODE/electrode_vector.cpp b/src/ELECTRODE/electrode_vector.cpp index 8511ddc17c..fc2cca5e46 100644 --- a/src/ELECTRODE/electrode_vector.cpp +++ b/src/ELECTRODE/electrode_vector.cpp @@ -29,6 +29,7 @@ #include "neigh_list.h" #include "pair.h" +#include #include #include @@ -47,6 +48,7 @@ ElectrodeVector::ElectrodeVector(LAMMPS *lmp, int sensor_group, int source_group source_grpbit = group->bitmask[source_group]; this->eta = eta; tfflag = false; + etaflag = false; kspace_time_total = 0; pair_time_total = 0; @@ -93,6 +95,14 @@ void ElectrodeVector::setup_tf(const std::map &tf_types) /* ---------------------------------------------------------------------- */ +void ElectrodeVector::setup_eta(int index) +{ + etaflag = true; + eta_index = index; +} + +/* ---------------------------------------------------------------------- */ + void ElectrodeVector::compute_vector(double *vector) { MPI_Barrier(world); @@ -121,7 +131,6 @@ void ElectrodeVector::compute_vector(double *vector) void ElectrodeVector::pair_contribution(double *vector) { - double const etaij = eta * MY_ISQRT2; double **x = atom->x; double *q = atom->q; int *type = atom->type; @@ -142,6 +151,7 @@ void ElectrodeVector::pair_contribution(double *vector) double const xtmp = x[i][0]; double const ytmp = x[i][1]; double const ztmp = x[i][2]; + double const eta_i = etaflag ? atom->dvector[eta_index][i] : eta; int itype = type[i]; int *jlist = firstneigh[i]; int jnum = numneigh[i]; @@ -158,18 +168,22 @@ void ElectrodeVector::pair_contribution(double *vector) double const rsq = delx * delx + dely * dely + delz * delz; int jtype = type[j]; if (rsq >= cutsq[itype][jtype]) continue; + double const eta_j = etaflag ? atom->dvector[eta_index][j] : eta; + double etaij; + if (i_in_sensor && j_in_sensor) { + etaij = eta_i * eta_j / sqrt(eta_i * eta_i + eta_j * eta_j); + } else if (i_in_sensor) { + etaij = eta_i; + } else { + assert(j_in_sensor); + etaij = eta_j; + } double const r = sqrt(rsq); double const rinv = 1.0 / r; double aij = rinv; aij *= ElectrodeMath::safe_erfc(g_ewald * r); - if (invert_source) - aij -= ElectrodeMath::safe_erfc(eta * r) * rinv; - else - aij -= ElectrodeMath::safe_erfc(etaij * r) * rinv; - if (i_in_sensor) { - vector[i] += aij * q[j]; - //} else if (j_in_sensor) { - } + aij -= ElectrodeMath::safe_erfc(etaij * r) * rinv; + if (i_in_sensor) { vector[i] += aij * q[j]; } if (j_in_sensor && (!invert_source || !i_in_sensor)) { vector[j] += aij * q[i]; } } } @@ -189,9 +203,10 @@ void ElectrodeVector::self_contribution(double *vector) for (int ii = 0; ii < inum; ii++) { int const i = ilist[ii]; + double const eta_i = etaflag ? atom->dvector[eta_index][i] : eta; bool const i_in_sensor = (mask[i] & groupbit); bool const i_in_source = !!(mask[i] & source_grpbit) != invert_source; - if (i_in_sensor && i_in_source) vector[i] += (preta * eta - selfint) * q[i]; + if (i_in_sensor && i_in_source) vector[i] += (preta * eta_i - selfint) * q[i]; } } diff --git a/src/ELECTRODE/electrode_vector.h b/src/ELECTRODE/electrode_vector.h index e7f637dd2d..a4f274a049 100644 --- a/src/ELECTRODE/electrode_vector.h +++ b/src/ELECTRODE/electrode_vector.h @@ -29,6 +29,7 @@ class ElectrodeVector : protected Pointers { ~ElectrodeVector() override; void setup(class Pair *, class NeighList *, bool); void setup_tf(const std::map &); + void setup_eta(int); void compute_vector(double *); int igroup, source_group; @@ -39,6 +40,8 @@ class ElectrodeVector : protected Pointers { double **cutsq; double g_ewald, eta; bool tfflag; + bool etaflag; + int eta_index; std::map tf_types; class Pair *pair; class NeighList *list; diff --git a/src/ELECTRODE/fix_electrode_conp.cpp b/src/ELECTRODE/fix_electrode_conp.cpp index e8b11c330b..94c085de5c 100644 --- a/src/ELECTRODE/fix_electrode_conp.cpp +++ b/src/ELECTRODE/fix_electrode_conp.cpp @@ -98,26 +98,30 @@ FixElectrodeConp::FixElectrodeConp(LAMMPS *lmp, int narg, char **arg) : top_group = 0; intelflag = false; tfflag = false; + etaflag = false; timer_flag = false; update_time = 0; mult_time = 0; n_call = n_cg_step = 0; + qtotal = 0.; + qtotal_var_style = VarStyle::UNSET; + // read fix command fixname = std::string(arg[0]); groups = std::vector(1, igroup); group_bits = std::vector(1, groupbit); group_psi_var_names = std::vector(1); group_psi_var_styles = std::vector(1, VarStyle::CONST); - group_psi = std::vector(1); + group_psi_const = std::vector(1); etypes_neighlists = false; if (strstr(arg[3], "v_") == arg[3]) { std::string vname = arg[3]; group_psi_var_names[0] = vname.substr(2); group_psi_var_styles[0] = VarStyle::EQUAL; } else - group_psi[0] = utils::numeric(FLERR, arg[3], false, lmp); + group_psi_const[0] = utils::numeric(FLERR, arg[3], false, lmp); char *eta_str = arg[4]; eta = utils::numeric(FLERR, eta_str, false, lmp); int iarg = 5; @@ -133,12 +137,12 @@ FixElectrodeConp::FixElectrodeConp(LAMMPS *lmp, int narg, char **arg) : std::string vname = arg[iarg]; group_psi_var_names.push_back(vname.substr(2)); group_psi_var_styles.push_back(VarStyle::EQUAL); - group_psi.push_back(0.); + group_psi_const.push_back(0.); } else { std::string null; group_psi_var_names.push_back(null); group_psi_var_styles.push_back(VarStyle::CONST); - group_psi.push_back(utils::numeric(FLERR, arg[iarg], false, lmp)); + group_psi_const.push_back(utils::numeric(FLERR, arg[iarg], false, lmp)); } } else if ((strcmp(arg[iarg], "algo") == 0)) { if (!default_algo) error->one(FLERR, "Algorithm can be set only once"); @@ -196,8 +200,32 @@ FixElectrodeConp::FixElectrodeConp(LAMMPS *lmp, int narg, char **arg) : thermo_temp = force->boltz / force->qe2f * utils::numeric(FLERR, arg[++iarg], false, lmp); thermo_time = utils::numeric(FLERR, arg[++iarg], false, lmp); thermo_init = utils::inumeric(FLERR, arg[++iarg], false, lmp); - // toggle parameters - } else if ((strcmp(arg[iarg], "etypes") == 0)) { + } else if ((strcmp(arg[iarg], "qtotal") == 0)) { + if (iarg + 2 > narg) error->all(FLERR, "Need one argument after qtotal keyword"); + if (strcmp(this->style, "electrode/conq") == 0) + error->all(FLERR, "qtotal keyword not available for electrode/conq"); + ++iarg; + if (strstr(arg[iarg], "v_") == arg[iarg]) { + std::string vname = arg[iarg]; + qtotal_var_name = vname.substr(2); + qtotal_var_style = VarStyle::EQUAL; + } else { + qtotal = utils::numeric(FLERR, arg[iarg], false, lmp); + qtotal_var_style = VarStyle::CONST; + } + } else if ((strcmp(arg[iarg], "eta") == 0)) { + if (iarg + 2 > narg) error->all(FLERR, "Need two arguments after eta command"); + etaflag = true; + int is_double, cols, ghost; + eta_index = atom->find_custom_ghost(arg[++iarg] + 2, is_double, cols, ghost); + if (eta_index == -1) + error->all(FLERR, "eta keyword requires name of previously defined property"); + if (!is_double) error->all(FLERR, "eta keyword requires double-valued property/atom vector"); + if (cols != 0) error->all(FLERR, "eta keyword requires property/atom vector not an array"); + if (!ghost) error->all(FLERR, "eta keyword requires property/atom fix with ghost on"); + } + // toggle parameters + else if ((strcmp(arg[iarg], "etypes") == 0)) { etypes_neighlists = utils::logical(FLERR, arg[++iarg], false, lmp); } else if ((strncmp(arg[iarg], "symm", 4) == 0)) { symm = utils::logical(FLERR, arg[++iarg], false, lmp); @@ -209,6 +237,12 @@ FixElectrodeConp::FixElectrodeConp(LAMMPS *lmp, int narg, char **arg) : iarg++; } + if (qtotal_var_style != VarStyle::UNSET) { + if (symm) error->all(FLERR, "{} cannot use qtotal keyword with symm on", this->style); + } + + // computatonal potential + group_psi = std::vector(groups.size()); // union of all coupled groups std::string union_group = "conp_group"; std::string group_cmd = union_group + " union"; @@ -226,6 +260,7 @@ FixElectrodeConp::FixElectrodeConp(LAMMPS *lmp, int narg, char **arg) : if (need_elec_vector) elec_vector = new ElectrodeVector(lmp, igroup, igroup, eta, false); assert(groups.size() == group_bits.size()); assert(groups.size() == group_psi.size()); + assert(groups.size() == group_psi_const.size()); assert(groups.size() == group_psi_var_styles.size()); assert(groups.size() == group_psi_var_names.size()); assert(igroup == elyt_vector->igroup); @@ -375,6 +410,31 @@ void FixElectrodeConp::init() if (strncmp(modify->fix[i]->style, "electrode", 9) == 0) count++; if (count > 1) error->all(FLERR, "More than one fix electrode"); + // make sure electrode atoms are not integrated if a matrix is used for electrode-electrode interaction + int const nlocal = atom->nlocal; + int *mask = atom->mask; + Fix **fix = modify->fix; + if (matrix_algo) { + std::vector integrate_ids = std::vector(); + for (int i = 0; i < modify->nfix; i++) { + if (fix[i]->time_integrate == 0) continue; + int electrode_mover = 0; + int fix_groupbit = fix[i]->groupbit; + for (int j = 0; j < nlocal; j++) + if ((mask[j] & fix_groupbit) && (mask[j] & groupbit)) electrode_mover = 1; + MPI_Allreduce(MPI_IN_PLACE, &electrode_mover, 1, MPI_INT, MPI_SUM, world); + if (electrode_mover && comm->me == 0) integrate_ids.push_back(fix[i]->id); + } + if (comm->me == 0) + for (char *fix_id : integrate_ids) + error->warning( + FLERR, + "Electrode atoms are integrated by fix {}, but fix electrode is using a matrix method. " + "For " + "mobile electrodes use the conjugate gradient algorithm without matrix ('algo cg').", + fix_id); + } + // check for package intel if (etypes_neighlists) request_etypes_neighlists(); @@ -449,6 +509,7 @@ void FixElectrodeConp::setup_post_neighbor() // get equal-style variable ids: group_psi_var_ids = std::vector(num_of_groups, -1); for (int g = 0; g < num_of_groups; g++) { + assert(group_psi_var_styles[g] != VarStyle::UNSET); if (group_psi_var_styles[g] == VarStyle::CONST) continue; const char *var_name = group_psi_var_names[g].c_str(); int var_id = input->variable->find(var_name); @@ -457,13 +518,23 @@ void FixElectrodeConp::setup_post_neighbor() error->all(FLERR, "Variable '{}' for fix {} is not equal-style", var_name, style); group_psi_var_ids[g] = var_id; } + if (qtotal_var_style == VarStyle::EQUAL) { + const char *var_name = qtotal_var_name.c_str(); + int var_id = input->variable->find(var_name); + if (var_id < 0) error->all(FLERR, "Variable '{}' for fix electrode does not exist", var_name); + if (!input->variable->equalstyle(var_id)) + error->all(FLERR, "Variable '{}' for fix electrode is not equal-style", var_name); + qtotal_var_id = var_id; + } // pair and list setups: evscale = force->qe2f / force->qqrd2e; elyt_vector->setup(pair, vec_neighlist, timer_flag); + if (etaflag) elyt_vector->setup_eta(eta_index); if (need_elec_vector) { elec_vector->setup(pair, mat_neighlist, timer_flag); + if (etaflag) elec_vector->setup_eta(eta_index); if (tfflag) elec_vector->setup_tf(tf_types); } @@ -498,7 +569,8 @@ void FixElectrodeConp::setup_post_neighbor() if (etypes_neighlists) neighbor->build_one(mat_neighlist, 0); auto array_compute = std::unique_ptr(new ElectrodeMatrix(lmp, igroup, eta)); array_compute->setup(tag_to_iele, pair, mat_neighlist); - if (tfflag) { array_compute->setup_tf(tf_types); } + if (etaflag) array_compute->setup_eta(eta_index); + if (tfflag) array_compute->setup_tf(tf_types); array_compute->compute_array(elastance, timer_flag); } // write_mat before proceeding if (comm->me == 0 && write_mat) { @@ -805,6 +877,8 @@ void FixElectrodeConp::update_charges() } MPI_Allreduce(MPI_IN_PLACE, &sb_charges.front(), num_of_groups, MPI_DOUBLE, MPI_SUM, world); update_psi(); // use for equal-style and conq + if (qtotal_var_style != VarStyle::UNSET) + update_psi_qtotal(); // use for qtotal; same for thermo for (int g = 0; g < num_of_groups; g++) for (int j = 0; j < nlocalele; j++) q_local[j] += sd_vectors[g][list_iele[j]] * group_psi[g]; MPI_Barrier(world); @@ -907,12 +981,22 @@ std::vector FixElectrodeConp::gather_ngroup(std::vector x_local) } /* ---------------------------------------------------------------------- - ensure total electrode charge is 0 if symm + ensure total electrode charge is 0 if symm and qtotal if qtotal is used ------------------------------------------------------------------------- */ std::vector FixElectrodeConp::constraint_correction(std::vector x) { - return constraint_projection(std::move(x)); + if (symm || qtotal_var_style != VarStyle::UNSET) { + if (qtotal_var_style == VarStyle::EQUAL) qtotal = input->variable->compute_equal(qtotal_var_id); + double sum = 0.; + for (double xi : x) sum += xi; + MPI_Allreduce(MPI_IN_PLACE, &sum, 1, MPI_DOUBLE, MPI_SUM, world); + if (qtotal_var_style != VarStyle::UNSET) sum -= qtotal; + sum /= ngroup; + for (double &xi : x) xi -= sum; + return x; + } + return x; } /* ---------------------------------------------------------------------- @@ -921,7 +1005,7 @@ std::vector FixElectrodeConp::constraint_correction(std::vector std::vector FixElectrodeConp::constraint_projection(std::vector x) { - if (symm) { + if (symm || qtotal_var_style != VarStyle::UNSET) { double sum = 0.; for (double xi : x) sum += xi; MPI_Allreduce(MPI_IN_PLACE, &sum, 1, MPI_DOUBLE, MPI_SUM, world); @@ -979,13 +1063,28 @@ std::vector FixElectrodeConp::times_elastance(std::vector x) void FixElectrodeConp::update_psi() { for (int g = 0; g < num_of_groups; g++) { - if (group_psi_var_styles[g] == VarStyle::CONST) continue; - group_psi[g] = input->variable->compute_equal(group_psi_var_ids[g]); + if (group_psi_var_styles[g] == VarStyle::CONST) + group_psi[g] = group_psi_const[g]; + else + group_psi[g] = input->variable->compute_equal(group_psi_var_ids[g]); } } /* ---------------------------------------------------------------------- */ +void FixElectrodeConp::update_psi_qtotal() +{ + if (qtotal_var_style == VarStyle::EQUAL) qtotal = input->variable->compute_equal(qtotal_var_id); + double q_current = 0.; + for (int i = 0; i < num_of_groups; i++) { + q_current += sb_charges[i]; + for (int j = 0; j < num_of_groups; j++) q_current += macro_capacitance[i][j] * group_psi[j]; + } + double add_psi = (qtotal - q_current) / macro_capacitance_sum; + for (int i = 0; i < num_of_groups; i++) group_psi[i] += add_psi; +} +/* ---------------------------------------------------------------------- */ + void FixElectrodeConp::compute_macro_matrices() { assert(algo == Algo::MATRIX_INV); @@ -1041,6 +1140,10 @@ void FixElectrodeConp::compute_macro_matrices() } } } + + macro_capacitance_sum = 0.; + for (int i = 0; i < num_of_groups; i++) + for (int j = 0; j < num_of_groups; j++) macro_capacitance_sum += macro_capacitance[i][j]; } /* ---------------------------------------------------------------------- */ @@ -1097,7 +1200,7 @@ double FixElectrodeConp::self_energy(int eflag) // corrections to energy due to self interaction double const qqrd2e = force->qqrd2e; int const nlocal = atom->nlocal; - double const pre = eta / sqrt(MY_2PI) * qqrd2e; + double const pre = 1. / sqrt(MY_2PI) * qqrd2e; int *mask = atom->mask; int *type = atom->type; double *q = atom->q; @@ -1105,7 +1208,8 @@ double FixElectrodeConp::self_energy(int eflag) for (int i = 0; i < nlocal; i++) { if (groupbit & mask[i]) { double const q2 = q[i] * q[i]; - double e = pre * q2; + double ieta = etaflag ? atom->dvector[eta_index][i] : eta; + double e = ieta * pre * q2; if (tfflag && (groupbit & mask[i])) e += 0.5 * qqrd2e * q2 * tf_types[type[i]]; energy += e; if (eflag) { @@ -1145,6 +1249,7 @@ double FixElectrodeConp::gausscorr(int eflag, bool fflag) double xtmp = x[i][0]; double ytmp = x[i][1]; double ztmp = x[i][2]; + double const eta_i = etaflag ? atom->dvector[eta_index][i] : eta; int itype = type[i]; int *jlist = firstneigh[i]; int jnum = numneigh[i]; @@ -1153,7 +1258,6 @@ double FixElectrodeConp::gausscorr(int eflag, bool fflag) int const j = jlist[jj] & NEIGHMASK; bool j_in_ele = groupbit & mask[j]; if (!(i_in_ele || j_in_ele)) continue; - double eta_ij = (i_in_ele && j_in_ele) ? eta / MY_SQRT2 : eta; double delx = xtmp - x[j][0]; double dely = ytmp - x[j][1]; @@ -1162,6 +1266,16 @@ double FixElectrodeConp::gausscorr(int eflag, bool fflag) int jtype = type[j]; if (rsq < force->pair->cutsq[itype][jtype]) { + double const eta_j = etaflag ? atom->dvector[eta_index][j] : eta; + double eta_ij; + if (i_in_ele && j_in_ele) + eta_ij = eta_i * eta_j / sqrt(eta_i * eta_i + eta_j * eta_j); + else if (i_in_ele) + eta_ij = eta_i; + else { + assert(j_in_ele); + eta_ij = eta_j; + } double r2inv = 1.0 / rsq; double r = sqrt(rsq); double erfc_etar = 0.; diff --git a/src/ELECTRODE/fix_electrode_conp.h b/src/ELECTRODE/fix_electrode_conp.h index 46da1eec35..a1d7530bd1 100644 --- a/src/ELECTRODE/fix_electrode_conp.h +++ b/src/ELECTRODE/fix_electrode_conp.h @@ -70,7 +70,7 @@ class FixElectrodeConp : public Fix { protected: enum class Algo { MATRIX_INV, MATRIX_CG, CG }; - enum class VarStyle { CONST, EQUAL }; + enum class VarStyle { CONST, EQUAL, UNSET }; virtual void update_psi(); virtual void pre_update(){}; virtual void recompute_potential(std::vector, std::vector){}; @@ -79,6 +79,7 @@ class FixElectrodeConp : public Fix { virtual void compute_macro_matrices(); std::vector ele_ele_interaction(const std::vector &); std::vector group_psi; + std::vector group_psi_const; // needed to undo qtotal psi updates std::vector group_bits; std::vector groups; int num_of_groups; @@ -100,6 +101,10 @@ class FixElectrodeConp : public Fix { std::string fixname; // used by electrode/ffield to set up internal efield bool intelflag; inline virtual void intel_pack_buffers() {} + double qtotal; + std::string qtotal_var_name; + int qtotal_var_id; + VarStyle qtotal_var_style; private: std::string output_file_inv, output_file_mat, output_file_vec; @@ -132,6 +137,8 @@ class FixElectrodeConp : public Fix { int get_top_group(); // used by ffield int top_group; // used by ffield bool tfflag; + int eta_index; // index of atom property for eta + bool etaflag; // eta specified as atom property bool timer_flag; std::map tf_types; // cg @@ -142,6 +149,9 @@ class FixElectrodeConp : public Fix { std::vector gather_ngroup(std::vector); std::vector gather_elevec_local(ElectrodeVector *); void set_charges(std::vector); + // qtotal + double macro_capacitance_sum; + void update_psi_qtotal(); // fix-specific electrode ID storage system: diff --git a/src/ELECTRODE/fix_electrode_conq.cpp b/src/ELECTRODE/fix_electrode_conq.cpp index 0d3d1d2aaf..a6baa1e122 100644 --- a/src/ELECTRODE/fix_electrode_conq.cpp +++ b/src/ELECTRODE/fix_electrode_conq.cpp @@ -30,7 +30,7 @@ FixElectrodeConq::FixElectrodeConq(LAMMPS *lmp, int narg, char **arg) : FixElectrodeConp(lmp, narg, arg) { // copy const-style values across because update_psi will change group_psi - group_q = group_psi; + group_q = group_psi_const; if (symm) { if (num_of_groups == 1) diff --git a/src/ELECTRODE/fix_electrode_thermo.cpp b/src/ELECTRODE/fix_electrode_thermo.cpp index 343bf14069..92db4b3ee0 100644 --- a/src/ELECTRODE/fix_electrode_thermo.cpp +++ b/src/ELECTRODE/fix_electrode_thermo.cpp @@ -47,7 +47,8 @@ FixElectrodeThermo::FixElectrodeThermo(LAMMPS *lmp, int narg, char **arg) : if (thermo_time < SMALL) error->all(FLERR, "Keyword temp not set or zero in electrode/thermo"); thermo_random = new RanMars(lmp, thermo_init); - if (group_psi_var_styles[0] == VarStyle::CONST) delta_psi_0 = group_psi[1] - group_psi[0]; + if (group_psi_var_styles[0] == VarStyle::CONST) + delta_psi_0 = group_psi_const[1] - group_psi_const[0]; } /* ----------------------------------------------------------------------- */ @@ -102,7 +103,7 @@ void FixElectrodeThermo::update_psi() double const delta_psi = group_psi_old[1] - group_psi_old[0]; // target potential difference from input parameters - if (group_psi_var_styles[0] != VarStyle::CONST) { + if (group_psi_var_styles[0] == VarStyle::EQUAL) { delta_psi_0 = input->variable->compute_equal(group_psi_var_ids[1]) - input->variable->compute_equal(group_psi_var_ids[0]); } diff --git a/src/ELECTRODE/pppm_electrode.cpp b/src/ELECTRODE/pppm_electrode.cpp index 98a76a7cca..ee34def74d 100644 --- a/src/ELECTRODE/pppm_electrode.cpp +++ b/src/ELECTRODE/pppm_electrode.cpp @@ -438,6 +438,7 @@ void PPPMElectrode::compute(int eflag, int vflag) start_compute(); + /* if (compute_vector_called && last_invert_source) { // electrolyte_density_brick is filled, so we can grab only electrode atoms. // Does not work for direct cg algorithm because electrode charges change after compute_vector. @@ -453,15 +454,17 @@ void PPPMElectrode::compute(int eflag, int vflag) density_brick[nz][ny][nx] += electrolyte_density_brick[nz][ny][nx]; } } else { - make_rho(); + */ + particle_map(); + make_rho(); - // all procs communicate density values from their ghost cells - // to fully sum contribution in their 3d bricks - // remap from 3d decomposition to FFT decomposition + // all procs communicate density values from their ghost cells + // to fully sum contribution in their 3d bricks + // remap from 3d decomposition to FFT decomposition - gc->reverse_comm(Grid3d::KSPACE, this, REVERSE_RHO, 1, sizeof(FFT_SCALAR), gc_buf1, gc_buf2, - MPI_FFT_SCALAR); - } + gc->reverse_comm(Grid3d::KSPACE, this, REVERSE_RHO, 1, sizeof(FFT_SCALAR), gc_buf1, gc_buf2, + MPI_FFT_SCALAR); + //} brick2fft(); @@ -584,6 +587,7 @@ void PPPMElectrode::compute_vector(double *vec, int sensor_grpbit, int source_gr // electrolyte density (without writing an additional function) FFT_SCALAR ***density_brick_real = density_brick; FFT_SCALAR *density_fft_real = density_fft; + particle_map(); make_rho_in_brick(source_grpbit, electrolyte_density_brick, invert_source); density_brick = electrolyte_density_brick; density_fft = electrolyte_density_fft; @@ -669,7 +673,8 @@ void PPPMElectrode::compute_matrix(bigint *imat, double **matrix, bool timer_fla // fft green's function k -> r (double) double *greens_real; memory->create(greens_real, nz_pppm * ny_pppm * nx_pppm, "pppm/electrode:greens_real"); - memset(greens_real, 0, (std::size_t)nz_pppm * (std::size_t)ny_pppm * (std::size_t)nx_pppm * sizeof(double)); + memset(greens_real, 0, + (std::size_t) nz_pppm * (std::size_t) ny_pppm * (std::size_t) nx_pppm * sizeof(double)); for (int i = 0, n = 0; i < nfft; i++) { work2[n++] = greensfn[i]; work2[n++] = ZEROF; @@ -862,7 +867,7 @@ void PPPMElectrode::two_step_multiplication(bigint *imat, double *greens_real, d double **gw; memory->create(gw, nmat, nxyz, "pppm/electrode:gw"); - memset(&(gw[0][0]), 0, (std::size_t)nmat * (std::size_t)nxyz * sizeof(double)); + memset(&(gw[0][0]), 0, (std::size_t) nmat * (std::size_t) nxyz * sizeof(double)); auto fmod = [](int x, int n) { // fast unsigned mod int r = abs(x); @@ -981,17 +986,18 @@ void PPPMElectrode::allocate() // returns local owned and ghost grid bounds // setup communication patterns and buffers - gc = new Grid3d(lmp,world,nx_pppm,ny_pppm,nz_pppm, - nxlo_in,nxhi_in,nylo_in,nyhi_in,nzlo_in,nzhi_in, - nxlo_out,nxhi_out,nylo_out,nyhi_out,nzlo_out,nzhi_out); + gc = new Grid3d(lmp, world, nx_pppm, ny_pppm, nz_pppm, nxlo_in, nxhi_in, nylo_in, nyhi_in, + nzlo_in, nzhi_in, nxlo_out, nxhi_out, nylo_out, nyhi_out, nzlo_out, nzhi_out); - gc->setup_comm(ngc_buf1,ngc_buf2); + gc->setup_comm(ngc_buf1, ngc_buf2); - if (differentiation_flag) npergrid = 1; - else npergrid = 3; + if (differentiation_flag) + npergrid = 1; + else + npergrid = 3; - memory->create(gc_buf1,npergrid*ngc_buf1,"pppm:gc_buf1"); - memory->create(gc_buf2,npergrid*ngc_buf2,"pppm:gc_buf2"); + memory->create(gc_buf1, npergrid * ngc_buf1, "pppm:gc_buf1"); + memory->create(gc_buf2, npergrid * ngc_buf2, "pppm:gc_buf2"); // tally local grid sizes // ngrid = count of owned+ghost grid cells on this proc @@ -1000,67 +1006,63 @@ void PPPMElectrode::allocate() // nfft = FFT points in x-pencil FFT decomposition on this proc // nfft_both = greater of nfft and nfft_brick - ngrid = (nxhi_out-nxlo_out+1) * (nyhi_out-nylo_out+1) * - (nzhi_out-nzlo_out+1); + ngrid = (nxhi_out - nxlo_out + 1) * (nyhi_out - nylo_out + 1) * (nzhi_out - nzlo_out + 1); - nfft_brick = (nxhi_in-nxlo_in+1) * (nyhi_in-nylo_in+1) * - (nzhi_in-nzlo_in+1); + nfft_brick = (nxhi_in - nxlo_in + 1) * (nyhi_in - nylo_in + 1) * (nzhi_in - nzlo_in + 1); - nfft = (nxhi_fft-nxlo_fft+1) * (nyhi_fft-nylo_fft+1) * - (nzhi_fft-nzlo_fft+1); + nfft = (nxhi_fft - nxlo_fft + 1) * (nyhi_fft - nylo_fft + 1) * (nzhi_fft - nzlo_fft + 1); - nfft_both = MAX(nfft,nfft_brick); + nfft_both = MAX(nfft, nfft_brick); // allocate distributed grid data - memory->create3d_offset(density_brick,nzlo_out,nzhi_out,nylo_out,nyhi_out, - nxlo_out,nxhi_out,"pppm:density_brick"); + memory->create3d_offset(density_brick, nzlo_out, nzhi_out, nylo_out, nyhi_out, nxlo_out, nxhi_out, + "pppm:density_brick"); - memory->create(density_fft,nfft_both,"pppm:density_fft"); - memory->create(greensfn,nfft_both,"pppm:greensfn"); - memory->create(work1,2*nfft_both,"pppm:work1"); - memory->create(work2,2*nfft_both,"pppm:work2"); - memory->create(vg,nfft_both,6,"pppm:vg"); + memory->create(density_fft, nfft_both, "pppm:density_fft"); + memory->create(greensfn, nfft_both, "pppm:greensfn"); + memory->create(work1, 2 * nfft_both, "pppm:work1"); + memory->create(work2, 2 * nfft_both, "pppm:work2"); + memory->create(vg, nfft_both, 6, "pppm:vg"); if (triclinic == 0) { - memory->create1d_offset(fkx,nxlo_fft,nxhi_fft,"pppm:fkx"); - memory->create1d_offset(fky,nylo_fft,nyhi_fft,"pppm:fky"); - memory->create1d_offset(fkz,nzlo_fft,nzhi_fft,"pppm:fkz"); + memory->create1d_offset(fkx, nxlo_fft, nxhi_fft, "pppm:fkx"); + memory->create1d_offset(fky, nylo_fft, nyhi_fft, "pppm:fky"); + memory->create1d_offset(fkz, nzlo_fft, nzhi_fft, "pppm:fkz"); } else { - memory->create(fkx,nfft_both,"pppm:fkx"); - memory->create(fky,nfft_both,"pppm:fky"); - memory->create(fkz,nfft_both,"pppm:fkz"); + memory->create(fkx, nfft_both, "pppm:fkx"); + memory->create(fky, nfft_both, "pppm:fky"); + memory->create(fkz, nfft_both, "pppm:fkz"); } if (differentiation_flag == 1) { - memory->create3d_offset(u_brick,nzlo_out,nzhi_out,nylo_out,nyhi_out, - nxlo_out,nxhi_out,"pppm:u_brick"); + memory->create3d_offset(u_brick, nzlo_out, nzhi_out, nylo_out, nyhi_out, nxlo_out, nxhi_out, + "pppm:u_brick"); - memory->create(sf_precoeff1,nfft_both,"pppm:sf_precoeff1"); - memory->create(sf_precoeff2,nfft_both,"pppm:sf_precoeff2"); - memory->create(sf_precoeff3,nfft_both,"pppm:sf_precoeff3"); - memory->create(sf_precoeff4,nfft_both,"pppm:sf_precoeff4"); - memory->create(sf_precoeff5,nfft_both,"pppm:sf_precoeff5"); - memory->create(sf_precoeff6,nfft_both,"pppm:sf_precoeff6"); + memory->create(sf_precoeff1, nfft_both, "pppm:sf_precoeff1"); + memory->create(sf_precoeff2, nfft_both, "pppm:sf_precoeff2"); + memory->create(sf_precoeff3, nfft_both, "pppm:sf_precoeff3"); + memory->create(sf_precoeff4, nfft_both, "pppm:sf_precoeff4"); + memory->create(sf_precoeff5, nfft_both, "pppm:sf_precoeff5"); + memory->create(sf_precoeff6, nfft_both, "pppm:sf_precoeff6"); } else { - memory->create3d_offset(vdx_brick,nzlo_out,nzhi_out,nylo_out,nyhi_out, - nxlo_out,nxhi_out,"pppm:vdx_brick"); - memory->create3d_offset(vdy_brick,nzlo_out,nzhi_out,nylo_out,nyhi_out, - nxlo_out,nxhi_out,"pppm:vdy_brick"); - memory->create3d_offset(vdz_brick,nzlo_out,nzhi_out,nylo_out,nyhi_out, - nxlo_out,nxhi_out,"pppm:vdz_brick"); + memory->create3d_offset(vdx_brick, nzlo_out, nzhi_out, nylo_out, nyhi_out, nxlo_out, nxhi_out, + "pppm:vdx_brick"); + memory->create3d_offset(vdy_brick, nzlo_out, nzhi_out, nylo_out, nyhi_out, nxlo_out, nxhi_out, + "pppm:vdy_brick"); + memory->create3d_offset(vdz_brick, nzlo_out, nzhi_out, nylo_out, nyhi_out, nxlo_out, nxhi_out, + "pppm:vdz_brick"); } // summation coeffs order_allocated = order; - if (!stagger_flag) memory->create(gf_b,order,"pppm:gf_b"); - memory->create2d_offset(rho1d,3,-order/2,order/2,"pppm:rho1d"); - memory->create2d_offset(drho1d,3,-order/2,order/2,"pppm:drho1d"); - memory->create2d_offset(rho_coeff,order,(1-order)/2,order/2,"pppm:rho_coeff"); - memory->create2d_offset(drho_coeff,order,(1-order)/2,order/2, - "pppm:drho_coeff"); + if (!stagger_flag) memory->create(gf_b, order, "pppm:gf_b"); + memory->create2d_offset(rho1d, 3, -order / 2, order / 2, "pppm:rho1d"); + memory->create2d_offset(drho1d, 3, -order / 2, order / 2, "pppm:drho1d"); + memory->create2d_offset(rho_coeff, order, (1 - order) / 2, order / 2, "pppm:rho_coeff"); + memory->create2d_offset(drho_coeff, order, (1 - order) / 2, order / 2, "pppm:drho_coeff"); // create 2 FFTs and a Remap // 1st FFT keeps data in FFT decomposition @@ -1069,20 +1071,17 @@ void PPPMElectrode::allocate() int tmp; - fft1 = new FFT3d(lmp,world,nx_pppm,ny_pppm,nz_pppm, - nxlo_fft,nxhi_fft,nylo_fft,nyhi_fft,nzlo_fft,nzhi_fft, - nxlo_fft,nxhi_fft,nylo_fft,nyhi_fft,nzlo_fft,nzhi_fft, - 0,0,&tmp,collective_flag); + fft1 = new FFT3d(lmp, world, nx_pppm, ny_pppm, nz_pppm, nxlo_fft, nxhi_fft, nylo_fft, nyhi_fft, + nzlo_fft, nzhi_fft, nxlo_fft, nxhi_fft, nylo_fft, nyhi_fft, nzlo_fft, nzhi_fft, + 0, 0, &tmp, collective_flag); - fft2 = new FFT3d(lmp,world,nx_pppm,ny_pppm,nz_pppm, - nxlo_fft,nxhi_fft,nylo_fft,nyhi_fft,nzlo_fft,nzhi_fft, - nxlo_in,nxhi_in,nylo_in,nyhi_in,nzlo_in,nzhi_in, - 0,0,&tmp,collective_flag); + fft2 = new FFT3d(lmp, world, nx_pppm, ny_pppm, nz_pppm, nxlo_fft, nxhi_fft, nylo_fft, nyhi_fft, + nzlo_fft, nzhi_fft, nxlo_in, nxhi_in, nylo_in, nyhi_in, nzlo_in, nzhi_in, 0, 0, + &tmp, collective_flag); - remap = new Remap(lmp,world, - nxlo_in,nxhi_in,nylo_in,nyhi_in,nzlo_in,nzhi_in, - nxlo_fft,nxhi_fft,nylo_fft,nyhi_fft,nzlo_fft,nzhi_fft, - 1,0,0,FFT_PRECISION,collective_flag); + remap = new Remap(lmp, world, nxlo_in, nxhi_in, nylo_in, nyhi_in, nzlo_in, nzhi_in, nxlo_fft, + nxhi_fft, nylo_fft, nyhi_fft, nzlo_fft, nzhi_fft, 1, 0, 0, FFT_PRECISION, + collective_flag); // ELECTRODE specific allocations diff --git a/src/KOKKOS/atom_vec_angle_kokkos.cpp b/src/KOKKOS/atom_vec_angle_kokkos.cpp index 418c2d629d..dc8641a6b6 100644 --- a/src/KOKKOS/atom_vec_angle_kokkos.cpp +++ b/src/KOKKOS/atom_vec_angle_kokkos.cpp @@ -186,302 +186,13 @@ void AtomVecAngleKokkos::sort_kokkos(Kokkos::BinSort &Sorter /* ---------------------------------------------------------------------- */ -template -struct AtomVecAngleKokkos_PackComm { - typedef DeviceType device_type; - - typename ArrayTypes::t_x_array_randomread _x; - typename ArrayTypes::t_xfloat_2d_um _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; - X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; - X_FLOAT _pbc[6]; - - AtomVecAngleKokkos_PackComm( - const typename DAT::tdual_x_array &x, - const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int & iswap, - const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, - const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): - _x(x.view()),_list(list.view()),_iswap(iswap), - _xprd(xprd),_yprd(yprd),_zprd(zprd), - _xy(xy),_xz(xz),_yz(yz) { - const size_t maxsend = (buf.view().extent(0) - *buf.view().extent(1))/3; - const size_t elements = 3; - buffer_view(_buf,buf,maxsend,elements); - _pbc[0] = pbc[0]; _pbc[1] = pbc[1]; _pbc[2] = pbc[2]; - _pbc[3] = pbc[3]; _pbc[4] = pbc[4]; _pbc[5] = pbc[5]; - }; - - KOKKOS_INLINE_FUNCTION - void operator() (const int& i) const { - const int j = _list(_iswap,i); - if (PBC_FLAG == 0) { - _buf(i,0) = _x(j,0); - _buf(i,1) = _x(j,1); - _buf(i,2) = _x(j,2); - } else { - if (TRICLINIC == 0) { - _buf(i,0) = _x(j,0) + _pbc[0]*_xprd; - _buf(i,1) = _x(j,1) + _pbc[1]*_yprd; - _buf(i,2) = _x(j,2) + _pbc[2]*_zprd; - } else { - _buf(i,0) = _x(j,0) + _pbc[0]*_xprd + _pbc[5]*_xy + _pbc[4]*_xz; - _buf(i,1) = _x(j,1) + _pbc[1]*_yprd + _pbc[3]*_yz; - _buf(i,2) = _x(j,2) + _pbc[2]*_zprd; - } - } - } -}; - -/* ---------------------------------------------------------------------- */ - -int AtomVecAngleKokkos::pack_comm_kokkos(const int &n, - const DAT::tdual_int_2d &list, - const int & iswap, - const DAT::tdual_xfloat_2d &buf, - const int &pbc_flag, - const int* const pbc) -{ - // Check whether to always run forward communication on the host - // Choose correct forward PackComm kernel - - if (commKK->forward_comm_on_host) { - atomKK->sync(Host,X_MASK); - if (pbc_flag) { - if (domain->triclinic) { - struct AtomVecAngleKokkos_PackComm f(atomKK->k_x,buf,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecAngleKokkos_PackComm f(atomKK->k_x,buf,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } else { - if (domain->triclinic) { - struct AtomVecAngleKokkos_PackComm f(atomKK->k_x,buf,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecAngleKokkos_PackComm f(atomKK->k_x,buf,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } - } else { - atomKK->sync(Device,X_MASK); - if (pbc_flag) { - if (domain->triclinic) { - struct AtomVecAngleKokkos_PackComm f(atomKK->k_x,buf,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecAngleKokkos_PackComm f(atomKK->k_x,buf,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } else { - if (domain->triclinic) { - struct AtomVecAngleKokkos_PackComm f(atomKK->k_x,buf,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecAngleKokkos_PackComm f(atomKK->k_x,buf,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } - } - - return n*size_forward; -} - -/* ---------------------------------------------------------------------- */ - -template -struct AtomVecAngleKokkos_PackCommSelf { - typedef DeviceType device_type; - - typename ArrayTypes::t_x_array_randomread _x; - typename ArrayTypes::t_x_array _xw; - int _nfirst; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; - X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; - X_FLOAT _pbc[6]; - - AtomVecAngleKokkos_PackCommSelf( - const typename DAT::tdual_x_array &x, - const int &nfirst, - const typename DAT::tdual_int_2d &list, - const int & iswap, - const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, - const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): - _x(x.view()),_xw(x.view()),_nfirst(nfirst),_list(list.view()),_iswap(iswap), - _xprd(xprd),_yprd(yprd),_zprd(zprd), - _xy(xy),_xz(xz),_yz(yz) { - _pbc[0] = pbc[0]; _pbc[1] = pbc[1]; _pbc[2] = pbc[2]; - _pbc[3] = pbc[3]; _pbc[4] = pbc[4]; _pbc[5] = pbc[5]; - }; - - KOKKOS_INLINE_FUNCTION - void operator() (const int& i) const { - const int j = _list(_iswap,i); - if (PBC_FLAG == 0) { - _xw(i+_nfirst,0) = _x(j,0); - _xw(i+_nfirst,1) = _x(j,1); - _xw(i+_nfirst,2) = _x(j,2); - } else { - if (TRICLINIC == 0) { - _xw(i+_nfirst,0) = _x(j,0) + _pbc[0]*_xprd; - _xw(i+_nfirst,1) = _x(j,1) + _pbc[1]*_yprd; - _xw(i+_nfirst,2) = _x(j,2) + _pbc[2]*_zprd; - } else { - _xw(i+_nfirst,0) = _x(j,0) + _pbc[0]*_xprd + _pbc[5]*_xy + _pbc[4]*_xz; - _xw(i+_nfirst,1) = _x(j,1) + _pbc[1]*_yprd + _pbc[3]*_yz; - _xw(i+_nfirst,2) = _x(j,2) + _pbc[2]*_zprd; - } - } - - } -}; - -/* ---------------------------------------------------------------------- */ - -int AtomVecAngleKokkos::pack_comm_self(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, - const int nfirst, const int &pbc_flag, - const int* const pbc) { - if (commKK->forward_comm_on_host) { - atomKK->sync(Host,X_MASK); - atomKK->modified(Host,X_MASK); - if (pbc_flag) { - if (domain->triclinic) { - struct AtomVecAngleKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecAngleKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } else { - if (domain->triclinic) { - struct AtomVecAngleKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecAngleKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } - } else { - atomKK->sync(Device,X_MASK); - atomKK->modified(Device,X_MASK); - if (pbc_flag) { - if (domain->triclinic) { - struct AtomVecAngleKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecAngleKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } else { - if (domain->triclinic) { - struct AtomVecAngleKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecAngleKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap, - domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } - } - return n*3; -} - -/* ---------------------------------------------------------------------- */ - -template -struct AtomVecAngleKokkos_UnpackComm { - typedef DeviceType device_type; - - typename ArrayTypes::t_x_array _x; - typename ArrayTypes::t_xfloat_2d_const _buf; - int _first; - - AtomVecAngleKokkos_UnpackComm( - const typename DAT::tdual_x_array &x, - const typename DAT::tdual_xfloat_2d &buf, - const int& first):_x(x.view()),_buf(buf.view()), - _first(first) {}; - - KOKKOS_INLINE_FUNCTION - void operator() (const int& i) const { - _x(i+_first,0) = _buf(i,0); - _x(i+_first,1) = _buf(i,1); - _x(i+_first,2) = _buf(i,2); - } -}; - -/* ---------------------------------------------------------------------- */ - -void AtomVecAngleKokkos::unpack_comm_kokkos(const int &n, const int &first, - const DAT::tdual_xfloat_2d &buf) { - if (commKK->forward_comm_on_host) { - atomKK->sync(Host,X_MASK); - atomKK->modified(Host,X_MASK); - struct AtomVecAngleKokkos_UnpackComm f(atomKK->k_x,buf,first); - Kokkos::parallel_for(n,f); - } else { - atomKK->sync(Device,X_MASK); - atomKK->modified(Device,X_MASK); - struct AtomVecAngleKokkos_UnpackComm f(atomKK->k_x,buf,first); - Kokkos::parallel_for(n,f); - } -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecAngleKokkos_PackBorder { typedef DeviceType device_type; typedef ArrayTypes AT; typename AT::t_xfloat_2d _buf; - const typename AT::t_int_2d_const _list; - const int _iswap; + const typename AT::t_int_1d_const _list; const typename AT::t_x_array_randomread _x; const typename AT::t_tagint_1d _tag; const typename AT::t_int_1d _type; @@ -491,21 +202,20 @@ struct AtomVecAngleKokkos_PackBorder { AtomVecAngleKokkos_PackBorder( const typename AT::t_xfloat_2d &buf, - const typename AT::t_int_2d_const &list, - const int & iswap, + const typename AT::t_int_1d_const &list, const typename AT::t_x_array &x, const typename AT::t_tagint_1d &tag, const typename AT::t_int_1d &type, const typename AT::t_int_1d &mask, const typename AT::t_tagint_1d &molecule, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask),_molecule(molecule), _dx(dx),_dy(dy),_dz(dz) {} KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -528,8 +238,8 @@ struct AtomVecAngleKokkos_PackBorder { /* ---------------------------------------------------------------------- */ -int AtomVecAngleKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, +int AtomVecAngleKokkos::pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -547,12 +257,12 @@ int AtomVecAngleKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecAngleKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecAngleKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } @@ -561,12 +271,12 @@ int AtomVecAngleKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecAngleKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecAngleKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } } diff --git a/src/KOKKOS/atom_vec_angle_kokkos.h b/src/KOKKOS/atom_vec_angle_kokkos.h index 44f1d824b2..157e8b45cc 100644 --- a/src/KOKKOS/atom_vec_angle_kokkos.h +++ b/src/KOKKOS/atom_vec_angle_kokkos.h @@ -35,17 +35,8 @@ class AtomVecAngleKokkos : public AtomVecKokkos, public AtomVecAngle { void grow(int) override; void grow_pointers() override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_comm_kokkos(const int &n, const DAT::tdual_int_2d &k_sendlist, - const int & iswap, - const DAT::tdual_xfloat_2d &buf, - const int &pbc_flag, const int pbc[]) override; - void unpack_comm_kokkos(const int &n, const int &nfirst, - const DAT::tdual_xfloat_2d &buf) override; - int pack_comm_self(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const int nfirst, - const int &pbc_flag, const int pbc[]) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_atomic_kokkos.cpp b/src/KOKKOS/atom_vec_atomic_kokkos.cpp index a69ff85c54..81f4f55962 100644 --- a/src/KOKKOS/atom_vec_atomic_kokkos.cpp +++ b/src/KOKKOS/atom_vec_atomic_kokkos.cpp @@ -124,8 +124,7 @@ struct AtomVecAtomicKokkos_PackBorder { typedef DeviceType device_type; typename ArrayTypes::t_xfloat_2d _buf; - const typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + const typename ArrayTypes::t_int_1d_const _list; const typename ArrayTypes::t_x_array_randomread _x; const typename ArrayTypes::t_tagint_1d _tag; const typename ArrayTypes::t_int_1d _type; @@ -134,20 +133,19 @@ struct AtomVecAtomicKokkos_PackBorder { AtomVecAtomicKokkos_PackBorder( const typename ArrayTypes::t_xfloat_2d &buf, - const typename ArrayTypes::t_int_2d_const &list, - const int &iswap, + const typename ArrayTypes::t_int_1d_const &list, const typename ArrayTypes::t_x_array &x, const typename ArrayTypes::t_tagint_1d &tag, const typename ArrayTypes::t_int_1d &type, const typename ArrayTypes::t_int_1d &mask, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask), _dx(dx),_dy(dy),_dz(dz) {} KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -168,7 +166,7 @@ struct AtomVecAtomicKokkos_PackBorder { /* ---------------------------------------------------------------------- */ -int AtomVecAtomicKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, +int AtomVecAtomicKokkos::pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -186,12 +184,12 @@ int AtomVecAtomicKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecAtomicKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,dx,dy,dz); + h_x,h_tag,h_type,h_mask,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecAtomicKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,dx,dy,dz); + d_x,d_tag,d_type,d_mask,dx,dy,dz); Kokkos::parallel_for(n,f); } @@ -200,12 +198,12 @@ int AtomVecAtomicKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecAtomicKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,dx,dy,dz); + h_x,h_tag,h_type,h_mask,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecAtomicKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,dx,dy,dz); + d_x,d_tag,d_type,d_mask,dx,dy,dz); Kokkos::parallel_for(n,f); } } diff --git a/src/KOKKOS/atom_vec_atomic_kokkos.h b/src/KOKKOS/atom_vec_atomic_kokkos.h index 07631dda98..457b5b61a9 100644 --- a/src/KOKKOS/atom_vec_atomic_kokkos.h +++ b/src/KOKKOS/atom_vec_atomic_kokkos.h @@ -36,8 +36,8 @@ class AtomVecAtomicKokkos : public AtomVecKokkos, public AtomVecAtomic { void grow(int) override; void grow_pointers() override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_bond_kokkos.cpp b/src/KOKKOS/atom_vec_bond_kokkos.cpp index 3684d30acf..6b32574c2a 100644 --- a/src/KOKKOS/atom_vec_bond_kokkos.cpp +++ b/src/KOKKOS/atom_vec_bond_kokkos.cpp @@ -157,8 +157,7 @@ struct AtomVecBondKokkos_PackBorder { typedef ArrayTypes AT; typename AT::t_xfloat_2d _buf; - const typename AT::t_int_2d_const _list; - const int _iswap; + const typename AT::t_int_1d_const _list; const typename AT::t_x_array_randomread _x; const typename AT::t_tagint_1d _tag; const typename AT::t_int_1d _type; @@ -168,21 +167,20 @@ struct AtomVecBondKokkos_PackBorder { AtomVecBondKokkos_PackBorder( const typename AT::t_xfloat_2d &buf, - const typename AT::t_int_2d_const &list, - const int & iswap, + const typename AT::t_int_1d_const &list, const typename AT::t_x_array &x, const typename AT::t_tagint_1d &tag, const typename AT::t_int_1d &type, const typename AT::t_int_1d &mask, const typename AT::t_tagint_1d &molecule, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask),_molecule(molecule), _dx(dx),_dy(dy),_dz(dz) {} KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -205,8 +203,8 @@ struct AtomVecBondKokkos_PackBorder { /* ---------------------------------------------------------------------- */ -int AtomVecBondKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, +int AtomVecBondKokkos::pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -224,12 +222,12 @@ int AtomVecBondKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecBondKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecBondKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } @@ -238,12 +236,12 @@ int AtomVecBondKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecBondKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecBondKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } } diff --git a/src/KOKKOS/atom_vec_bond_kokkos.h b/src/KOKKOS/atom_vec_bond_kokkos.h index 5ed59432de..cad1ea86d7 100644 --- a/src/KOKKOS/atom_vec_bond_kokkos.h +++ b/src/KOKKOS/atom_vec_bond_kokkos.h @@ -35,8 +35,8 @@ class AtomVecBondKokkos : public AtomVecKokkos, public AtomVecBond { void grow(int) override; void grow_pointers() override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_charge_kokkos.cpp b/src/KOKKOS/atom_vec_charge_kokkos.cpp index a479e4f216..637a219433 100644 --- a/src/KOKKOS/atom_vec_charge_kokkos.cpp +++ b/src/KOKKOS/atom_vec_charge_kokkos.cpp @@ -133,19 +133,17 @@ struct AtomVecChargeKokkos_PackComm { typename AT::t_x_array_randomread _x; typename AT::t_xfloat_2d_um _buf; - typename AT::t_int_2d_const _list; - const int _iswap; + typename AT::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; AtomVecChargeKokkos_PackComm( const typename DAT::tdual_x_array &x, const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int & iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): - _x(x.view()),_list(list.view()),_iswap(iswap), + _x(x.view()),_list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz) { const size_t maxsend = (buf.view().extent(0)*buf.view().extent(1))/3; @@ -157,7 +155,7 @@ struct AtomVecChargeKokkos_PackComm { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -184,8 +182,7 @@ struct AtomVecChargeKokkos_PackBorder { typedef ArrayTypes AT; typename AT::t_xfloat_2d _buf; - const typename AT::t_int_2d_const _list; - const int _iswap; + const typename AT::t_int_1d_const _list; const typename AT::t_x_array_randomread _x; const typename AT::t_tagint_1d _tag; const typename AT::t_int_1d _type; @@ -195,21 +192,20 @@ struct AtomVecChargeKokkos_PackBorder { AtomVecChargeKokkos_PackBorder( const typename AT::t_xfloat_2d &buf, - const typename AT::t_int_2d_const &list, - const int & iswap, + const typename AT::t_int_1d_const &list, const typename AT::t_x_array &x, const typename AT::t_tagint_1d &tag, const typename AT::t_int_1d &type, const typename AT::t_int_1d &mask, const typename AT::t_float_1d &q, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask),_q(q), _dx(dx),_dy(dy),_dz(dz) {} KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -232,7 +228,7 @@ struct AtomVecChargeKokkos_PackBorder { /* ---------------------------------------------------------------------- */ -int AtomVecChargeKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, +int AtomVecChargeKokkos::pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -250,12 +246,12 @@ int AtomVecChargeKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecChargeKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_q,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_q,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecChargeKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_q,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_q,dx,dy,dz); Kokkos::parallel_for(n,f); } @@ -264,12 +260,12 @@ int AtomVecChargeKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecChargeKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_q,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_q,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecChargeKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_q,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_q,dx,dy,dz); Kokkos::parallel_for(n,f); } } diff --git a/src/KOKKOS/atom_vec_charge_kokkos.h b/src/KOKKOS/atom_vec_charge_kokkos.h index 397a5ee4c0..1d1c68735e 100644 --- a/src/KOKKOS/atom_vec_charge_kokkos.h +++ b/src/KOKKOS/atom_vec_charge_kokkos.h @@ -36,8 +36,8 @@ class AtomVecChargeKokkos : public AtomVecKokkos, public AtomVecCharge { void grow(int) override; void grow_pointers() override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_dipole_kokkos.cpp b/src/KOKKOS/atom_vec_dipole_kokkos.cpp index 6af575ad37..7728fedd4b 100644 --- a/src/KOKKOS/atom_vec_dipole_kokkos.cpp +++ b/src/KOKKOS/atom_vec_dipole_kokkos.cpp @@ -135,8 +135,7 @@ struct AtomVecDipoleKokkos_PackComm { typename ArrayTypes::t_x_array_randomread _x; typename ArrayTypes::t_mu_array_randomread _mu; typename ArrayTypes::t_xfloat_2d_um _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; @@ -144,13 +143,12 @@ struct AtomVecDipoleKokkos_PackComm { const typename DAT::tdual_x_array &x, const typename DAT::tdual_float_1d_4 &mu, const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int & iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): _x(x.view()), _mu(mu.view()), - _list(list.view()),_iswap(iswap), + _list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz) { const size_t elements = 7; // size_forward @@ -162,7 +160,7 @@ struct AtomVecDipoleKokkos_PackComm { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -200,8 +198,7 @@ struct AtomVecDipoleKokkos_PackBorder { typedef DeviceType device_type; typename ArrayTypes::t_xfloat_2d _buf; - const typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + const typename ArrayTypes::t_int_1d_const _list; const typename ArrayTypes::t_x_array_randomread _x; const typename ArrayTypes::t_tagint_1d _tag; const typename ArrayTypes::t_int_1d _type; @@ -212,8 +209,7 @@ struct AtomVecDipoleKokkos_PackBorder { AtomVecDipoleKokkos_PackBorder( const typename ArrayTypes::t_xfloat_2d &buf, - const typename ArrayTypes::t_int_2d_const &list, - const int & iswap, + const typename ArrayTypes::t_int_1d_const &list, const typename ArrayTypes::t_x_array &x, const typename ArrayTypes::t_tagint_1d &tag, const typename ArrayTypes::t_int_1d &type, @@ -221,13 +217,13 @@ struct AtomVecDipoleKokkos_PackBorder { const typename ArrayTypes::t_float_1d &q, const typename ArrayTypes::t_mu_array_randomread &mu, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask),_q(q),_mu(mu), _dx(dx),_dy(dy),_dz(dz) {} KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -258,7 +254,7 @@ struct AtomVecDipoleKokkos_PackBorder { /* ---------------------------------------------------------------------- */ -int AtomVecDipoleKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, +int AtomVecDipoleKokkos::pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -276,12 +272,12 @@ int AtomVecDipoleKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecDipoleKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_q,h_mu,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_q,h_mu,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecDipoleKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_q,d_mu,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_q,d_mu,dx,dy,dz); Kokkos::parallel_for(n,f); } @@ -290,12 +286,12 @@ int AtomVecDipoleKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecDipoleKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_q,h_mu,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_q,h_mu,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecDipoleKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_q,d_mu,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_q,d_mu,dx,dy,dz); Kokkos::parallel_for(n,f); } } diff --git a/src/KOKKOS/atom_vec_dipole_kokkos.h b/src/KOKKOS/atom_vec_dipole_kokkos.h index 97ec92c6c6..46e102936a 100644 --- a/src/KOKKOS/atom_vec_dipole_kokkos.h +++ b/src/KOKKOS/atom_vec_dipole_kokkos.h @@ -36,8 +36,8 @@ class AtomVecDipoleKokkos : public AtomVecKokkos, public AtomVecDipole { void grow(int) override; void grow_pointers() override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_dpd_kokkos.cpp b/src/KOKKOS/atom_vec_dpd_kokkos.cpp index 70aedcc931..6152fa60fb 100644 --- a/src/KOKKOS/atom_vec_dpd_kokkos.cpp +++ b/src/KOKKOS/atom_vec_dpd_kokkos.cpp @@ -20,6 +20,7 @@ #include "domain.h" #include "error.h" #include "fix.h" +#include "kokkos.h" #include "memory_kokkos.h" #include "modify.h" @@ -168,8 +169,7 @@ struct AtomVecDPDKokkos_PackComm { typename ArrayTypes::t_x_array_randomread _x; typename ArrayTypes::t_efloat_1d _dpdTheta,_uCond,_uMech,_uChem; typename ArrayTypes::t_xfloat_2d_um _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; @@ -180,8 +180,7 @@ struct AtomVecDPDKokkos_PackComm { const typename DAT::tdual_efloat_1d &uMech, const typename DAT::tdual_efloat_1d &uChem, const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int & iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): _x(x.view()), @@ -189,7 +188,7 @@ struct AtomVecDPDKokkos_PackComm { _uCond(uCond.view()), _uMech(uMech.view()), _uChem(uChem.view()), - _list(list.view()),_iswap(iswap), + _list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz) { const size_t maxsend = (buf.view().extent(0)*buf.view().extent(1))/3; @@ -201,7 +200,7 @@ struct AtomVecDPDKokkos_PackComm { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -227,8 +226,7 @@ struct AtomVecDPDKokkos_PackComm { /* ---------------------------------------------------------------------- */ int AtomVecDPDKokkos::pack_comm_kokkos(const int &n, - const DAT::tdual_int_2d &list, - const int & iswap, + const DAT::tdual_int_1d &list, const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int* const pbc) @@ -236,20 +234,20 @@ int AtomVecDPDKokkos::pack_comm_kokkos(const int &n, // Check whether to always run forward communication on the host // Choose correct forward PackComm kernel - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK|DPDTHETA_MASK|UCOND_MASK|UMECH_MASK|UCHEM_MASK); if (pbc_flag) { if (domain->triclinic) { struct AtomVecDPDKokkos_PackComm f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { struct AtomVecDPDKokkos_PackComm f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -258,14 +256,14 @@ int AtomVecDPDKokkos::pack_comm_kokkos(const int &n, if (domain->triclinic) { struct AtomVecDPDKokkos_PackComm f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { struct AtomVecDPDKokkos_PackComm f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -277,14 +275,14 @@ int AtomVecDPDKokkos::pack_comm_kokkos(const int &n, if (domain->triclinic) { struct AtomVecDPDKokkos_PackComm f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { struct AtomVecDPDKokkos_PackComm f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -293,14 +291,14 @@ int AtomVecDPDKokkos::pack_comm_kokkos(const int &n, if (domain->triclinic) { struct AtomVecDPDKokkos_PackComm f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { struct AtomVecDPDKokkos_PackComm f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -321,8 +319,7 @@ struct AtomVecDPDKokkos_PackCommSelf { typename ArrayTypes::t_x_array _xw; typename ArrayTypes::t_efloat_1d _dpdTheta,_uCond,_uMech,_uChem; int _nfirst; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; @@ -333,8 +330,7 @@ struct AtomVecDPDKokkos_PackCommSelf { const typename DAT::tdual_efloat_1d &uMech, const typename DAT::tdual_efloat_1d &uChem, const int &nfirst, - const typename DAT::tdual_int_2d &list, - const int & iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): _x(x.view()),_xw(x.view()), @@ -342,7 +338,7 @@ struct AtomVecDPDKokkos_PackCommSelf { _uCond(uCond.view()), _uMech(uMech.view()), _uChem(uChem.view()), - _nfirst(nfirst),_list(list.view()),_iswap(iswap), + _nfirst(nfirst),_list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz) { _pbc[0] = pbc[0]; _pbc[1] = pbc[1]; _pbc[2] = pbc[2]; @@ -351,7 +347,7 @@ struct AtomVecDPDKokkos_PackCommSelf { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _xw(i+_nfirst,0) = _x(j,0); _xw(i+_nfirst,1) = _x(j,1); @@ -376,23 +372,23 @@ struct AtomVecDPDKokkos_PackCommSelf { /* ---------------------------------------------------------------------- */ -int AtomVecDPDKokkos::pack_comm_self(const int &n, const DAT::tdual_int_2d &list, const int & iswap, +int AtomVecDPDKokkos::pack_comm_self(const int &n, const DAT::tdual_int_1d &list, const int nfirst, const int &pbc_flag, const int* const pbc) { - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK|DPDTHETA_MASK|UCOND_MASK|UMECH_MASK|UCHEM_MASK); atomKK->modified(Host,X_MASK|DPDTHETA_MASK|UCOND_MASK|UMECH_MASK|UCHEM_MASK); if (pbc_flag) { if (domain->triclinic) { struct AtomVecDPDKokkos_PackCommSelf f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { struct AtomVecDPDKokkos_PackCommSelf f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -401,14 +397,14 @@ int AtomVecDPDKokkos::pack_comm_self(const int &n, const DAT::tdual_int_2d &list if (domain->triclinic) { struct AtomVecDPDKokkos_PackCommSelf f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { struct AtomVecDPDKokkos_PackCommSelf f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -421,14 +417,14 @@ int AtomVecDPDKokkos::pack_comm_self(const int &n, const DAT::tdual_int_2d &list if (domain->triclinic) { struct AtomVecDPDKokkos_PackCommSelf f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { struct AtomVecDPDKokkos_PackCommSelf f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -437,14 +433,14 @@ int AtomVecDPDKokkos::pack_comm_self(const int &n, const DAT::tdual_int_2d &list if (domain->triclinic) { struct AtomVecDPDKokkos_PackCommSelf f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { struct AtomVecDPDKokkos_PackCommSelf f(atomKK->k_x, atomKK->k_dpdTheta,atomKK->k_uCond,atomKK->k_uMech,atomKK->k_uChem, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -496,7 +492,7 @@ struct AtomVecDPDKokkos_UnpackComm { void AtomVecDPDKokkos::unpack_comm_kokkos(const int &n, const int &first, const DAT::tdual_xfloat_2d &buf) { - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK|DPDTHETA_MASK|UCOND_MASK|UMECH_MASK|UCHEM_MASK); atomKK->modified(Host,X_MASK|DPDTHETA_MASK|UCOND_MASK|UMECH_MASK|UCHEM_MASK); struct AtomVecDPDKokkos_UnpackComm f(atomKK->k_x, @@ -520,8 +516,7 @@ struct AtomVecDPDKokkos_PackBorder { typedef DeviceType device_type; typename ArrayTypes::t_xfloat_2d _buf; - const typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + const typename ArrayTypes::t_int_1d_const _list; const typename ArrayTypes::t_x_array_randomread _x; const typename ArrayTypes::t_tagint_1d _tag; const typename ArrayTypes::t_int_1d _type; @@ -531,8 +526,7 @@ struct AtomVecDPDKokkos_PackBorder { AtomVecDPDKokkos_PackBorder( const typename ArrayTypes::t_xfloat_2d &buf, - const typename ArrayTypes::t_int_2d_const &list, - const int & iswap, + const typename ArrayTypes::t_int_1d_const &list, const typename ArrayTypes::t_x_array &x, const typename ArrayTypes::t_tagint_1d &tag, const typename ArrayTypes::t_int_1d &type, @@ -544,7 +538,7 @@ struct AtomVecDPDKokkos_PackBorder { const typename ArrayTypes::t_efloat_1d &uCG, const typename ArrayTypes::t_efloat_1d &uCGnew, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask), _dpdTheta(dpdTheta), _uCond(uCond), @@ -556,7 +550,7 @@ struct AtomVecDPDKokkos_PackBorder { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -580,7 +574,7 @@ struct AtomVecDPDKokkos_PackBorder { /* ---------------------------------------------------------------------- */ -int AtomVecDPDKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, +int AtomVecDPDKokkos::pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -600,14 +594,14 @@ int AtomVecDPDKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DA if (space==Host) { AtomVecDPDKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask, + h_x,h_tag,h_type,h_mask, h_dpdTheta,h_uCond,h_uMech,h_uChem,h_uCG,h_uCGnew, dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecDPDKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask, + d_x,d_tag,d_type,d_mask, d_dpdTheta,d_uCond,d_uMech,d_uChem,d_uCG,d_uCGnew, dx,dy,dz); Kokkos::parallel_for(n,f); @@ -618,14 +612,14 @@ int AtomVecDPDKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DA if (space==Host) { AtomVecDPDKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask, + h_x,h_tag,h_type,h_mask, h_dpdTheta,h_uCond,h_uMech,h_uChem,h_uCG,h_uCGnew, dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecDPDKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask, + d_x,d_tag,d_type,d_mask, d_dpdTheta,d_uCond,d_uMech,d_uChem,d_uCG,d_uCGnew, dx,dy,dz); Kokkos::parallel_for(n,f); diff --git a/src/KOKKOS/atom_vec_dpd_kokkos.h b/src/KOKKOS/atom_vec_dpd_kokkos.h index a76d7f908a..185422cfcf 100644 --- a/src/KOKKOS/atom_vec_dpd_kokkos.h +++ b/src/KOKKOS/atom_vec_dpd_kokkos.h @@ -36,17 +36,16 @@ class AtomVecDPDKokkos : public AtomVecKokkos, public AtomVecDPD { void grow(int) override; void grow_pointers() override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_comm_kokkos(const int &n, const DAT::tdual_int_2d &k_sendlist, - const int & iswap, + int pack_comm_kokkos(const int &n, const DAT::tdual_int_1d &k_sendlist, const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int pbc[]) override; void unpack_comm_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf) override; - int pack_comm_self(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const int nfirst, + int pack_comm_self(const int &n, const DAT::tdual_int_1d &list, + const int nfirst, const int &pbc_flag, const int pbc[]) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_full_kokkos.cpp b/src/KOKKOS/atom_vec_full_kokkos.cpp index 282414ab9b..1ae93a3df6 100644 --- a/src/KOKKOS/atom_vec_full_kokkos.cpp +++ b/src/KOKKOS/atom_vec_full_kokkos.cpp @@ -274,8 +274,7 @@ struct AtomVecFullKokkos_PackBorder { typedef ArrayTypes AT; typename AT::t_xfloat_2d _buf; - const typename AT::t_int_2d_const _list; - const int _iswap; + const typename AT::t_int_1d_const _list; const typename AT::t_x_array_randomread _x; const typename AT::t_tagint_1d _tag; const typename AT::t_int_1d _type; @@ -286,8 +285,7 @@ struct AtomVecFullKokkos_PackBorder { AtomVecFullKokkos_PackBorder( const typename AT::t_xfloat_2d &buf, - const typename AT::t_int_2d_const &list, - const int & iswap, + const typename AT::t_int_1d_const &list, const typename AT::t_x_array &x, const typename AT::t_tagint_1d &tag, const typename AT::t_int_1d &type, @@ -295,13 +293,13 @@ struct AtomVecFullKokkos_PackBorder { const typename AT::t_float_1d &q, const typename AT::t_tagint_1d &molecule, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask),_q(q),_molecule(molecule), _dx(dx),_dy(dy),_dz(dz) {} KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -326,8 +324,8 @@ struct AtomVecFullKokkos_PackBorder { /* ---------------------------------------------------------------------- */ -int AtomVecFullKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, +int AtomVecFullKokkos::pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -345,12 +343,12 @@ int AtomVecFullKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecFullKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_q,h_molecule,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_q,h_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecFullKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_q,d_molecule,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_q,d_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } @@ -359,12 +357,12 @@ int AtomVecFullKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, if (space==Host) { AtomVecFullKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_q,h_molecule,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_q,h_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecFullKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_q,d_molecule,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_q,d_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } } diff --git a/src/KOKKOS/atom_vec_full_kokkos.h b/src/KOKKOS/atom_vec_full_kokkos.h index 4937ef4152..9eea48ef95 100644 --- a/src/KOKKOS/atom_vec_full_kokkos.h +++ b/src/KOKKOS/atom_vec_full_kokkos.h @@ -35,8 +35,8 @@ class AtomVecFullKokkos : public AtomVecKokkos, public AtomVecFull { void grow(int) override; void grow_pointers() override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_hybrid_kokkos.cpp b/src/KOKKOS/atom_vec_hybrid_kokkos.cpp index 70b852a312..77af2cff05 100644 --- a/src/KOKKOS/atom_vec_hybrid_kokkos.cpp +++ b/src/KOKKOS/atom_vec_hybrid_kokkos.cpp @@ -56,8 +56,7 @@ void AtomVecHybridKokkos::sort_kokkos(Kokkos::BinSort &Sorte /* ---------------------------------------------------------------------- */ -int AtomVecHybridKokkos::pack_comm_kokkos(const int &/*n*/, const DAT::tdual_int_2d &/*k_sendlist*/, - const int & /*iswap*/, +int AtomVecHybridKokkos::pack_comm_kokkos(const int &/*n*/, const DAT::tdual_int_1d &/*k_sendlist*/, const DAT::tdual_xfloat_2d &/*buf*/, const int &/*pbc_flag*/, const int /*pbc*/[]) { @@ -71,16 +70,16 @@ void AtomVecHybridKokkos::unpack_comm_kokkos(const int &/*n*/, const int &/*nfir error->all(FLERR,"AtomVecHybridKokkos doesn't yet support threaded comm"); } -int AtomVecHybridKokkos::pack_comm_self(const int &/*n*/, const DAT::tdual_int_2d &/*list*/, - const int & /*iswap*/, const int /*nfirst*/, - const int &/*pbc_flag*/, const int /*pbc*/[]) +int AtomVecHybridKokkos::pack_comm_self(const int &/*n*/, const DAT::tdual_int_1d &/*list*/, + const int /*nfirst*/, + const int &/*pbc_flag*/, const int pbc[]) { error->all(FLERR,"AtomVecHybridKokkos doesn't yet support threaded comm"); return 0; } -int AtomVecHybridKokkos::pack_border_kokkos(int /*n*/, DAT::tdual_int_2d /*k_sendlist*/, - DAT::tdual_xfloat_2d /*buf*/,int /*iswap*/, +int AtomVecHybridKokkos::pack_border_kokkos(int /*n*/, DAT::tdual_int_1d /*k_sendlist*/, + DAT::tdual_xfloat_2d /*buf*/, int /*pbc_flag*/, int * /*pbc*/, ExecutionSpace /*space*/) { error->all(FLERR,"AtomVecHybridKokkos doesn't yet support threaded comm"); diff --git a/src/KOKKOS/atom_vec_hybrid_kokkos.h b/src/KOKKOS/atom_vec_hybrid_kokkos.h index 6f81c93673..19210549f5 100644 --- a/src/KOKKOS/atom_vec_hybrid_kokkos.h +++ b/src/KOKKOS/atom_vec_hybrid_kokkos.h @@ -36,17 +36,16 @@ class AtomVecHybridKokkos : public AtomVecKokkos, public AtomVecHybrid { void grow(int) override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_comm_kokkos(const int &n, const DAT::tdual_int_2d &k_sendlist, - const int & iswap, + int pack_comm_kokkos(const int &n, const DAT::tdual_int_1d &k_sendlist, const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int pbc[]) override; void unpack_comm_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf) override; - int pack_comm_self(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const int nfirst, + int pack_comm_self(const int &n, const DAT::tdual_int_1d &list, + const int nfirst, const int &pbc_flag, const int pbc[]) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_kokkos.cpp b/src/KOKKOS/atom_vec_kokkos.cpp index 42a32dd71d..d54cc2c3af 100644 --- a/src/KOKKOS/atom_vec_kokkos.cpp +++ b/src/KOKKOS/atom_vec_kokkos.cpp @@ -18,6 +18,7 @@ #include "atom_masks.h" #include "comm_kokkos.h" #include "domain.h" +#include "kokkos.h" using namespace LAMMPS_NS; @@ -36,7 +37,6 @@ AtomVecKokkos::AtomVecKokkos(LAMMPS *lmp) : AtomVec(lmp) k_count = DAT::tdual_int_1d("atom:k_count",1); atomKK = (AtomKokkos *) atom; - commKK = (CommKokkos *) comm; } /* ---------------------------------------------------------------------- */ @@ -56,19 +56,17 @@ struct AtomVecKokkos_PackComm { typename ArrayTypes::t_x_array_randomread _x; typename ArrayTypes::t_xfloat_2d_um _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; AtomVecKokkos_PackComm( const typename DAT::tdual_x_array &x, const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int & iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): - _x(x.view()),_list(list.view()),_iswap(iswap), + _x(x.view()),_list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz) { const size_t maxsend = (buf.view().extent(0)*buf.view().extent(1))/3; @@ -80,7 +78,7 @@ struct AtomVecKokkos_PackComm { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -102,8 +100,7 @@ struct AtomVecKokkos_PackComm { /* ---------------------------------------------------------------------- */ int AtomVecKokkos::pack_comm_kokkos(const int &n, - const DAT::tdual_int_2d &list, - const int & iswap, + const DAT::tdual_int_1d &list, const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int* const pbc) @@ -111,28 +108,28 @@ int AtomVecKokkos::pack_comm_kokkos(const int &n, // Check whether to always run forward communication on the host // Choose correct forward PackComm kernel - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK); if (pbc_flag) { if (domain->triclinic) { - struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list,iswap, + struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list,iswap, + struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } } else { if (domain->triclinic) { - struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list,iswap, + struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list,iswap, + struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -142,24 +139,24 @@ int AtomVecKokkos::pack_comm_kokkos(const int &n, atomKK->sync(Device,X_MASK); if (pbc_flag) { if (domain->triclinic) { - struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list,iswap, + struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list,iswap, + struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } } else { if (domain->triclinic) { - struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list,iswap, + struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list,iswap, + struct AtomVecKokkos_PackComm f(atomKK->k_x,buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -167,7 +164,7 @@ int AtomVecKokkos::pack_comm_kokkos(const int &n, } } - return n*size_forward; + return n*size_forward; } /* ---------------------------------------------------------------------- */ @@ -179,19 +176,17 @@ struct AtomVecKokkos_PackCommSelf { typename ArrayTypes::t_x_array_randomread _x; typename ArrayTypes::t_x_array _xw; int _nfirst; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; AtomVecKokkos_PackCommSelf( const typename DAT::tdual_x_array &x, const int &nfirst, - const typename DAT::tdual_int_2d &list, - const int & iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): - _x(x.view()),_xw(x.view()),_nfirst(nfirst),_list(list.view()),_iswap(iswap), + _x(x.view()),_xw(x.view()),_nfirst(nfirst),_list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz) { _pbc[0] = pbc[0]; _pbc[1] = pbc[1]; _pbc[2] = pbc[2]; @@ -200,7 +195,7 @@ struct AtomVecKokkos_PackCommSelf { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _xw(i+_nfirst,0) = _x(j,0); _xw(i+_nfirst,1) = _x(j,1); @@ -222,66 +217,67 @@ struct AtomVecKokkos_PackCommSelf { /* ---------------------------------------------------------------------- */ -int AtomVecKokkos::pack_comm_self(const int &n, const DAT::tdual_int_2d &list, const int & iswap, +int AtomVecKokkos::pack_comm_self(const int &n, const DAT::tdual_int_1d &list, const int nfirst, const int &pbc_flag, const int* const pbc) { - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK); - atomKK->modified(Host,X_MASK); if (pbc_flag) { if (domain->triclinic) { - struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list,iswap, + struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list,iswap, + struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } } else { if (domain->triclinic) { - struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list,iswap, + struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list,iswap, + struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } } + atomKK->modified(Host,X_MASK); } else { atomKK->sync(Device,X_MASK); - atomKK->modified(Device,X_MASK); if (pbc_flag) { if (domain->triclinic) { - struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list,iswap, + struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list,iswap, + struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } } else { if (domain->triclinic) { - struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list,iswap, + struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list,iswap, + struct AtomVecKokkos_PackCommSelf f(atomKK->k_x,nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } } + atomKK->modified(Device,X_MASK); } - return n*3; + + return n*3; } @@ -360,35 +356,36 @@ struct AtomVecKokkos_PackCommSelfFused { int AtomVecKokkos::pack_comm_self_fused(const int &n, const DAT::tdual_int_2d &list, const DAT::tdual_int_1d &sendnum_scan, const DAT::tdual_int_1d &firstrecv, const DAT::tdual_int_1d &pbc_flag, const DAT::tdual_int_2d &pbc, const DAT::tdual_int_1d &g2l) { - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK); - atomKK->modified(Host,X_MASK); if (domain->triclinic) { - struct AtomVecKokkos_PackCommSelfFused f(atomKK->k_x,list,pbc,pbc_flag,firstrecv,sendnum_scan,g2l, + struct AtomVecKokkos_PackCommSelfFused f(atomKK->k_x,list,pbc,pbc_flag,firstrecv,sendnum_scan,g2l, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackCommSelfFused f(atomKK->k_x,list,pbc,pbc_flag,firstrecv,sendnum_scan,g2l, + struct AtomVecKokkos_PackCommSelfFused f(atomKK->k_x,list,pbc,pbc_flag,firstrecv,sendnum_scan,g2l, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } + atomKK->modified(Host,X_MASK); } else { atomKK->sync(Device,X_MASK); - atomKK->modified(Device,X_MASK); if (domain->triclinic) { - struct AtomVecKokkos_PackCommSelfFused f(atomKK->k_x,list,pbc,pbc_flag,firstrecv,sendnum_scan,g2l, + struct AtomVecKokkos_PackCommSelfFused f(atomKK->k_x,list,pbc,pbc_flag,firstrecv,sendnum_scan,g2l, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } else { - struct AtomVecKokkos_PackCommSelfFused f(atomKK->k_x,list,pbc,pbc_flag,firstrecv,sendnum_scan,g2l, + struct AtomVecKokkos_PackCommSelfFused f(atomKK->k_x,list,pbc,pbc_flag,firstrecv,sendnum_scan,g2l, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz); - Kokkos::parallel_for(n,f); + Kokkos::parallel_for(n,f); } + atomKK->modified(Device,X_MASK); } + return n*3; } @@ -420,20 +417,19 @@ struct AtomVecKokkos_UnpackComm { void AtomVecKokkos::unpack_comm_kokkos(const int &n, const int &first, const DAT::tdual_xfloat_2d &buf) { - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK); - atomKK->modified(Host,X_MASK); struct AtomVecKokkos_UnpackComm f(atomKK->k_x,buf,first); Kokkos::parallel_for(n,f); + atomKK->modified(Host,X_MASK); } else { atomKK->sync(Device,X_MASK); - atomKK->modified(Device,X_MASK); struct AtomVecKokkos_UnpackComm f(atomKK->k_x,buf,first); Kokkos::parallel_for(n,f); + atomKK->modified(Device,X_MASK); } } - /* ---------------------------------------------------------------------- */ template @@ -444,8 +440,7 @@ struct AtomVecKokkos_PackCommVel { typename ArrayTypes::t_int_1d _mask; typename ArrayTypes::t_v_array _v; typename ArrayTypes::t_xfloat_2d_um _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; X_FLOAT _h_rate[6]; @@ -456,8 +451,7 @@ struct AtomVecKokkos_PackCommVel { const typename DAT::tdual_int_1d &mask, const typename DAT::tdual_v_array &v, const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int &iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc, const double * const h_rate, @@ -465,7 +459,7 @@ struct AtomVecKokkos_PackCommVel { _x(x.view()), _mask(mask.view()), _v(v.view()), - _list(list.view()),_iswap(iswap), + _list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz), _deform_vremap(deform_vremap) @@ -481,7 +475,7 @@ struct AtomVecKokkos_PackCommVel { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -523,13 +517,12 @@ struct AtomVecKokkos_PackCommVel { int AtomVecKokkos::pack_comm_vel_kokkos( const int &n, - const DAT::tdual_int_2d &list, - const int & iswap, + const DAT::tdual_int_1d &list, const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int* const pbc) { - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK|V_MASK); if (pbc_flag) { if (deform_vremap) { @@ -537,7 +530,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -545,7 +538,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -555,7 +548,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -563,7 +556,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -574,7 +567,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -582,7 +575,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -596,7 +589,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -604,7 +597,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -614,7 +607,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -622,7 +615,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -633,7 +626,7 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -641,13 +634,14 @@ int AtomVecKokkos::pack_comm_vel_kokkos( struct AtomVecKokkos_PackCommVel f( atomKK->k_x,atomKK->k_mask, atomKK->k_v, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); } } } + return n*6; } @@ -691,16 +685,16 @@ struct AtomVecKokkos_UnpackCommVel { void AtomVecKokkos::unpack_comm_vel_kokkos(const int &n, const int &first, const DAT::tdual_xfloat_2d &buf) { - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK|V_MASK); - atomKK->modified(Host,X_MASK|V_MASK); struct AtomVecKokkos_UnpackCommVel f(atomKK->k_x,atomKK->k_v,buf,first); Kokkos::parallel_for(n,f); + atomKK->modified(Host,X_MASK|V_MASK); } else { atomKK->sync(Device,X_MASK|V_MASK); - atomKK->modified(Device,X_MASK|V_MASK); struct AtomVecKokkos_UnpackCommVel f(atomKK->k_x,atomKK->k_v,buf,first); Kokkos::parallel_for(n,f); + atomKK->modified(Device,X_MASK|V_MASK); } } @@ -732,7 +726,7 @@ struct AtomVecKokkos_PackReverse { int AtomVecKokkos::pack_reverse_kokkos(const int &n, const int &first, const DAT::tdual_ffloat_2d &buf) { - if (commKK->reverse_comm_on_host) { + if (lmp->kokkos->reverse_comm_on_host) { atomKK->sync(Host,F_MASK); struct AtomVecKokkos_PackReverse f(atomKK->k_f,buf,first); Kokkos::parallel_for(n,f); @@ -754,20 +748,18 @@ struct AtomVecKokkos_UnPackReverseSelf { typename ArrayTypes::t_f_array_randomread _f; typename ArrayTypes::t_f_array _fw; int _nfirst; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; AtomVecKokkos_UnPackReverseSelf( const typename DAT::tdual_f_array &f, const int &nfirst, - const typename DAT::tdual_int_2d &list, - const int & iswap): - _f(f.view()),_fw(f.view()),_nfirst(nfirst),_list(list.view()),_iswap(iswap) { + const typename DAT::tdual_int_1d &list): + _f(f.view()),_fw(f.view()),_nfirst(nfirst),_list(list.view()) { }; KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); _fw(j,0) += _f(i+_nfirst,0); _fw(j,1) += _f(i+_nfirst,1); _fw(j,2) += _f(i+_nfirst,2); @@ -776,19 +768,20 @@ struct AtomVecKokkos_UnPackReverseSelf { /* ---------------------------------------------------------------------- */ -int AtomVecKokkos::unpack_reverse_self(const int &n, const DAT::tdual_int_2d &list, const int & iswap, - const int nfirst) { - if (commKK->reverse_comm_on_host) { +int AtomVecKokkos::pack_reverse_self(const int &n, const DAT::tdual_int_1d &list, + const int nfirst) { + if (lmp->kokkos->reverse_comm_on_host) { atomKK->sync(Host,F_MASK); - struct AtomVecKokkos_UnPackReverseSelf f(atomKK->k_f,nfirst,list,iswap); + struct AtomVecKokkos_UnPackReverseSelf f(atomKK->k_f,nfirst,list); Kokkos::parallel_for(n,f); atomKK->modified(Host,F_MASK); } else { atomKK->sync(Device,F_MASK); - struct AtomVecKokkos_UnPackReverseSelf f(atomKK->k_f,nfirst,list,iswap); + struct AtomVecKokkos_UnPackReverseSelf f(atomKK->k_f,nfirst,list); Kokkos::parallel_for(n,f); atomKK->modified(Device,F_MASK); } + return n*3; } @@ -800,15 +793,13 @@ struct AtomVecKokkos_UnPackReverse { typename ArrayTypes::t_f_array _f; typename ArrayTypes::t_ffloat_2d_const _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; AtomVecKokkos_UnPackReverse( const typename DAT::tdual_f_array &f, const typename DAT::tdual_ffloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int & iswap): - _f(f.view()),_list(list.view()),_iswap(iswap) { + const typename DAT::tdual_int_1d &list): + _f(f.view()),_list(list.view()) { const size_t maxsend = (buf.view().extent(0)*buf.view().extent(1))/3; const size_t elements = 3; buffer_view(_buf,buf,maxsend,elements); @@ -816,7 +807,7 @@ struct AtomVecKokkos_UnPackReverse { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); _f(j,0) += _buf(i,0); _f(j,1) += _buf(i,1); _f(j,2) += _buf(i,2); @@ -826,19 +817,18 @@ struct AtomVecKokkos_UnPackReverse { /* ---------------------------------------------------------------------- */ void AtomVecKokkos::unpack_reverse_kokkos(const int &n, - const DAT::tdual_int_2d &list, - const int & iswap, + const DAT::tdual_int_1d &list, const DAT::tdual_ffloat_2d &buf) { // Check whether to always run reverse communication on the host // Choose correct reverse UnPackReverse kernel - if (commKK->reverse_comm_on_host) { - struct AtomVecKokkos_UnPackReverse f(atomKK->k_f,buf,list,iswap); + if (lmp->kokkos->reverse_comm_on_host) { + struct AtomVecKokkos_UnPackReverse f(atomKK->k_f,buf,list); Kokkos::parallel_for(n,f); atomKK->modified(Host,F_MASK); } else { - struct AtomVecKokkos_UnPackReverse f(atomKK->k_f,buf,list,iswap); + struct AtomVecKokkos_UnPackReverse f(atomKK->k_f,buf,list); Kokkos::parallel_for(n,f); atomKK->modified(Device,F_MASK); } diff --git a/src/KOKKOS/atom_vec_kokkos.h b/src/KOKKOS/atom_vec_kokkos.h index c10ff5b40a..646d9a4840 100644 --- a/src/KOKKOS/atom_vec_kokkos.h +++ b/src/KOKKOS/atom_vec_kokkos.h @@ -50,8 +50,8 @@ class AtomVecKokkos : virtual public AtomVec { virtual void sync_overlapping_device(ExecutionSpace space, unsigned int mask) = 0; virtual int - pack_comm_self(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const int nfirst, + pack_comm_self(const int &n, const DAT::tdual_int_1d &list, + const int nfirst, const int &pbc_flag, const int pbc[]); virtual int @@ -63,8 +63,8 @@ class AtomVecKokkos : virtual public AtomVec { const DAT::tdual_int_1d &g2l); virtual int - pack_comm_kokkos(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const DAT::tdual_xfloat_2d &buf, + pack_comm_kokkos(const int &n, const DAT::tdual_int_1d &list, + const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int pbc[]); virtual void @@ -72,8 +72,8 @@ class AtomVecKokkos : virtual public AtomVec { const DAT::tdual_xfloat_2d &buf); virtual int - pack_comm_vel_kokkos(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const DAT::tdual_xfloat_2d &buf, + pack_comm_vel_kokkos(const int &n, const DAT::tdual_int_1d &list, + const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int pbc[]); virtual void @@ -81,20 +81,20 @@ class AtomVecKokkos : virtual public AtomVec { const DAT::tdual_xfloat_2d &buf); virtual int - unpack_reverse_self(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const int nfirst); + pack_reverse_self(const int &n, const DAT::tdual_int_1d &list, + const int nfirst); virtual int pack_reverse_kokkos(const int &n, const int &nfirst, const DAT::tdual_ffloat_2d &buf); virtual void - unpack_reverse_kokkos(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const DAT::tdual_ffloat_2d &buf); + unpack_reverse_kokkos(const int &n, const DAT::tdual_int_1d &list, + const DAT::tdual_ffloat_2d &buf); virtual int - pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) = 0; virtual void @@ -103,8 +103,8 @@ class AtomVecKokkos : virtual public AtomVec { ExecutionSpace space) = 0; virtual int - pack_border_vel_kokkos(int /*n*/, DAT::tdual_int_2d /*k_sendlist*/, - DAT::tdual_xfloat_2d /*buf*/,int /*iswap*/, + pack_border_vel_kokkos(int /*n*/, DAT::tdual_int_1d /*k_sendlist*/, + DAT::tdual_xfloat_2d /*buf*/, int /*pbc_flag*/, int * /*pbc*/, ExecutionSpace /*space*/) { return 0; } virtual void @@ -133,7 +133,6 @@ class AtomVecKokkos : virtual public AtomVec { HAT::t_v_array h_v; HAT::t_f_array h_f; - class CommKokkos *commKK; size_t buffer_size; void* buffer; diff --git a/src/KOKKOS/atom_vec_molecular_kokkos.cpp b/src/KOKKOS/atom_vec_molecular_kokkos.cpp index ec98ff9239..68369e2fad 100644 --- a/src/KOKKOS/atom_vec_molecular_kokkos.cpp +++ b/src/KOKKOS/atom_vec_molecular_kokkos.cpp @@ -260,295 +260,13 @@ void AtomVecMolecularKokkos::sort_kokkos(Kokkos::BinSort &So /* ---------------------------------------------------------------------- */ -template -struct AtomVecMolecularKokkos_PackComm { - typedef DeviceType device_type; - - typename ArrayTypes::t_x_array_randomread _x; - typename ArrayTypes::t_xfloat_2d_um _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; - X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; - X_FLOAT _pbc[6]; - - AtomVecMolecularKokkos_PackComm( - const typename DAT::tdual_x_array &x, - const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int & iswap, - const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, - const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): - _x(x.view()),_list(list.view()),_iswap(iswap), - _xprd(xprd),_yprd(yprd),_zprd(zprd), - _xy(xy),_xz(xz),_yz(yz) { - const size_t maxsend = (buf.view().extent(0) - *buf.view().extent(1))/3; - const size_t elements = 3; - buffer_view(_buf,buf,maxsend,elements); - _pbc[0] = pbc[0]; _pbc[1] = pbc[1]; _pbc[2] = pbc[2]; - _pbc[3] = pbc[3]; _pbc[4] = pbc[4]; _pbc[5] = pbc[5]; - }; - - KOKKOS_INLINE_FUNCTION - void operator() (const int& i) const { - const int j = _list(_iswap,i); - if (PBC_FLAG == 0) { - _buf(i,0) = _x(j,0); - _buf(i,1) = _x(j,1); - _buf(i,2) = _x(j,2); - } else { - if (TRICLINIC == 0) { - _buf(i,0) = _x(j,0) + _pbc[0]*_xprd; - _buf(i,1) = _x(j,1) + _pbc[1]*_yprd; - _buf(i,2) = _x(j,2) + _pbc[2]*_zprd; - } else { - _buf(i,0) = _x(j,0) + _pbc[0]*_xprd + _pbc[5]*_xy + _pbc[4]*_xz; - _buf(i,1) = _x(j,1) + _pbc[1]*_yprd + _pbc[3]*_yz; - _buf(i,2) = _x(j,2) + _pbc[2]*_zprd; - } - } - } -}; - -/* ---------------------------------------------------------------------- */ - -int AtomVecMolecularKokkos::pack_comm_kokkos(const int &n, - const DAT::tdual_int_2d &list, - const int & iswap, - const DAT::tdual_xfloat_2d &buf, - const int &pbc_flag, - const int* const pbc) -{ - // Check whether to always run forward communication on the host - // Choose correct forward PackComm kernel - - if (commKK->forward_comm_on_host) { - atomKK->sync(Host,X_MASK); - if (pbc_flag) { - if (domain->triclinic) { - struct AtomVecMolecularKokkos_PackComm - f(atomKK->k_x,buf,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecMolecularKokkos_PackComm - f(atomKK->k_x,buf,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } else { - if (domain->triclinic) { - struct AtomVecMolecularKokkos_PackComm - f(atomKK->k_x,buf,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecMolecularKokkos_PackComm - f(atomKK->k_x,buf,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } - } else { - atomKK->sync(Device,X_MASK); - if (pbc_flag) { - if (domain->triclinic) { - struct AtomVecMolecularKokkos_PackComm - f(atomKK->k_x,buf,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecMolecularKokkos_PackComm - f(atomKK->k_x,buf,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } else { - if (domain->triclinic) { - struct AtomVecMolecularKokkos_PackComm - f(atomKK->k_x,buf,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecMolecularKokkos_PackComm - f(atomKK->k_x,buf,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } - } - - return n*size_forward; -} - -/* ---------------------------------------------------------------------- */ - -template -struct AtomVecMolecularKokkos_PackCommSelf { - typedef DeviceType device_type; - - typename ArrayTypes::t_x_array_randomread _x; - typename ArrayTypes::t_x_array _xw; - int _nfirst; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; - X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; - X_FLOAT _pbc[6]; - - AtomVecMolecularKokkos_PackCommSelf( - const typename DAT::tdual_x_array &x, - const int &nfirst, - const typename DAT::tdual_int_2d &list, - const int & iswap, - const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, - const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): - _x(x.view()),_xw(x.view()),_nfirst(nfirst), - _list(list.view()),_iswap(iswap), - _xprd(xprd),_yprd(yprd),_zprd(zprd), - _xy(xy),_xz(xz),_yz(yz) { - _pbc[0] = pbc[0]; _pbc[1] = pbc[1]; _pbc[2] = pbc[2]; - _pbc[3] = pbc[3]; _pbc[4] = pbc[4]; _pbc[5] = pbc[5]; - }; - - KOKKOS_INLINE_FUNCTION - void operator() (const int& i) const { - const int j = _list(_iswap,i); - if (PBC_FLAG == 0) { - _xw(i+_nfirst,0) = _x(j,0); - _xw(i+_nfirst,1) = _x(j,1); - _xw(i+_nfirst,2) = _x(j,2); - } else { - if (TRICLINIC == 0) { - _xw(i+_nfirst,0) = _x(j,0) + _pbc[0]*_xprd; - _xw(i+_nfirst,1) = _x(j,1) + _pbc[1]*_yprd; - _xw(i+_nfirst,2) = _x(j,2) + _pbc[2]*_zprd; - } else { - _xw(i+_nfirst,0) = _x(j,0) + _pbc[0]*_xprd + _pbc[5]*_xy + _pbc[4]*_xz; - _xw(i+_nfirst,1) = _x(j,1) + _pbc[1]*_yprd + _pbc[3]*_yz; - _xw(i+_nfirst,2) = _x(j,2) + _pbc[2]*_zprd; - } - } - - } -}; - -/* ---------------------------------------------------------------------- */ - -int AtomVecMolecularKokkos::pack_comm_self(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, - const int nfirst, const int &pbc_flag, - const int* const pbc) { - if (commKK->forward_comm_on_host) { - atomKK->sync(Host,X_MASK); - atomKK->modified(Host,X_MASK); - if (pbc_flag) { - if (domain->triclinic) { - struct AtomVecMolecularKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecMolecularKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } else { - if (domain->triclinic) { - struct AtomVecMolecularKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecMolecularKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } - } else { - atomKK->sync(Device,X_MASK); - atomKK->modified(Device,X_MASK); - if (pbc_flag) { - if (domain->triclinic) { - struct AtomVecMolecularKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecMolecularKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } else { - if (domain->triclinic) { - struct AtomVecMolecularKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } else { - struct AtomVecMolecularKokkos_PackCommSelf - f(atomKK->k_x,nfirst,list,iswap,domain->xprd,domain->yprd,domain->zprd, - domain->xy,domain->xz,domain->yz,pbc); - Kokkos::parallel_for(n,f); - } - } - } - return n*3; -} - -/* ---------------------------------------------------------------------- */ - -template -struct AtomVecMolecularKokkos_UnpackComm { - typedef DeviceType device_type; - - typename ArrayTypes::t_x_array _x; - typename ArrayTypes::t_xfloat_2d_const _buf; - int _first; - - AtomVecMolecularKokkos_UnpackComm( - const typename DAT::tdual_x_array &x, - const typename DAT::tdual_xfloat_2d &buf, - const int& first):_x(x.view()),_buf(buf.view()), - _first(first) {}; - - KOKKOS_INLINE_FUNCTION - void operator() (const int& i) const { - _x(i+_first,0) = _buf(i,0); - _x(i+_first,1) = _buf(i,1); - _x(i+_first,2) = _buf(i,2); - } -}; - -/* ---------------------------------------------------------------------- */ - -void AtomVecMolecularKokkos::unpack_comm_kokkos(const int &n, const int &first, - const DAT::tdual_xfloat_2d &buf) { - if (commKK->forward_comm_on_host) { - atomKK->sync(Host,X_MASK); - atomKK->modified(Host,X_MASK); - struct AtomVecMolecularKokkos_UnpackComm f(atomKK->k_x,buf,first); - Kokkos::parallel_for(n,f); - } else { - atomKK->sync(Device,X_MASK); - atomKK->modified(Device,X_MASK); - struct AtomVecMolecularKokkos_UnpackComm f(atomKK->k_x,buf,first); - Kokkos::parallel_for(n,f); - } -} - -/* ---------------------------------------------------------------------- */ - template struct AtomVecMolecularKokkos_PackBorder { typedef DeviceType device_type; typedef ArrayTypes AT; typename AT::t_xfloat_2d _buf; - const typename AT::t_int_2d_const _list; - const int _iswap; + const typename AT::t_int_1d_const _list; const typename AT::t_x_array_randomread _x; const typename AT::t_tagint_1d _tag; const typename AT::t_int_1d _type; @@ -558,21 +276,20 @@ struct AtomVecMolecularKokkos_PackBorder { AtomVecMolecularKokkos_PackBorder( const typename AT::t_xfloat_2d &buf, - const typename AT::t_int_2d_const &list, - const int & iswap, + const typename AT::t_int_1d_const &list, const typename AT::t_x_array &x, const typename AT::t_tagint_1d &tag, const typename AT::t_int_1d &type, const typename AT::t_int_1d &mask, const typename AT::t_tagint_1d &molecule, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask),_molecule(molecule), _dx(dx),_dy(dy),_dz(dz) {} KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -595,8 +312,8 @@ struct AtomVecMolecularKokkos_PackBorder { /* ---------------------------------------------------------------------- */ -int AtomVecMolecularKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, +int AtomVecMolecularKokkos::pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -614,12 +331,12 @@ int AtomVecMolecularKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendli if (space==Host) { AtomVecMolecularKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecMolecularKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } @@ -628,12 +345,12 @@ int AtomVecMolecularKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendli if (space==Host) { AtomVecMolecularKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecMolecularKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_molecule,dx,dy,dz); Kokkos::parallel_for(n,f); } } diff --git a/src/KOKKOS/atom_vec_molecular_kokkos.h b/src/KOKKOS/atom_vec_molecular_kokkos.h index eb976e9073..a92784fbd9 100644 --- a/src/KOKKOS/atom_vec_molecular_kokkos.h +++ b/src/KOKKOS/atom_vec_molecular_kokkos.h @@ -35,17 +35,8 @@ class AtomVecMolecularKokkos : public AtomVecKokkos, public AtomVecMolecular { void grow(int) override; void grow_pointers() override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_comm_kokkos(const int &n, const DAT::tdual_int_2d &k_sendlist, - const int & iswap, - const DAT::tdual_xfloat_2d &buf, - const int &pbc_flag, const int pbc[]) override; - void unpack_comm_kokkos(const int &n, const int &nfirst, - const DAT::tdual_xfloat_2d &buf) override; - int pack_comm_self(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const int nfirst, - const int &pbc_flag, const int pbc[]) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_sphere_kokkos.cpp b/src/KOKKOS/atom_vec_sphere_kokkos.cpp index a9dcf72ff3..8802275e31 100644 --- a/src/KOKKOS/atom_vec_sphere_kokkos.cpp +++ b/src/KOKKOS/atom_vec_sphere_kokkos.cpp @@ -20,6 +20,7 @@ #include "domain.h" #include "error.h" #include "fix.h" +#include "kokkos.h" #include "math_const.h" #include "memory_kokkos.h" #include "modify.h" @@ -149,8 +150,7 @@ struct AtomVecSphereKokkos_PackComm { typename ArrayTypes::t_x_array_randomread _x; typename ArrayTypes::t_float_1d _radius,_rmass; typename ArrayTypes::t_xfloat_2d_um _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; @@ -159,14 +159,13 @@ struct AtomVecSphereKokkos_PackComm { const typename DAT::tdual_float_1d &radius, const typename DAT::tdual_float_1d &rmass, const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int & iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): _x(x.view()), _radius(radius.view()), _rmass(rmass.view()), - _list(list.view()),_iswap(iswap), + _list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz) { const size_t elements = 5; @@ -178,7 +177,7 @@ struct AtomVecSphereKokkos_PackComm { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -203,25 +202,24 @@ struct AtomVecSphereKokkos_PackComm { int AtomVecSphereKokkos::pack_comm_kokkos( const int &n, - const DAT::tdual_int_2d &list, - const int & iswap, + const DAT::tdual_int_1d &list, const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int* const pbc) { // Fallback to AtomVecKokkos if radvary == 0 if (radvary == 0) - return AtomVecKokkos::pack_comm_kokkos(n,list,iswap,buf,pbc_flag,pbc); + return AtomVecKokkos::pack_comm_kokkos(n,list,buf,pbc_flag,pbc); // Check whether to always run forward communication on the host // Choose correct forward PackComm kernel - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK|RADIUS_MASK|RMASS_MASK); if (pbc_flag) { if (domain->triclinic) { struct AtomVecSphereKokkos_PackComm f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -229,7 +227,7 @@ int AtomVecSphereKokkos::pack_comm_kokkos( struct AtomVecSphereKokkos_PackComm f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -239,7 +237,7 @@ int AtomVecSphereKokkos::pack_comm_kokkos( struct AtomVecSphereKokkos_PackComm f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -247,7 +245,7 @@ int AtomVecSphereKokkos::pack_comm_kokkos( struct AtomVecSphereKokkos_PackComm f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -260,7 +258,7 @@ int AtomVecSphereKokkos::pack_comm_kokkos( struct AtomVecSphereKokkos_PackComm f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -268,7 +266,7 @@ int AtomVecSphereKokkos::pack_comm_kokkos( struct AtomVecSphereKokkos_PackComm f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -278,7 +276,7 @@ int AtomVecSphereKokkos::pack_comm_kokkos( struct AtomVecSphereKokkos_PackComm f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -286,7 +284,7 @@ int AtomVecSphereKokkos::pack_comm_kokkos( struct AtomVecSphereKokkos_PackComm f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -307,8 +305,7 @@ struct AtomVecSphereKokkos_PackCommVel { typename ArrayTypes::t_float_1d _radius,_rmass; typename ArrayTypes::t_v_array _v, _omega; typename ArrayTypes::t_xfloat_2d_um _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; X_FLOAT _h_rate[6]; @@ -322,8 +319,7 @@ struct AtomVecSphereKokkos_PackCommVel { const typename DAT::tdual_v_array &v, const typename DAT::tdual_v_array &omega, const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int &iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc, const double * const h_rate, @@ -334,7 +330,7 @@ struct AtomVecSphereKokkos_PackCommVel { _rmass(rmass.view()), _v(v.view()), _omega(omega.view()), - _list(list.view()),_iswap(iswap), + _list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz), _deform_vremap(deform_vremap) @@ -350,7 +346,7 @@ struct AtomVecSphereKokkos_PackCommVel { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -395,13 +391,12 @@ struct AtomVecSphereKokkos_PackCommVel { int AtomVecSphereKokkos::pack_comm_vel_kokkos( const int &n, - const DAT::tdual_int_2d &list, - const int & iswap, + const DAT::tdual_int_1d &list, const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int* const pbc) { - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK|RADIUS_MASK|RMASS_MASK|V_MASK|OMEGA_MASK); if (pbc_flag) { if (deform_vremap) { @@ -411,7 +406,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -420,7 +415,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -431,7 +426,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -440,7 +435,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -453,7 +448,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -462,7 +457,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -473,7 +468,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -482,7 +477,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -496,7 +491,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -505,7 +500,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -516,7 +511,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -525,7 +520,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -542,7 +537,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -551,7 +546,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -562,7 +557,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -571,7 +566,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -584,7 +579,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -593,7 +588,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -604,7 +599,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -613,7 +608,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -627,7 +622,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -636,7 +631,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -647,7 +642,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -656,7 +651,7 @@ int AtomVecSphereKokkos::pack_comm_vel_kokkos( atomKK->k_x,atomKK->k_mask, atomKK->k_radius,atomKK->k_rmass, atomKK->k_v,atomKK->k_omega, - buf,list,iswap, + buf,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc,h_rate,deform_vremap); Kokkos::parallel_for(n,f); @@ -677,8 +672,7 @@ struct AtomVecSphereKokkos_PackCommSelf { typename ArrayTypes::t_x_array _xw; typename ArrayTypes::t_float_1d _radius,_rmass; int _nfirst; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; @@ -687,14 +681,13 @@ struct AtomVecSphereKokkos_PackCommSelf { const typename DAT::tdual_float_1d &radius, const typename DAT::tdual_float_1d &rmass, const int &nfirst, - const typename DAT::tdual_int_2d &list, - const int & iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): _x(x.view()),_xw(x.view()), _radius(radius.view()), _rmass(rmass.view()), - _nfirst(nfirst),_list(list.view()),_iswap(iswap), + _nfirst(nfirst),_list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz) { _pbc[0] = pbc[0]; _pbc[1] = pbc[1]; _pbc[2] = pbc[2]; @@ -703,7 +696,7 @@ struct AtomVecSphereKokkos_PackCommSelf { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _xw(i+_nfirst,0) = _x(j,0); _xw(i+_nfirst,1) = _x(j,1); @@ -727,12 +720,12 @@ struct AtomVecSphereKokkos_PackCommSelf { /* ---------------------------------------------------------------------- */ int AtomVecSphereKokkos::pack_comm_self( - const int &n, const DAT::tdual_int_2d &list, const int &iswap, + const int &n, const DAT::tdual_int_1d &list, const int nfirst, const int &pbc_flag, const int* const pbc) { // Fallback to AtomVecKokkos if radvary == 0 if (radvary == 0) - return AtomVecKokkos::pack_comm_self(n,list,iswap,nfirst,pbc_flag,pbc); - if (commKK->forward_comm_on_host) { + return AtomVecKokkos::pack_comm_self(n,list,nfirst,pbc_flag,pbc); + if (lmp->kokkos->forward_comm_on_host) { atomKK->sync(Host,X_MASK|RADIUS_MASK|RMASS_MASK); atomKK->modified(Host,X_MASK|RADIUS_MASK|RMASS_MASK); if (pbc_flag) { @@ -740,7 +733,7 @@ int AtomVecSphereKokkos::pack_comm_self( struct AtomVecSphereKokkos_PackCommSelf f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -748,7 +741,7 @@ int AtomVecSphereKokkos::pack_comm_self( struct AtomVecSphereKokkos_PackCommSelf f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -758,7 +751,7 @@ int AtomVecSphereKokkos::pack_comm_self( struct AtomVecSphereKokkos_PackCommSelf f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -766,7 +759,7 @@ int AtomVecSphereKokkos::pack_comm_self( struct AtomVecSphereKokkos_PackCommSelf f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -780,7 +773,7 @@ int AtomVecSphereKokkos::pack_comm_self( struct AtomVecSphereKokkos_PackCommSelf f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -788,7 +781,7 @@ int AtomVecSphereKokkos::pack_comm_self( struct AtomVecSphereKokkos_PackCommSelf f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -798,7 +791,7 @@ int AtomVecSphereKokkos::pack_comm_self( struct AtomVecSphereKokkos_PackCommSelf f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -806,7 +799,7 @@ int AtomVecSphereKokkos::pack_comm_self( struct AtomVecSphereKokkos_PackCommSelf f( atomKK->k_x, atomKK->k_radius,atomKK->k_rmass, - nfirst,list,iswap, + nfirst,list, domain->xprd,domain->yprd,domain->zprd, domain->xy,domain->xz,domain->yz,pbc); Kokkos::parallel_for(n,f); @@ -863,7 +856,7 @@ void AtomVecSphereKokkos::unpack_comm_kokkos( AtomVecKokkos::unpack_comm_kokkos(n,first,buf); return; } - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->modified(Host,X_MASK|RADIUS_MASK|RMASS_MASK); struct AtomVecSphereKokkos_UnpackComm f( atomKK->k_x, @@ -935,7 +928,7 @@ struct AtomVecSphereKokkos_UnpackCommVel { void AtomVecSphereKokkos::unpack_comm_vel_kokkos( const int &n, const int &first, const DAT::tdual_xfloat_2d &buf) { - if (commKK->forward_comm_on_host) { + if (lmp->kokkos->forward_comm_on_host) { atomKK->modified(Host,X_MASK|RADIUS_MASK|RMASS_MASK|V_MASK|OMEGA_MASK); if (radvary == 0) { struct AtomVecSphereKokkos_UnpackCommVel f( @@ -979,8 +972,7 @@ struct AtomVecSphereKokkos_PackBorder { typedef DeviceType device_type; typename ArrayTypes::t_xfloat_2d_um _buf; - const typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + const typename ArrayTypes::t_int_1d_const _list; const typename ArrayTypes::t_x_array_randomread _x; const typename ArrayTypes::t_tagint_1d _tag; const typename ArrayTypes::t_int_1d _type; @@ -990,8 +982,7 @@ struct AtomVecSphereKokkos_PackBorder { AtomVecSphereKokkos_PackBorder( const typename ArrayTypes::t_xfloat_2d &buf, - const typename ArrayTypes::t_int_2d_const &list, - const int &iswap, + const typename ArrayTypes::t_int_1d_const &list, const typename ArrayTypes::t_x_array &x, const typename ArrayTypes::t_tagint_1d &tag, const typename ArrayTypes::t_int_1d &type, @@ -999,7 +990,7 @@ struct AtomVecSphereKokkos_PackBorder { const typename ArrayTypes::t_float_1d &radius, const typename ArrayTypes::t_float_1d &rmass, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask), _radius(radius), _rmass(rmass), @@ -1012,7 +1003,7 @@ struct AtomVecSphereKokkos_PackBorder { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -1033,7 +1024,7 @@ struct AtomVecSphereKokkos_PackBorder { /* ---------------------------------------------------------------------- */ int AtomVecSphereKokkos::pack_border_kokkos( - int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, + int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -1054,14 +1045,14 @@ int AtomVecSphereKokkos::pack_border_kokkos( if (space==Host) { AtomVecSphereKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask, + h_x,h_tag,h_type,h_mask, h_radius,h_rmass, dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecSphereKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask, + d_x,d_tag,d_type,d_mask, d_radius,d_rmass, dx,dy,dz); Kokkos::parallel_for(n,f); @@ -1071,14 +1062,14 @@ int AtomVecSphereKokkos::pack_border_kokkos( if (space==Host) { AtomVecSphereKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask, + h_x,h_tag,h_type,h_mask, h_radius,h_rmass, dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecSphereKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask, + d_x,d_tag,d_type,d_mask, d_radius,d_rmass, dx,dy,dz); Kokkos::parallel_for(n,f); @@ -1094,8 +1085,7 @@ struct AtomVecSphereKokkos_PackBorderVel { typedef DeviceType device_type; typename ArrayTypes::t_xfloat_2d_um _buf; - const typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + const typename ArrayTypes::t_int_1d_const _list; const typename ArrayTypes::t_x_array_randomread _x; const typename ArrayTypes::t_tagint_1d _tag; const typename ArrayTypes::t_int_1d _type; @@ -1107,8 +1097,7 @@ struct AtomVecSphereKokkos_PackBorderVel { AtomVecSphereKokkos_PackBorderVel( const typename ArrayTypes::t_xfloat_2d &buf, - const typename ArrayTypes::t_int_2d_const &list, - const int &iswap, + const typename ArrayTypes::t_int_1d_const &list, const typename ArrayTypes::t_x_array &x, const typename ArrayTypes::t_tagint_1d &tag, const typename ArrayTypes::t_int_1d &type, @@ -1120,7 +1109,7 @@ struct AtomVecSphereKokkos_PackBorderVel { const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz, const X_FLOAT &dvx, const X_FLOAT &dvy, const X_FLOAT &dvz, const int &deform_groupbit): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask), _radius(radius), _rmass(rmass), @@ -1136,7 +1125,7 @@ struct AtomVecSphereKokkos_PackBorderVel { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -1172,7 +1161,7 @@ struct AtomVecSphereKokkos_PackBorderVel { /* ---------------------------------------------------------------------- */ int AtomVecSphereKokkos::pack_border_vel_kokkos( - int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, + int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx=0,dy=0,dz=0; @@ -1195,7 +1184,7 @@ int AtomVecSphereKokkos::pack_border_vel_kokkos( if (space==Host) { AtomVecSphereKokkos_PackBorderVel f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask, + h_x,h_tag,h_type,h_mask, h_radius,h_rmass, h_v, h_omega, dx,dy,dz,dvx,dvy,dvz, @@ -1204,7 +1193,7 @@ int AtomVecSphereKokkos::pack_border_vel_kokkos( } else { AtomVecSphereKokkos_PackBorderVel f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask, + d_x,d_tag,d_type,d_mask, d_radius,d_rmass, d_v, d_omega, dx,dy,dz,dvx,dvy,dvz, @@ -1219,7 +1208,7 @@ int AtomVecSphereKokkos::pack_border_vel_kokkos( if (space==Host) { AtomVecSphereKokkos_PackBorderVel f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask, + h_x,h_tag,h_type,h_mask, h_radius,h_rmass, h_v, h_omega, dx,dy,dz,dvx,dvy,dvz, @@ -1228,7 +1217,7 @@ int AtomVecSphereKokkos::pack_border_vel_kokkos( } else { AtomVecSphereKokkos_PackBorderVel f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask, + d_x,d_tag,d_type,d_mask, d_radius,d_rmass, d_v, d_omega, dx,dy,dz,dvx,dvy,dvz, @@ -1240,7 +1229,7 @@ int AtomVecSphereKokkos::pack_border_vel_kokkos( if (space==Host) { AtomVecSphereKokkos_PackBorderVel f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask, + h_x,h_tag,h_type,h_mask, h_radius,h_rmass, h_v, h_omega, dx,dy,dz,dvx,dvy,dvz, @@ -1249,7 +1238,7 @@ int AtomVecSphereKokkos::pack_border_vel_kokkos( } else { AtomVecSphereKokkos_PackBorderVel f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask, + d_x,d_tag,d_type,d_mask, d_radius,d_rmass, d_v, d_omega, dx,dy,dz,dvx,dvy,dvz, diff --git a/src/KOKKOS/atom_vec_sphere_kokkos.h b/src/KOKKOS/atom_vec_sphere_kokkos.h index 34529320d9..b28da45c6a 100644 --- a/src/KOKKOS/atom_vec_sphere_kokkos.h +++ b/src/KOKKOS/atom_vec_sphere_kokkos.h @@ -37,29 +37,27 @@ class AtomVecSphereKokkos : public AtomVecKokkos, public AtomVecSphere { void grow_pointers() override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_comm_kokkos(const int &n, const DAT::tdual_int_2d &k_sendlist, - const int & iswap, + int pack_comm_kokkos(const int &n, const DAT::tdual_int_1d &k_sendlist, const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int pbc[]) override; void unpack_comm_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf) override; - int pack_comm_vel_kokkos(const int &n, const DAT::tdual_int_2d &k_sendlist, - const int & iswap, + int pack_comm_vel_kokkos(const int &n, const DAT::tdual_int_1d &k_sendlist, const DAT::tdual_xfloat_2d &buf, const int &pbc_flag, const int pbc[]) override; void unpack_comm_vel_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf) override; - int pack_comm_self(const int &n, const DAT::tdual_int_2d &list, - const int & iswap, const int nfirst, + int pack_comm_self(const int &n, const DAT::tdual_int_1d &list, + const int nfirst, const int &pbc_flag, const int pbc[]) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, ExecutionSpace space) override; - int pack_border_vel_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_vel_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_vel_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/atom_vec_spin_kokkos.cpp b/src/KOKKOS/atom_vec_spin_kokkos.cpp index 1f52b56269..7cd0b8934c 100644 --- a/src/KOKKOS/atom_vec_spin_kokkos.cpp +++ b/src/KOKKOS/atom_vec_spin_kokkos.cpp @@ -156,8 +156,7 @@ struct AtomVecSpinKokkos_PackComm { typename ArrayTypes::t_x_array_randomread _x; typename ArrayTypes::t_sp_array_randomread _sp; typename ArrayTypes::t_xfloat_2d_um _buf; - typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + typename ArrayTypes::t_int_1d_const _list; X_FLOAT _xprd,_yprd,_zprd,_xy,_xz,_yz; X_FLOAT _pbc[6]; @@ -165,12 +164,11 @@ struct AtomVecSpinKokkos_PackComm { const typename DAT::tdual_x_array &x, const typename DAT::tdual_float_1d_4 &sp, const typename DAT::tdual_xfloat_2d &buf, - const typename DAT::tdual_int_2d &list, - const int & iswap, + const typename DAT::tdual_int_1d &list, const X_FLOAT &xprd, const X_FLOAT &yprd, const X_FLOAT &zprd, const X_FLOAT &xy, const X_FLOAT &xz, const X_FLOAT &yz, const int* const pbc): _x(x.view()),_sp(sp.view()), - _list(list.view()),_iswap(iswap), + _list(list.view()), _xprd(xprd),_yprd(yprd),_zprd(zprd), _xy(xy),_xz(xz),_yz(yz) { const size_t maxsend = (buf.view().extent(0)*buf.view().extent(1))/3; @@ -182,7 +180,7 @@ struct AtomVecSpinKokkos_PackComm { KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -220,8 +218,7 @@ struct AtomVecSpinKokkos_PackBorder { typedef DeviceType device_type; typename ArrayTypes::t_xfloat_2d _buf; - const typename ArrayTypes::t_int_2d_const _list; - const int _iswap; + const typename ArrayTypes::t_int_1d_const _list; const typename ArrayTypes::t_x_array_randomread _x; const typename ArrayTypes::t_tagint_1d _tag; const typename ArrayTypes::t_int_1d _type; @@ -231,21 +228,20 @@ struct AtomVecSpinKokkos_PackBorder { AtomVecSpinKokkos_PackBorder( const typename ArrayTypes::t_xfloat_2d &buf, - const typename ArrayTypes::t_int_2d_const &list, - const int & iswap, + const typename ArrayTypes::t_int_1d_const &list, const typename ArrayTypes::t_x_array &x, const typename ArrayTypes::t_tagint_1d &tag, const typename ArrayTypes::t_int_1d &type, const typename ArrayTypes::t_int_1d &mask, const typename ArrayTypes::t_sp_array &sp, const X_FLOAT &dx, const X_FLOAT &dy, const X_FLOAT &dz): - _buf(buf),_list(list),_iswap(iswap), + _buf(buf),_list(list), _x(x),_tag(tag),_type(type),_mask(mask),_sp(sp), _dx(dx),_dy(dy),_dz(dz) {} KOKKOS_INLINE_FUNCTION void operator() (const int& i) const { - const int j = _list(_iswap,i); + const int j = _list(i); if (PBC_FLAG == 0) { _buf(i,0) = _x(j,0); _buf(i,1) = _x(j,1); @@ -274,7 +270,7 @@ struct AtomVecSpinKokkos_PackBorder { /* ---------------------------------------------------------------------- */ -int AtomVecSpinKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, DAT::tdual_xfloat_2d buf,int iswap, +int AtomVecSpinKokkos::pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) { X_FLOAT dx,dy,dz; @@ -292,12 +288,12 @@ int AtomVecSpinKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, D if(space==Host) { AtomVecSpinKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_sp,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_sp,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecSpinKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_sp,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_sp,dx,dy,dz); Kokkos::parallel_for(n,f); } @@ -306,12 +302,12 @@ int AtomVecSpinKokkos::pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, D if(space==Host) { AtomVecSpinKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,h_x,h_tag,h_type,h_mask,h_sp,dx,dy,dz); + h_x,h_tag,h_type,h_mask,h_sp,dx,dy,dz); Kokkos::parallel_for(n,f); } else { AtomVecSpinKokkos_PackBorder f( buf.view(), k_sendlist.view(), - iswap,d_x,d_tag,d_type,d_mask,d_sp,dx,dy,dz); + d_x,d_tag,d_type,d_mask,d_sp,dx,dy,dz); Kokkos::parallel_for(n,f); } } diff --git a/src/KOKKOS/atom_vec_spin_kokkos.h b/src/KOKKOS/atom_vec_spin_kokkos.h index f0145e4db7..6f968dcd25 100644 --- a/src/KOKKOS/atom_vec_spin_kokkos.h +++ b/src/KOKKOS/atom_vec_spin_kokkos.h @@ -36,8 +36,8 @@ class AtomVecSpinKokkos : public AtomVecKokkos, public AtomVecSpin { void grow_pointers() override; void force_clear(int, size_t) override; void sort_kokkos(Kokkos::BinSort &Sorter) override; - int pack_border_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, + int pack_border_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_2d buf, int pbc_flag, int *pbc, ExecutionSpace space) override; void unpack_border_kokkos(const int &n, const int &nfirst, const DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/comm_kokkos.cpp b/src/KOKKOS/comm_kokkos.cpp index 6bb2d7e4d0..2425857d61 100644 --- a/src/KOKKOS/comm_kokkos.cpp +++ b/src/KOKKOS/comm_kokkos.cpp @@ -142,11 +142,15 @@ void CommKokkos::init() if (force->newton == 0) check_reverse = 0; if (force->pair) check_reverse += force->pair->comm_reverse_off; - if (!comm_f_only) // not all Kokkos atom_vec styles have reverse pack/unpack routines yet + if (!comm_f_only) {// not all Kokkos atom_vec styles have reverse pack/unpack routines yet reverse_comm_classic = true; + lmp->kokkos->reverse_comm_classic = 1; + } - if (ghost_velocity && atomKK->avecKK->no_comm_vel_flag) // not all Kokkos atom_vec styles have comm vel pack/unpack routines yet + if (ghost_velocity && atomKK->avecKK->no_comm_vel_flag) { // not all Kokkos atom_vec styles have comm vel pack/unpack routines yet forward_comm_classic = true; + lmp->kokkos->forward_comm_classic = 1; + } } /* ---------------------------------------------------------------------- @@ -157,8 +161,8 @@ void CommKokkos::init() void CommKokkos::forward_comm(int dummy) { if (!forward_comm_classic) { - if (forward_comm_on_host) forward_comm_device(dummy); - else forward_comm_device(dummy); + if (forward_comm_on_host) forward_comm_device(); + else forward_comm_device(); return; } @@ -181,7 +185,7 @@ void CommKokkos::forward_comm(int dummy) /* ---------------------------------------------------------------------- */ template -void CommKokkos::forward_comm_device(int) +void CommKokkos::forward_comm_device() { int n; MPI_Request request; @@ -192,7 +196,6 @@ void CommKokkos::forward_comm_device(int) // if comm_x_only set, exchange or copy directly to x, don't unpack k_sendlist.sync(); - atomKK->sync(ExecutionSpaceFromDevice::space,X_MASK); if (comm->nprocs == 1 && !ghost_velocity) { k_swap.sync(); @@ -211,26 +214,26 @@ void CommKokkos::forward_comm_device(int) MPI_Irecv(buf,size_forward_recv[iswap],MPI_DOUBLE, recvproc[iswap],0,world,&request); } - n = atomKK->avecKK->pack_comm_kokkos(sendnum[iswap],k_sendlist, - iswap,k_buf_send,pbc_flag[iswap],pbc[iswap]); + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + n = atomKK->avecKK->pack_comm_kokkos(sendnum[iswap],k_sendlist_iswap, + k_buf_send,pbc_flag[iswap],pbc[iswap]); DeviceType().fence(); if (n) { MPI_Send(k_buf_send.view().data(), n,MPI_DOUBLE,sendproc[iswap],0,world); } - if (size_forward_recv[iswap]) { + if (size_forward_recv[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE); - atomKK->modified(ExecutionSpaceFromDevice:: - space,X_MASK); - } + } else if (ghost_velocity) { if (size_forward_recv[iswap]) { MPI_Irecv(k_buf_recv.view().data(), size_forward_recv[iswap],MPI_DOUBLE, recvproc[iswap],0,world,&request); } - n = atomKK->avecKK->pack_comm_vel_kokkos(sendnum[iswap],k_sendlist,iswap, + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + n = atomKK->avecKK->pack_comm_vel_kokkos(sendnum[iswap],k_sendlist_iswap, k_buf_send,pbc_flag[iswap],pbc[iswap]); DeviceType().fence(); if (n) { @@ -245,7 +248,8 @@ void CommKokkos::forward_comm_device(int) MPI_Irecv(k_buf_recv.view().data(), size_forward_recv[iswap],MPI_DOUBLE, recvproc[iswap],0,world,&request); - n = atomKK->avecKK->pack_comm_kokkos(sendnum[iswap],k_sendlist,iswap, + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + n = atomKK->avecKK->pack_comm_kokkos(sendnum[iswap],k_sendlist_iswap, k_buf_send,pbc_flag[iswap],pbc[iswap]); DeviceType().fence(); if (n) @@ -257,12 +261,15 @@ void CommKokkos::forward_comm_device(int) } } else { if (!ghost_velocity) { - if (sendnum[iswap]) - n = atomKK->avecKK->pack_comm_self(sendnum[iswap],k_sendlist,iswap, + if (sendnum[iswap]) { + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + n = atomKK->avecKK->pack_comm_self(sendnum[iswap],k_sendlist_iswap, firstrecv[iswap],pbc_flag[iswap],pbc[iswap]); - DeviceType().fence(); + DeviceType().fence(); + } } else { - n = atomKK->avecKK->pack_comm_vel_kokkos(sendnum[iswap],k_sendlist,iswap, + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + n = atomKK->avecKK->pack_comm_vel_kokkos(sendnum[iswap],k_sendlist_iswap, k_buf_send,pbc_flag[iswap],pbc[iswap]); DeviceType().fence(); atomKK->avecKK->unpack_comm_vel_kokkos(recvnum[iswap],firstrecv[iswap],k_buf_send); @@ -299,10 +306,10 @@ void CommKokkos::reverse_comm() atomKK->modified(Host,F_MASK); else atomKK->modified(Host,ALL_MASK); - - //atomKK->sync(Device,ALL_MASK); // is this needed? } +/* ---------------------------------------------------------------------- */ + template void CommKokkos::reverse_comm_device() { @@ -315,7 +322,6 @@ void CommKokkos::reverse_comm_device() // if comm_f_only set, exchange or copy directly from f, don't pack k_sendlist.sync(); - atomKK->sync(ExecutionSpaceFromDevice::space,F_MASK); for (int iswap = nswap-1; iswap >= 0; iswap--) { if (sendproc[iswap] != me) { @@ -330,11 +336,9 @@ void CommKokkos::reverse_comm_device() MPI_Send(buf,size_reverse_send[iswap],MPI_DOUBLE, recvproc[iswap],0,world); } - if (size_reverse_recv[iswap]) { + if (size_reverse_recv[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE); - atomKK->modified(ExecutionSpaceFromDevice:: - space,F_MASK); - } + } else { if (size_reverse_recv[iswap]) MPI_Irecv(k_buf_recv.view().data(), @@ -347,18 +351,28 @@ void CommKokkos::reverse_comm_device() MPI_DOUBLE,recvproc[iswap],0,world); if (size_reverse_recv[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE); } - atomKK->avecKK->unpack_reverse_kokkos(sendnum[iswap],k_sendlist,iswap, + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + atomKK->avecKK->unpack_reverse_kokkos(sendnum[iswap],k_sendlist_iswap, k_buf_recv); DeviceType().fence(); } else { - if (sendnum[iswap]) - n = atomKK->avecKK->unpack_reverse_self(sendnum[iswap],k_sendlist,iswap, + if (sendnum[iswap]) { + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + n = atomKK->avecKK->pack_reverse_self(sendnum[iswap],k_sendlist_iswap, firstrecv[iswap]); + } } } } -/* ---------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + forward communication invoked by a Fix + size/nsize used only to set recv buffer limit + size = 0 (default) -> use comm_forward from Fix + size > 0 -> Fix passes max size per atom + the latter is only useful if Fix does several comm modes, + some are smaller than max stored in its comm_forward +------------------------------------------------------------------------- */ void CommKokkos::forward_comm(Fix *fix, int size) { @@ -371,6 +385,8 @@ void CommKokkos::forward_comm(Fix *fix, int size) } } +/* ---------------------------------------------------------------------- */ + template void CommKokkos::forward_comm_device(Fix *fix, int size) { @@ -393,8 +409,9 @@ void CommKokkos::forward_comm_device(Fix *fix, int size) // pack buffer - n = fixKKBase->pack_forward_comm_kokkos(sendnum[iswap],k_sendlist, - iswap,k_buf_send_fix,pbc_flag[iswap],pbc[iswap]); + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + n = fixKKBase->pack_forward_comm_kokkos(sendnum[iswap],k_sendlist_iswap, + k_buf_send_fix,pbc_flag[iswap],pbc[iswap]); DeviceType().fence(); // exchange with another proc @@ -435,7 +452,14 @@ void CommKokkos::forward_comm_device(Fix *fix, int size) } } -/* ---------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + reverse communication invoked by a Fix + size/nsize used only to set recv buffer limit + size = 0 (default) -> use comm_forward from Fix + size > 0 -> Fix passes max size per atom + the latter is only useful if Fix does several comm modes, + some are smaller than max stored in its comm_forward +------------------------------------------------------------------------- */ void CommKokkos::reverse_comm(Fix *fix, int size) { @@ -443,18 +467,66 @@ void CommKokkos::reverse_comm(Fix *fix, int size) CommBrick::reverse_comm(fix, size); } + +/* ---------------------------------------------------------------------- + reverse communication invoked by a Fix with variable size data + query fix for pack size to ensure buf_send is big enough + handshake sizes before each Irecv/Send to ensure buf_recv is big enough +------------------------------------------------------------------------- */ + +void CommKokkos::reverse_comm_variable(Fix *fix) +{ + k_sendlist.sync(); + CommBrick::reverse_comm_variable(fix); +} + +/* ---------------------------------------------------------------------- + forward communication invoked by a Compute + nsize used only to set recv buffer limit +------------------------------------------------------------------------- */ + void CommKokkos::forward_comm(Compute *compute) { k_sendlist.sync(); CommBrick::forward_comm(compute); } +/* ---------------------------------------------------------------------- + forward communication invoked by a Bond + nsize used only to set recv buffer limit +------------------------------------------------------------------------- */ + +void CommKokkos::forward_comm(Bond *bond) +{ + CommBrick::forward_comm(bond); +} + +/* ---------------------------------------------------------------------- + reverse communication invoked by a Bond + nsize used only to set recv buffer limit +------------------------------------------------------------------------- */ + +void CommKokkos::reverse_comm(Bond *bond) +{ + CommBrick::reverse_comm(bond); +} + +/* ---------------------------------------------------------------------- + reverse communication invoked by a Compute + nsize used only to set recv buffer limit +------------------------------------------------------------------------- */ + void CommKokkos::reverse_comm(Compute *compute) { k_sendlist.sync(); CommBrick::reverse_comm(compute); } +/* ---------------------------------------------------------------------- + forward communication invoked by a Dump + nsize used only to set recv buffer limit +------------------------------------------------------------------------- */ + void CommKokkos::forward_comm(Pair *pair) { if (pair->execution_space == Host || forward_pair_comm_classic) { @@ -466,6 +538,8 @@ void CommKokkos::forward_comm(Pair *pair) } } +/* ---------------------------------------------------------------------- */ + template void CommKokkos::forward_comm_device(Pair *pair) { @@ -488,8 +562,9 @@ void CommKokkos::forward_comm_device(Pair *pair) // pack buffer - n = pairKKBase->pack_forward_comm_kokkos(sendnum[iswap],k_sendlist, - iswap,k_buf_send_pair,pbc_flag[iswap],pbc[iswap]); + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + n = pairKKBase->pack_forward_comm_kokkos(sendnum[iswap],k_sendlist_iswap, + k_buf_send_pair,pbc_flag[iswap],pbc[iswap]); DeviceType().fence(); // exchange with another proc @@ -530,18 +605,24 @@ void CommKokkos::forward_comm_device(Pair *pair) } } +/* ---------------------------------------------------------------------- */ + void CommKokkos::grow_buf_pair(int n) { max_buf_pair = n * BUFFACTOR; k_buf_send_pair.resize(max_buf_pair); k_buf_recv_pair.resize(max_buf_pair); } +/* ---------------------------------------------------------------------- */ + void CommKokkos::grow_buf_fix(int n) { max_buf_fix = n * BUFFACTOR; k_buf_send_fix.resize(max_buf_fix); k_buf_recv_fix.resize(max_buf_fix); } +/* ---------------------------------------------------------------------- */ + void CommKokkos::reverse_comm(Pair *pair) { if (pair->execution_space == Host || !pair->reverse_comm_device || reverse_pair_comm_classic) { @@ -553,6 +634,8 @@ void CommKokkos::reverse_comm(Pair *pair) } } +/* ---------------------------------------------------------------------- */ + template void CommKokkos::reverse_comm_device(Pair *pair) { @@ -610,18 +693,23 @@ void CommKokkos::reverse_comm_device(Pair *pair) // unpack buffer - pairKKBase->unpack_reverse_comm_kokkos(sendnum[iswap],k_sendlist, - iswap,k_buf_tmp); + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); + pairKKBase->unpack_reverse_comm_kokkos(sendnum[iswap],k_sendlist_iswap, + k_buf_tmp); DeviceType().fence(); } } +/* ---------------------------------------------------------------------- */ + void CommKokkos::forward_comm(Dump *dump) { k_sendlist.sync(); CommBrick::forward_comm(dump); } +/* ---------------------------------------------------------------------- */ + void CommKokkos::reverse_comm(Dump *dump) { k_sendlist.sync(); @@ -668,6 +756,7 @@ void CommKokkos::exchange() } } exchange_comm_classic = true; + lmp->kokkos->exchange_comm_classic = 1; } } } @@ -980,6 +1069,7 @@ void CommKokkos::borders() "switching to classic exchange/border communication"); } exchange_comm_classic = true; + lmp->kokkos->exchange_comm_classic = 1; } } @@ -1202,14 +1292,15 @@ void CommKokkos::borders_device() { if (nsend*size_border > maxsend) grow_send_kokkos(nsend*size_border,0); if (ghost_velocity) { + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); n = atomKK->avecKK-> - pack_border_vel_kokkos(nsend,k_sendlist,k_buf_send,iswap, + pack_border_vel_kokkos(nsend,k_sendlist_iswap,k_buf_send, pbc_flag[iswap],pbc[iswap],exec_space); DeviceType().fence(); - } - else { + } else { + auto k_sendlist_iswap = Kokkos::subview(k_sendlist,iswap,Kokkos::ALL); n = atomKK->avecKK-> - pack_border_kokkos(nsend,k_sendlist,k_buf_send,iswap, + pack_border_kokkos(nsend,k_sendlist_iswap,k_buf_send, pbc_flag[iswap],pbc[iswap],exec_space); DeviceType().fence(); } diff --git a/src/KOKKOS/comm_kokkos.h b/src/KOKKOS/comm_kokkos.h index e06810b939..4fb4dfbe29 100644 --- a/src/KOKKOS/comm_kokkos.h +++ b/src/KOKKOS/comm_kokkos.h @@ -45,18 +45,21 @@ class CommKokkos : public CommBrick { void exchange() override; // move atoms to new procs void borders() override; // setup list of atoms to comm - void forward_comm(class Pair *) override; // forward comm from a Pair - void reverse_comm(class Pair *) override; // reverse comm from a Pair - void forward_comm(class Fix *, int size=0) override; // forward comm from a Fix - void reverse_comm(class Fix *, int size=0) override; // reverse comm from a Fix - void forward_comm(class Compute *) override; // forward from a Compute - void reverse_comm(class Compute *) override; // reverse from a Compute - void forward_comm(class Dump *) override; // forward comm from a Dump - void reverse_comm(class Dump *) override; // reverse comm from a Dump + void forward_comm(class Pair *) override; // forward comm from a Pair + void reverse_comm(class Pair *) override; // reverse comm from a Pair + void forward_comm(class Bond *) override; // forward comm from a Bond + void reverse_comm(class Bond *) override; // reverse comm from a Bond + void forward_comm(class Fix *, int size = 0) override; // forward comm from a Fix + void reverse_comm(class Fix *, int size = 0) override; // reverse comm from a Fix + void reverse_comm_variable(class Fix *) override; // variable size reverse comm from a Fix + void forward_comm(class Compute *) override; // forward from a Compute + void reverse_comm(class Compute *) override; // reverse from a Compute + void forward_comm(class Dump *) override; // forward comm from a Dump + void reverse_comm(class Dump *) override; // reverse comm from a Dump void forward_comm_array(int, double **) override; // forward comm of array - template void forward_comm_device(int dummy); + template void forward_comm_device(); template void reverse_comm_device(); template void forward_comm_device(Pair *pair); template void reverse_comm_device(Pair *pair); @@ -95,7 +98,6 @@ class CommKokkos : public CommBrick { void copy_swap_info(); }; -} +} // namespace LAMMPS_NS #endif - diff --git a/src/KOKKOS/comm_tiled_kokkos.cpp b/src/KOKKOS/comm_tiled_kokkos.cpp index 5b35527b7e..2e4ca30bed 100644 --- a/src/KOKKOS/comm_tiled_kokkos.cpp +++ b/src/KOKKOS/comm_tiled_kokkos.cpp @@ -16,13 +16,28 @@ #include "atom_kokkos.h" #include "atom_masks.h" -#include "atom_vec.h" +#include "atom_vec_kokkos.h" +#include "compute.h" +#include "dump.h" +#include "fix.h" +#include "force.h" +#include "kokkos.h" +#include "memory_kokkos.h" +#include "modify.h" +#include "output.h" using namespace LAMMPS_NS; +static constexpr double BUFFACTOR = 1.5; +static constexpr int BUFMIN = 1024; +static constexpr int BUFEXTRA = 1000; + /* ---------------------------------------------------------------------- */ -CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp) : CommTiled(_lmp) {} +CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp) : CommTiled(_lmp) +{ + sendlist = nullptr; +} /* ---------------------------------------------------------------------- */ //IMPORTANT: we *MUST* pass "*oldcomm" to the Comm initializer here, as @@ -31,10 +46,69 @@ CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp) : CommTiled(_lmp) {} // The call to Comm::copy_arrays() then converts the shallow copy // into a deep copy of the class with the new layout. -CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp, Comm *oldcomm) : CommTiled(_lmp,oldcomm) {} +CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp, Comm *oldcomm) : CommTiled(_lmp,oldcomm) +{ + sendlist = nullptr; +} /* ---------------------------------------------------------------------- */ +CommTiledKokkos::~CommTiledKokkos() +{ + memoryKK->destroy_kokkos(k_sendlist,sendlist); + sendlist = nullptr; + buf_send = nullptr; + buf_recv = nullptr; +} + +/* ---------------------------------------------------------------------- */ + +void CommTiledKokkos::init() +{ + atomKK = (AtomKokkos *) atom; + exchange_comm_classic = lmp->kokkos->exchange_comm_classic; + forward_comm_classic = lmp->kokkos->forward_comm_classic; + forward_pair_comm_classic = lmp->kokkos->forward_pair_comm_classic; + reverse_pair_comm_classic = lmp->kokkos->reverse_pair_comm_classic; + forward_fix_comm_classic = lmp->kokkos->forward_fix_comm_classic; + reverse_comm_classic = lmp->kokkos->reverse_comm_classic; + exchange_comm_on_host = lmp->kokkos->exchange_comm_on_host; + forward_comm_on_host = lmp->kokkos->forward_comm_on_host; + reverse_comm_on_host = lmp->kokkos->reverse_comm_on_host; + + CommTiled::init(); + + int check_forward = 0; + int check_reverse = 0; + if (force->pair && (force->pair->execution_space == Host)) + check_forward += force->pair->comm_forward; + if (force->pair && (force->pair->execution_space == Host)) + check_reverse += force->pair->comm_reverse; + + for (const auto &fix : modify->get_fix_list()) { + check_forward += fix->comm_forward; + check_reverse += fix->comm_reverse; + } + + for (const auto &compute : modify->get_compute_list()) { + check_forward += compute->comm_forward; + check_reverse += compute->comm_reverse; + } + + for (const auto &dump : output->get_dump_list()) { + check_forward += dump->comm_forward; + check_reverse += dump->comm_reverse; + } + + if (force->newton == 0) check_reverse = 0; + if (force->pair) check_reverse += force->pair->comm_reverse_off; + + if (!comm_f_only) { // not all Kokkos atom_vec styles have reverse pack/unpack routines yet + reverse_comm_classic = true; + lmp->kokkos->reverse_comm_classic = 1; + } +} + /* ---------------------------------------------------------------------- forward communication of atom coords every timestep other per-atom attributes may also be sent via pack/unpack routines @@ -42,6 +116,14 @@ CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp, Comm *oldcomm) : CommTiled(_lmp,o void CommTiledKokkos::forward_comm(int dummy) { + if (!forward_comm_classic) { + if (forward_comm_on_host) forward_comm_device(); + else forward_comm_device(); + return; + } + + k_sendlist.sync(); + if (comm_x_only) { atomKK->sync(Host,X_MASK); atomKK->modified(Host,X_MASK); @@ -56,6 +138,127 @@ void CommTiledKokkos::forward_comm(int dummy) CommTiled::forward_comm(dummy); } +/* ---------------------------------------------------------------------- */ + +template +void CommTiledKokkos::forward_comm_device() +{ + int i,irecv,n,nsend,nrecv; + double *buf; + + // exchange data with another set of procs in each swap + // post recvs from all procs except self + // send data to all procs except self + // copy data to self if sendself is set + // wait on all procs except self and unpack received data + // if comm_x_only set, exchange or copy directly to x, don't unpack + + k_sendlist.sync(); + + for (int iswap = 0; iswap < nswap; iswap++) { + nsend = nsendproc[iswap] - sendself[iswap]; + nrecv = nrecvproc[iswap] - sendself[iswap]; + + if (comm_x_only) { + if (recvother[iswap]) { + for (i = 0; i < nrecv; i++) { + buf = atomKK->k_x.view().data() + + firstrecv[iswap][i]*atomKK->k_x.view().extent(1); + MPI_Irecv(buf,size_forward_recv[iswap][i], + MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]); + } + } + if (sendother[iswap]) { + for (i = 0; i < nsend; i++) { + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,i,Kokkos::ALL); + n = atomKK->avecKK->pack_comm_kokkos(sendnum[iswap][i],k_sendlist_small, + k_buf_send,pbc_flag[iswap][i],pbc[iswap][i]); + DeviceType().fence(); + MPI_Send(k_buf_send.view().data(),n,MPI_DOUBLE,sendproc[iswap][i],0,world); + } + } + if (sendself[iswap]) { + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,nsend,Kokkos::ALL); + atomKK->avecKK->pack_comm_self(sendnum[iswap][nsend],k_sendlist_small, + firstrecv[iswap][nrecv],pbc_flag[iswap][nsend],pbc[iswap][nsend]); + DeviceType().fence(); + } + if (recvother[iswap]) MPI_Waitall(nrecv,requests,MPI_STATUS_IGNORE); + + } else if (ghost_velocity) { + if (recvother[iswap]) { + for (i = 0; i < nrecv; i++) { + buf = k_buf_recv.view().data() + + forward_recv_offset[iswap][i]*k_buf_recv.view().extent(1); + MPI_Irecv(buf, + size_forward_recv[iswap][i],MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]); + } + } + if (sendother[iswap]) { + for (i = 0; i < nsend; i++) { + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,i,Kokkos::ALL); + n = atomKK->avecKK->pack_comm_vel_kokkos(sendnum[iswap][i],k_sendlist_small, + k_buf_send,pbc_flag[iswap][i],pbc[iswap][i]); + DeviceType().fence(); + MPI_Send(k_buf_send.view().data(),n, + MPI_DOUBLE,sendproc[iswap][i],0,world); + } + } + if (sendself[iswap]) { + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,nsend,Kokkos::ALL); + atomKK->avecKK->pack_comm_vel_kokkos(sendnum[iswap][nsend],k_sendlist_small, + k_buf_send,pbc_flag[iswap][nsend],pbc[iswap][nsend]); + DeviceType().fence(); + atomKK->avecKK->unpack_comm_vel_kokkos(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],k_buf_send); + DeviceType().fence(); + } + if (recvother[iswap]) { + for (i = 0; i < nrecv; i++) { + MPI_Waitany(nrecv,requests,&irecv,MPI_STATUS_IGNORE); + auto k_buf_recv_offset = Kokkos::subview(k_buf_recv,std::pair(forward_recv_offset[iswap][irecv],(int)k_buf_recv.extent(0)),Kokkos::ALL); + atomKK->avecKK->unpack_comm_vel_kokkos(recvnum[iswap][irecv],firstrecv[iswap][irecv], + k_buf_recv_offset); + DeviceType().fence(); + } + } + + } else { + if (recvother[iswap]) { + for (i = 0; i < nrecv; i++) { + buf = k_buf_recv.view().data() + + forward_recv_offset[iswap][i]*k_buf_recv.view().extent(1); + MPI_Irecv(buf, + size_forward_recv[iswap][i],MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]); + } + } + if (sendother[iswap]) { + for (i = 0; i < nsend; i++) { + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,i,Kokkos::ALL); + n = atomKK->avecKK->pack_comm_kokkos(sendnum[iswap][i],k_sendlist_small, + k_buf_send,pbc_flag[iswap][i],pbc[iswap][i]); + DeviceType().fence(); + MPI_Send(k_buf_send.view().data(),n,MPI_DOUBLE,sendproc[iswap][i],0,world); + } + } + if (sendself[iswap]) { + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,nsend,Kokkos::ALL); + n = atomKK->avecKK->pack_comm_kokkos(sendnum[iswap][nsend],k_sendlist_small, + k_buf_send,pbc_flag[iswap][nsend],pbc[iswap][nsend]); + DeviceType().fence(); + } + if (recvother[iswap]) { + for (i = 0; i < nrecv; i++) { + MPI_Waitany(nrecv,requests,&irecv,MPI_STATUS_IGNORE); + auto k_buf_recv_offset = Kokkos::subview(k_buf_recv,std::pair(forward_recv_offset[iswap][irecv],(int)k_buf_recv.extent(0)),Kokkos::ALL); + atomKK->avecKK->unpack_comm_kokkos(recvnum[iswap][irecv],firstrecv[iswap][irecv], + k_buf_recv_offset); + DeviceType().fence(); + } + } + } + } +} + /* ---------------------------------------------------------------------- reverse communication of forces on atoms every timestep other per-atom attributes may also be sent via pack/unpack routines @@ -63,16 +266,117 @@ void CommTiledKokkos::forward_comm(int dummy) void CommTiledKokkos::reverse_comm() { + if (!reverse_comm_classic) { + if (reverse_comm_on_host) reverse_comm_device(); + else reverse_comm_device(); + return; + } + + k_sendlist.sync(); + if (comm_f_only) atomKK->sync(Host,F_MASK); else atomKK->sync(Host,ALL_MASK); + CommTiled::reverse_comm(); + if (comm_f_only) atomKK->modified(Host,F_MASK); else atomKK->modified(Host,ALL_MASK); - atomKK->sync(Device,ALL_MASK); +} + +/* ---------------------------------------------------------------------- */ + +template +void CommTiledKokkos::reverse_comm_device() +{ + int i,irecv,n,nsend,nrecv; + double *buf; + + // exchange data with another set of procs in each swap + // post recvs from all procs except self + // send data to all procs except self + // copy data to self if sendself is set + // wait on all procs except self and unpack received data + // if comm_f_only set, exchange or copy directly from f, don't pack + + k_sendlist.sync(); + + for (int iswap = nswap-1; iswap >= 0; iswap--) { + nsend = nsendproc[iswap] - sendself[iswap]; + nrecv = nrecvproc[iswap] - sendself[iswap]; + + if (comm_f_only) { + if (sendother[iswap]) { + for (i = 0; i < nsend; i++) { + buf = k_buf_recv.view().data() + + reverse_recv_offset[iswap][i]*k_buf_recv.view().extent(1); + MPI_Irecv(buf, + size_reverse_recv[iswap][i],MPI_DOUBLE,sendproc[iswap][i],0,world,&requests[i]); + } + } + if (recvother[iswap]) { + for (i = 0; i < nrecv; i++) { + buf = atomKK->k_f.view().data() + + firstrecv[iswap][i]*atomKK->k_f.view().extent(1); + MPI_Send(buf,size_reverse_send[iswap][i], + MPI_DOUBLE,recvproc[iswap][i],0,world); + } + } + if (sendself[iswap]) { + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,nsend,Kokkos::ALL); + atomKK->avecKK->pack_reverse_self(sendnum[iswap][nsend],k_sendlist_small, + firstrecv[iswap][nrecv]); + DeviceType().fence(); + } + if (sendother[iswap]) { + for (i = 0; i < nsend; i++) { + MPI_Waitany(nsend,requests,&irecv,MPI_STATUS_IGNORE); + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,irecv,Kokkos::ALL); + auto k_buf_recv_offset = Kokkos::subview(k_buf_recv,std::pair(reverse_recv_offset[iswap][irecv],(int)k_buf_recv.extent(0)),Kokkos::ALL); + atomKK->avecKK->unpack_reverse_kokkos(sendnum[iswap][irecv],k_sendlist_small, + k_buf_recv_offset); + DeviceType().fence(); + } + } + + } else { + if (sendother[iswap]) { + for (i = 0; i < nsend; i++) { + buf = k_buf_recv.view().data() + + reverse_recv_offset[iswap][i]*k_buf_recv.view().extent(1); + MPI_Irecv(buf, + size_reverse_recv[iswap][i],MPI_DOUBLE,sendproc[iswap][i],0,world,&requests[i]); + } + } + if (recvother[iswap]) { + for (i = 0; i < nrecv; i++) { + n = atomKK->avecKK->pack_reverse_kokkos(recvnum[iswap][i],firstrecv[iswap][i],k_buf_send); + DeviceType().fence(); + MPI_Send(k_buf_send.view().data(),n,MPI_DOUBLE,recvproc[iswap][i],0,world); + } + } + if (sendself[iswap]) { + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,nsend,Kokkos::ALL); + atomKK->avecKK->pack_reverse_kokkos(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],k_buf_send); + DeviceType().fence(); + atomKK->avecKK->unpack_reverse_kokkos(sendnum[iswap][nsend],k_sendlist_small,k_buf_send); + DeviceType().fence(); + } + if (sendother[iswap]) { + for (i = 0; i < nsend; i++) { + MPI_Waitany(nsend,requests,&irecv,MPI_STATUS_IGNORE); + auto k_sendlist_small = Kokkos::subview(k_sendlist,iswap,irecv,Kokkos::ALL); + auto k_buf_recv_offset = Kokkos::subview(k_buf_recv,std::pair(reverse_recv_offset[iswap][irecv],(int)k_buf_recv.extent(0)),Kokkos::ALL); + atomKK->avecKK->unpack_reverse_kokkos(sendnum[iswap][irecv],k_sendlist_small, + k_buf_recv_offset); + DeviceType().fence(); + } + } + } + } } /* ---------------------------------------------------------------------- @@ -108,6 +412,7 @@ void CommTiledKokkos::borders() atomKK->sync(Host,ALL_MASK); CommTiled::borders(); atomKK->modified(Host,ALL_MASK); + k_sendlist.modify_host(); } /* ---------------------------------------------------------------------- @@ -130,6 +435,26 @@ void CommTiledKokkos::reverse_comm(Pair *pair) CommTiled::reverse_comm(pair); } +/* ---------------------------------------------------------------------- + forward communication invoked by a Bond + nsize used only to set recv buffer limit +------------------------------------------------------------------------- */ + +void CommTiledKokkos::forward_comm(Bond *bond) +{ + CommTiled::forward_comm(bond); +} + +/* ---------------------------------------------------------------------- + reverse communication invoked by a Bond + nsize used only to set recv buffer limit +------------------------------------------------------------------------- */ + +void CommTiledKokkos::reverse_comm(Bond *bond) +{ + CommTiled::reverse_comm(bond); +} + /* ---------------------------------------------------------------------- forward communication invoked by a Fix size/nsize used only to set recv buffer limit @@ -218,3 +543,141 @@ void CommTiledKokkos::forward_comm_array(int nsize, double **array) { CommTiled::forward_comm_array(nsize,array); } + +/* ---------------------------------------------------------------------- + realloc the size of the send buffer as needed with BUFFACTOR and bufextra + if flag = 1, realloc + if flag = 0, don't need to realloc with copy, just free/malloc +------------------------------------------------------------------------- */ + +void CommTiledKokkos::grow_send(int n, int flag) +{ + grow_send_kokkos(n,flag,Host); +} + +/* ---------------------------------------------------------------------- + free/malloc the size of the recv buffer as needed with BUFFACTOR +------------------------------------------------------------------------- */ + +void CommTiledKokkos::grow_recv(int n, int flag) +{ + grow_recv_kokkos(n,flag,Host); +} + +/* ---------------------------------------------------------------------- + realloc the size of the send buffer as needed with BUFFACTOR & BUFEXTRA + if flag = 1, realloc + if flag = 0, don't need to realloc with copy, just free/malloc +------------------------------------------------------------------------- */ + +void CommTiledKokkos::grow_send_kokkos(int n, int flag, ExecutionSpace space) +{ + + maxsend = static_cast (BUFFACTOR * n); + int maxsend_border = (maxsend+BUFEXTRA)/atomKK->avecKK->size_border; + if (flag) { + if (space == Device) + k_buf_send.modify(); + else + k_buf_send.modify(); + + if (ghost_velocity) + k_buf_send.resize(maxsend_border, + atomKK->avecKK->size_border + atomKK->avecKK->size_velocity); + else + k_buf_send.resize(maxsend_border,atomKK->avecKK->size_border); + buf_send = k_buf_send.view().data(); + } else { + if (ghost_velocity) + MemoryKokkos::realloc_kokkos(k_buf_send,"comm:k_buf_send",maxsend_border, + atomKK->avecKK->size_border + atomKK->avecKK->size_velocity); + else + MemoryKokkos::realloc_kokkos(k_buf_send,"comm:k_buf_send",maxsend_border, + atomKK->avecKK->size_border); + buf_send = k_buf_send.view().data(); + } +} + +/* ---------------------------------------------------------------------- + free/malloc the size of the recv buffer as needed with BUFFACTOR +------------------------------------------------------------------------- */ + +void CommTiledKokkos::grow_recv_kokkos(int n, int flag, ExecutionSpace /*space*/) +{ + if (flag) maxrecv = n; + else maxrecv = static_cast (BUFFACTOR * n); + + int maxrecv_border = (maxrecv+BUFEXTRA)/atomKK->avecKK->size_border; + + MemoryKokkos::realloc_kokkos(k_buf_recv,"comm:k_buf_recv",maxrecv_border, + atomKK->avecKK->size_border); + buf_recv = k_buf_recv.view().data(); +} + +/* ---------------------------------------------------------------------- + realloc the size of the iswap sendlist as needed with BUFFACTOR +------------------------------------------------------------------------- */ + +void CommTiledKokkos::grow_list(int iswap, int iwhich, int n) +{ + int size = static_cast (BUFFACTOR * n); + + k_sendlist.sync(); + k_sendlist.modify(); + + if (size > (int)k_sendlist.extent(2)) { + memoryKK->grow_kokkos(k_sendlist,sendlist,maxswap,maxsend,size,"comm:sendlist"); + + for (int i = 0; i < maxswap; i++) + maxsendlist[iswap][iwhich] = size; + } +} + +/* ---------------------------------------------------------------------- + grow info for swap I, to allow for N procs to communicate with + ditto for complementary recv for swap I+1 or I-1, as invoked by caller +------------------------------------------------------------------------- */ + +void CommTiledKokkos::grow_swap_send(int i, int n, int /*nold*/) +{ + delete [] sendproc[i]; + sendproc[i] = new int[n]; + delete [] sendnum[i]; + sendnum[i] = new int[n]; + + delete [] size_reverse_recv[i]; + size_reverse_recv[i] = new int[n]; + delete [] reverse_recv_offset[i]; + reverse_recv_offset[i] = new int[n]; + + delete [] pbc_flag[i]; + pbc_flag[i] = new int[n]; + memory->destroy(pbc[i]); + memory->create(pbc[i],n,6,"comm:pbc_flag"); + memory->destroy(sendbox[i]); + memory->create(sendbox[i],n,6,"comm:sendbox"); + grow_swap_send_multi(i,n); + memory->destroy(sendbox_multiold[i]); + memory->create(sendbox_multiold[i],n,atom->ntypes+1,6,"comm:sendbox_multiold"); + + delete [] maxsendlist[i]; + maxsendlist[i] = new int[n]; + + for (int j = 0; j < n; j++) + maxsendlist[i][j] = BUFMIN; + + if (sendlist && !k_sendlist.d_view.data()) { + for (int ii = 0; ii < maxswap; ii++) { + if (sendlist[ii]) { + for (int jj = 0; jj < nprocmax[ii]; jj++) + memory->destroy(sendlist[ii][jj]); + delete [] sendlist[ii]; + } + } + delete [] sendlist; + } else { + memoryKK->destroy_kokkos(k_sendlist,sendlist); + } + + memoryKK->create_kokkos(k_sendlist,sendlist,maxswap,n,BUFMIN,"comm:sendlist"); +} diff --git a/src/KOKKOS/comm_tiled_kokkos.h b/src/KOKKOS/comm_tiled_kokkos.h index c80436b454..9033714796 100644 --- a/src/KOKKOS/comm_tiled_kokkos.h +++ b/src/KOKKOS/comm_tiled_kokkos.h @@ -25,28 +25,59 @@ class CommTiledKokkos : public CommTiled { CommTiledKokkos(class LAMMPS *); CommTiledKokkos(class LAMMPS *, class Comm *); + ~CommTiledKokkos() override; + + bool exchange_comm_classic; + bool forward_comm_classic; + bool forward_pair_comm_classic; + bool reverse_pair_comm_classic; + bool forward_fix_comm_classic; + bool reverse_comm_classic; + bool exchange_comm_on_host; + bool forward_comm_on_host; + bool reverse_comm_on_host; + using CommTiled::forward_comm; using CommTiled::reverse_comm; + + void init() override; void forward_comm(int dummy = 0) override; // forward comm of atom coords void reverse_comm() override; // reverse comm of forces void exchange() override; // move atoms to new procs void borders() override; // setup list of atoms to comm - void forward_comm(class Pair *) override; // forward comm from a Pair - void reverse_comm(class Pair *) override; // reverse comm from a Pair - void forward_comm(class Fix *, int size=0) override; - // forward comm from a Fix - void reverse_comm(class Fix *, int size=0) override; - // reverse comm from a Fix - void reverse_comm_variable(class Fix *) override; - // variable size reverse comm from a Fix - void forward_comm(class Compute *) override; // forward from a Compute - void reverse_comm(class Compute *) override; // reverse from a Compute - void forward_comm(class Dump *) override; // forward comm from a Dump - void reverse_comm(class Dump *) override; // reverse comm from a Dump + void forward_comm(class Pair *) override; // forward comm from a Pair + void reverse_comm(class Pair *) override; // reverse comm from a Pair + void forward_comm(class Bond *) override; // forward comm from a Bond + void reverse_comm(class Bond *) override; // reverse comm from a Bond + void forward_comm(class Fix *, int size = 0) override; // forward comm from a Fix + void reverse_comm(class Fix *, int size = 0) override; // reverse comm from a Fix + void reverse_comm_variable(class Fix *) override; // variable size reverse comm from a Fix + void forward_comm(class Compute *) override; // forward from a Compute + void reverse_comm(class Compute *) override; // reverse from a Compute + void forward_comm(class Dump *) override; // forward comm from a Dump + void reverse_comm(class Dump *) override; // reverse comm from a Dump void forward_comm_array(int, double **) override; // forward comm of array -}; -} -#endif + template void forward_comm_device(); + template void reverse_comm_device(); + + protected: + + DAT::tdual_int_3d k_sendlist; + //DAT::tdual_int_scalar k_total_send; + DAT::tdual_xfloat_2d k_buf_send,k_buf_recv; + //DAT::tdual_int_scalar k_count; + + void grow_send(int, int) override; + void grow_recv(int, int flag = 0) override; + void grow_send_kokkos(int, int, ExecutionSpace space = Host); + void grow_recv_kokkos(int, int, ExecutionSpace space = Host); + void grow_list(int, int, int) override; + void grow_swap_send(int, int, int) override; // grow swap arrays for send and recv +}; + +} // namespace LAMMPS_NS + +#endif diff --git a/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp b/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp index cc3df5d78d..308df20c0e 100644 --- a/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp +++ b/src/KOKKOS/fix_acks2_reaxff_kokkos.cpp @@ -534,7 +534,7 @@ void FixACKS2ReaxFFKokkos::deallocate_array() { memoryKK->destroy_kokkos(k_s,s); memoryKK->destroy_kokkos(k_chi_field,chi_field); - memoryKK->destroy_kokkos(X_diag); + memoryKK->destroy_kokkos(k_X_diag,X_diag); memoryKK->destroy_kokkos(k_d,d); memoryKK->destroy_kokkos(k_q_hat,q_hat); memoryKK->destroy_kokkos(k_y,y); diff --git a/src/KOKKOS/fix_acks2_reaxff_kokkos.h b/src/KOKKOS/fix_acks2_reaxff_kokkos.h index c27719c364..cb16b4cd24 100644 --- a/src/KOKKOS/fix_acks2_reaxff_kokkos.h +++ b/src/KOKKOS/fix_acks2_reaxff_kokkos.h @@ -246,9 +246,8 @@ class FixACKS2ReaxFFKokkos : public FixACKS2ReaxFF, public KokkosBase { int count, isuccess; double alpha, beta, omega, cutsq; - int iswap; int first; - typename AT::t_int_2d d_sendlist; + typename AT::t_int_1d d_sendlist; typename AT::t_xfloat_1d_um v_buf; void grow_arrays(int) override; diff --git a/src/KOKKOS/fix_langevin_kokkos.h b/src/KOKKOS/fix_langevin_kokkos.h index 05c5612313..fc25a0a748 100644 --- a/src/KOKKOS/fix_langevin_kokkos.h +++ b/src/KOKKOS/fix_langevin_kokkos.h @@ -102,8 +102,6 @@ namespace LAMMPS_NS { void end_of_step_rmass_item(int) const; private: - class CommKokkos *commKK; - typename ArrayTypes::t_float_1d rmass; typename ArrayTypes::t_float_1d mass; typename ArrayTypes::tdual_double_2d k_franprev; diff --git a/src/KOKKOS/fix_qeq_reaxff_kokkos.cpp b/src/KOKKOS/fix_qeq_reaxff_kokkos.cpp index f5b805844f..deb41944bc 100644 --- a/src/KOKKOS/fix_qeq_reaxff_kokkos.cpp +++ b/src/KOKKOS/fix_qeq_reaxff_kokkos.cpp @@ -1115,12 +1115,11 @@ void FixQEqReaxFFKokkos::operator()(TagQEqCalculateQ, const int &ii) /* ---------------------------------------------------------------------- */ template -int FixQEqReaxFFKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d k_sendlist, - int iswap_in, DAT::tdual_xfloat_1d &k_buf, +int FixQEqReaxFFKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_1d &k_buf, int /*pbc_flag*/, int * /*pbc*/) { d_sendlist = k_sendlist.view(); - iswap = iswap_in; d_buf = k_buf.view(); Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); if (pack_flag == 3) return n; @@ -1132,7 +1131,7 @@ int FixQEqReaxFFKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_i template KOKKOS_INLINE_FUNCTION void FixQEqReaxFFKokkos::operator()(TagQEqPackForwardComm, const int &i) const { - int j = d_sendlist(iswap, i); + int j = d_sendlist(i); if (pack_flag == 1) { if (!(converged & 1)) diff --git a/src/KOKKOS/fix_qeq_reaxff_kokkos.h b/src/KOKKOS/fix_qeq_reaxff_kokkos.h index 6aa345fba6..92026b209d 100644 --- a/src/KOKKOS/fix_qeq_reaxff_kokkos.h +++ b/src/KOKKOS/fix_qeq_reaxff_kokkos.h @@ -154,7 +154,7 @@ class FixQEqReaxFFKokkos : public FixQEqReaxFF, public KokkosBase { F_FLOAT chi, eta, gamma; }; - int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, + int pack_forward_comm_kokkos(int, DAT::tdual_int_1d, DAT::tdual_xfloat_1d&, int, int *) override; void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) override; int pack_forward_comm(int, int *, double *, int, int *) override; @@ -255,9 +255,9 @@ class FixQEqReaxFFKokkos : public FixQEqReaxFF, public KokkosBase { DupScatterView dup_o; NonDupScatterView ndup_o; - int iswap,nsend; + int nsend; int first; - typename AT::t_int_2d d_sendlist; + typename AT::t_int_1d d_sendlist; typename AT::t_xfloat_1d d_buf; typename AT::t_int_1d d_copylist; typename AT::t_int_1d d_indices; diff --git a/src/KOKKOS/fix_rx_kokkos.cpp b/src/KOKKOS/fix_rx_kokkos.cpp index e07fbe119d..0d1c250b3d 100644 --- a/src/KOKKOS/fix_rx_kokkos.cpp +++ b/src/KOKKOS/fix_rx_kokkos.cpp @@ -84,9 +84,6 @@ FixRxKokkos::~FixRxKokkos() memoryKK->destroy_kokkos(k_dpdThetaLocal, dpdThetaLocal); memoryKK->destroy_kokkos(k_sumWeights, sumWeights); - memoryKK->destroy_kokkos(d_scratchSpace); - - memoryKK->destroy_kokkos(k_cutsq); } /* ---------------------------------------------------------------------- */ @@ -1462,8 +1459,8 @@ void FixRxKokkos::solve_reactions(const int /*vflag*/, const bool is this->scratchSpaceSize = (8*nspecies + 2*nreactions); if (nlocal*scratchSpaceSize > d_scratchSpace.extent(0)) { - memoryKK->destroy_kokkos (d_scratchSpace); - memoryKK->create_kokkos (d_scratchSpace, nlocal*scratchSpaceSize, "FixRxKokkos::d_scratchSpace"); + d_scratchSpace = typename AT::t_double_1d(); + d_scratchSpace = typename AT::t_double_1d("FixRxKokkos::d_scratchSpace", nlocal*scratchSpaceSize); } if (setRatesToZero) @@ -1821,8 +1818,8 @@ void FixRxKokkos::computeLocalTemperature() const int ntypes = atom->ntypes; if (ntypes+1 > (int) k_cutsq.extent(0)) { - memoryKK->destroy_kokkos (k_cutsq); - memoryKK->create_kokkos (k_cutsq, ntypes+1, ntypes+1, "FixRxKokkos::k_cutsq"); + k_cutsq = typename AT::tdual_ffloat_2d(); + k_cutsq = typename AT::tdual_ffloat_2d("FixRxKokkos::k_cutsq", ntypes+1, ntypes+1); d_cutsq = k_cutsq.template view(); } @@ -1842,7 +1839,7 @@ void FixRxKokkos::computeLocalTemperature() if (sumWeightsCt > (int)k_sumWeights.template view().extent(0)) { memoryKK->destroy_kokkos(k_sumWeights, sumWeights); - memoryKK->create_kokkos (k_sumWeights, sumWeightsCt, "FixRxKokkos::sumWeights"); + memoryKK->create_kokkos(k_sumWeights, sumWeights, sumWeightsCt, "FixRxKokkos::sumWeights"); d_sumWeights = k_sumWeights.template view(); h_sumWeights = k_sumWeights.h_view; } diff --git a/src/KOKKOS/fix_shake_kokkos.cpp b/src/KOKKOS/fix_shake_kokkos.cpp index a4c66f6069..b25e2dad59 100644 --- a/src/KOKKOS/fix_shake_kokkos.cpp +++ b/src/KOKKOS/fix_shake_kokkos.cpp @@ -1799,12 +1799,11 @@ int FixShakeKokkos::unpack_exchange(int nlocal, double *buf) /* ---------------------------------------------------------------------- */ template -int FixShakeKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d k_sendlist, - int iswap_in, DAT::tdual_xfloat_1d &k_buf, - int pbc_flag, int* pbc) +int FixShakeKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_1d &k_buf, + int pbc_flag, int* pbc) { d_sendlist = k_sendlist.view(); - iswap = iswap_in; d_buf = k_buf.view(); if (domain->triclinic == 0) { @@ -1828,7 +1827,7 @@ template template KOKKOS_INLINE_FUNCTION void FixShakeKokkos::operator()(TagFixShakePackForwardComm, const int &i) const { - const int j = d_sendlist(iswap, i); + const int j = d_sendlist(i); if (PBC_FLAG == 0) { d_buf[3*i] = d_xshake(j,0); diff --git a/src/KOKKOS/fix_shake_kokkos.h b/src/KOKKOS/fix_shake_kokkos.h index 19f3a2343d..31a6c340be 100644 --- a/src/KOKKOS/fix_shake_kokkos.h +++ b/src/KOKKOS/fix_shake_kokkos.h @@ -66,7 +66,7 @@ class FixShakeKokkos : public FixShake, public KokkosBase { int pack_exchange(int, double *) override; int unpack_exchange(int, double *) override; - int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, + int pack_forward_comm_kokkos(int, DAT::tdual_int_1d, DAT::tdual_xfloat_1d&, int, int *) override; void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) override; int pack_forward_comm(int, int *, double *, int, int *) override; @@ -211,9 +211,9 @@ class FixShakeKokkos : public FixShake, public KokkosBase { KOKKOS_INLINE_FUNCTION void v_tally(EV_FLOAT&, int, int *, double, double *) const; - int iswap,first,nsend; + int first,nsend; - typename AT::t_int_2d d_sendlist; + typename AT::t_int_1d d_sendlist; typename AT::t_xfloat_1d_um d_buf; typename AT::t_int_1d d_exchange_sendlist; diff --git a/src/KOKKOS/fix_wall_lj93_kokkos.cpp b/src/KOKKOS/fix_wall_lj93_kokkos.cpp index 6890a16c18..93bcc9abc9 100644 --- a/src/KOKKOS/fix_wall_lj93_kokkos.cpp +++ b/src/KOKKOS/fix_wall_lj93_kokkos.cpp @@ -51,8 +51,6 @@ void FixWallLJ93Kokkos::wall_particle(int m_in, int which, double co x = atomKK->k_x.view(); f = atomKK->k_f.view(); mask = atomKK->k_mask.view(); - DAT::tdual_int_scalar k_oneflag = DAT::tdual_int_scalar("fix:oneflag"); - d_oneflag = k_oneflag.view(); int nlocal = atom->nlocal; @@ -66,10 +64,6 @@ void FixWallLJ93Kokkos::wall_particle(int m_in, int which, double co copymode = 0; atomKK->modified(execution_space, F_MASK); - - k_oneflag.template modify(); - k_oneflag.template sync(); - if (k_oneflag.h_view()) error->one(FLERR,"Particle on or inside fix wall surface"); } template @@ -80,10 +74,8 @@ void FixWallLJ93Kokkos::wall_particle_item(int i, value_type ewall) if (side < 0) delta = x(i,dim) - coord; else delta = coord - x(i,dim); if (delta >= cutoff[m]) return; - if (delta <= 0.0) { - d_oneflag() = 1; - return; - } + if (delta <= 0.0) + Kokkos::abort("Particle on or inside fix wall surface"); double rinv = 1.0/delta; double r2inv = rinv*rinv; double r4inv = r2inv*r2inv; diff --git a/src/KOKKOS/fix_wall_lj93_kokkos.h b/src/KOKKOS/fix_wall_lj93_kokkos.h index 2bc78f3781..720e586f5d 100644 --- a/src/KOKKOS/fix_wall_lj93_kokkos.h +++ b/src/KOKKOS/fix_wall_lj93_kokkos.h @@ -50,7 +50,6 @@ class FixWallLJ93Kokkos : public FixWallLJ93 { typename AT::t_x_array x; typename AT::t_f_array f; typename AT::t_int_1d mask; - typename AT::t_int_scalar d_oneflag; }; template diff --git a/src/KOKKOS/kokkos_base.h b/src/KOKKOS/kokkos_base.h index 24fcc47579..22ed1687a9 100644 --- a/src/KOKKOS/kokkos_base.h +++ b/src/KOKKOS/kokkos_base.h @@ -26,18 +26,18 @@ class KokkosBase { KokkosBase() {} // Pair - virtual int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, - int, DAT::tdual_xfloat_1d &, + virtual int pack_forward_comm_kokkos(int, DAT::tdual_int_1d, + DAT::tdual_xfloat_1d &, int, int *) {return 0;}; virtual void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d &) {} virtual int pack_reverse_comm_kokkos(int, int, DAT::tdual_xfloat_1d &) {return 0;}; - virtual void unpack_reverse_comm_kokkos(int, DAT::tdual_int_2d, - int, DAT::tdual_xfloat_1d &) {} + virtual void unpack_reverse_comm_kokkos(int, DAT::tdual_int_1d, + DAT::tdual_xfloat_1d &) {} // Fix - virtual int pack_forward_comm_fix_kokkos(int, DAT::tdual_int_2d, - int, DAT::tdual_xfloat_1d &, + virtual int pack_forward_comm_fix_kokkos(int, DAT::tdual_int_1d, + DAT::tdual_xfloat_1d &, int, int *) {return 0;}; virtual void unpack_forward_comm_fix_kokkos(int, int, DAT::tdual_xfloat_1d &) {} diff --git a/src/KOKKOS/kokkos_type.h b/src/KOKKOS/kokkos_type.h index 1009e43196..cc4e00819f 100644 --- a/src/KOKKOS/kokkos_type.h +++ b/src/KOKKOS/kokkos_type.h @@ -689,6 +689,14 @@ typedef tdual_int_2d_dl::t_dev_um t_int_2d_um_dl; typedef tdual_int_2d_dl::t_dev_const_um t_int_2d_const_um_dl; typedef tdual_int_2d_dl::t_dev_const_randomread t_int_2d_randomread_dl; +typedef Kokkos:: + DualView tdual_int_3d; +typedef tdual_int_3d::t_dev t_int_3d; +typedef tdual_int_3d::t_dev_const t_int_3d_const; +typedef tdual_int_3d::t_dev_um t_int_3d_um; +typedef tdual_int_3d::t_dev_const_um t_int_3d_const_um; +typedef tdual_int_3d::t_dev_const_randomread t_int_3d_randomread; + typedef Kokkos:: DualView tdual_tagint_1d; @@ -1006,6 +1014,13 @@ typedef tdual_int_2d_dl::t_host_um t_int_2d_um_dl; typedef tdual_int_2d_dl::t_host_const_um t_int_2d_const_um_dl; typedef tdual_int_2d_dl::t_host_const_randomread t_int_2d_randomread_dl; +typedef Kokkos::DualView tdual_int_3d; +typedef tdual_int_3d::t_host t_int_3d; +typedef tdual_int_3d::t_host_const t_int_3d_const; +typedef tdual_int_3d::t_host_um t_int_3d_um; +typedef tdual_int_3d::t_host_const_um t_int_3d_const_um; +typedef tdual_int_3d::t_host_const_randomread t_int_3d_randomread; + typedef Kokkos::DualView tdual_tagint_1d; typedef tdual_tagint_1d::t_host t_tagint_1d; typedef tdual_tagint_1d::t_host_const t_tagint_1d_const; diff --git a/src/KOKKOS/memory_kokkos.h b/src/KOKKOS/memory_kokkos.h index 9d894a344a..0c7555875e 100644 --- a/src/KOKKOS/memory_kokkos.h +++ b/src/KOKKOS/memory_kokkos.h @@ -65,8 +65,7 @@ template } /* ---------------------------------------------------------------------- - grow or shrink 1st dim of a 1d array - last dim must stay the same + grow or shrink a 1d array ------------------------------------------------------------------------- */ template @@ -80,6 +79,10 @@ TYPE grow_kokkos(TYPE &data, typename TYPE::value_type *&array, return data; } +/* ---------------------------------------------------------------------- + destroy a 1d array +------------------------------------------------------------------------- */ + template void destroy_kokkos(TYPE data, typename TYPE::value_type* &array) { @@ -92,71 +95,6 @@ void destroy_kokkos(TYPE data, typename TYPE::value_type* &array) create a 2d array ------------------------------------------------------------------------- */ -template -TYPE destroy_kokkos(TYPE &data) -{ - /*if (data.data()!=nullptr) - free(data.data());*/ - data = TYPE(); - return data; -} - -template -TYPE create_kokkos(TYPE &data, int n1, const char *name) -{ - /*typename TYPE::non_const_value_type* ptr = (typename TYPE::non_const_value_type*) - malloc(n1*sizeof(typename TYPE::non_const_value_type)*4);*/ - data = TYPE(std::string(name),n1); - return data; -} - -template -TYPE create_kokkos(TYPE &data, int n1, int n2, const char *name) -{ - /*typename TYPE::non_const_value_type* ptr = (typename TYPE::non_const_value_type*) - malloc(n1*n2*sizeof(typename TYPE::non_const_value_type)*4);*/ - data = TYPE(std::string(name),n1,n2); - return data; -} - -template -TYPE create_kokkos(TYPE &data, int n1, int n2, int n3 ,const char *name) -{ - /*typename TYPE::non_const_value_type* ptr = (typename TYPE::non_const_value_type*) - malloc(n1*n2*n3*sizeof(typename TYPE::non_const_value_type)*4);*/ - data = TYPE(std::string(name),n1,n2,n3); - return data; -} - -template -TYPE create_kokkos(TYPE &data, int n1, int n2, int n3, int n4 ,const char *name) -{ - /*typename TYPE::non_const_value_type* ptr = (typename TYPE::non_const_value_type*) - malloc(n1*n2*n3*n4*sizeof(typename TYPE::non_const_value_type)*4);*/ - data = TYPE(std::string(name),n1,n2,n3,n4); - return data; -} - -template -TYPE create_kokkos(TYPE &data, int n1, int n2, int n3, int n4, int n5 ,const char *name) -{ - /*typename TYPE::non_const_value_type* ptr = (typename TYPE::non_const_value_type*) - malloc(n1*n2*n3*n4*n5*sizeof(typename TYPE::non_const_value_type)*4);*/ - data = TYPE(std::string(name),n1,n2,n3,n4,n5); - return data; -} - -template -TYPE create_kokkos(TYPE &data, int n1, int n2, int n3, int n4, int n5 , int n6 ,const char *name) -{ - /*typename TYPE::non_const_value_type* ptr = (typename TYPE::non_const_value_type*) - malloc(n1*n2*n3*n4*n5*n6*sizeof(typename TYPE::non_const_value_type)*4);*/ - data = TYPE(std::string(name) ,n1,n2,n3,n4,n5,n6); - return data; -} - - - template TYPE create_kokkos(TYPE &data, HTYPE &h_data, int n1, int n2, const char *name) @@ -202,20 +140,87 @@ template return data; } -template - TYPE create_kokkos(TYPE &data, HTYPE &h_data, int n1, int n2, int n3, - const char *name) +template +TYPE create_kokkos(TYPE &data, typename TYPE::value_type **&array, + int n1, const char *name) { - data = TYPE(std::string(name),n1,n2,n3); - h_data = Kokkos::create_mirror_view(data); + data = TYPE(std::string(name),n1); + bigint nbytes = ((bigint) sizeof(typename TYPE::value_type *)) * n1; + array = (typename TYPE::value_type **) smalloc(nbytes,name); + + for (int i = 0; i < n1; i++) + if (data.h_view.extent(1) == 0) + array[i] = nullptr; + else + array[i] = &data.h_view(i,0); + return data; } +/* ---------------------------------------------------------------------- + grow or shrink a 2d array +------------------------------------------------------------------------- */ + +template +TYPE grow_kokkos(TYPE &data, typename TYPE::value_type **&array, + int n1, int n2, const char *name) +{ + if (array == nullptr) return create_kokkos(data,array,n1,n2,name); + data.resize(n1,n2); + bigint nbytes = ((bigint) sizeof(typename TYPE::value_type *)) * n1; + array = (typename TYPE::value_type**) srealloc(array,nbytes,name); + + for (int i = 0; i < n1; i++) + if (n2 == 0) + array[i] = nullptr; + else + array[i] = &data.h_view(i,0); + + return data; +} + +template +TYPE grow_kokkos(TYPE &data, typename TYPE::value_type **&array, + int n1, const char *name) +{ + if (array == nullptr) return create_kokkos(data,array,n1,name); + + data.resize(n1); + + bigint nbytes = ((bigint) sizeof(typename TYPE::value_type *)) * n1; + array = (typename TYPE::value_type **) srealloc(array,nbytes,name); + + for (int i = 0; i < n1; i++) + if (data.h_view.extent(1) == 0) + array[i] = nullptr; + else + array[i] = &data.h_view(i,0); + + return data; +} + +/* ---------------------------------------------------------------------- + destroy a 2d array +------------------------------------------------------------------------- */ + +template +void destroy_kokkos(TYPE data, typename TYPE::value_type** &array) +{ + if (array == nullptr) return; + data = TYPE(); + sfree(array); + array = nullptr; +} + +/* ---------------------------------------------------------------------- + create a 3d array +------------------------------------------------------------------------- */ + template TYPE create_kokkos(TYPE &data, typename TYPE::value_type ***&array, int n1, int n2, int n3, const char *name) { - data = TYPE(std::string(name),n1,n2); + data = TYPE(std::string(name),n1,n2,n3); bigint nbytes = ((bigint) sizeof(typename TYPE::value_type **)) * n1; array = (typename TYPE::value_type ***) smalloc(nbytes,name); @@ -263,79 +268,46 @@ template return data; } +template + TYPE create_kokkos(TYPE &data, HTYPE &h_data, int n1, int n2, int n3, + const char *name) +{ + data = TYPE(std::string(name),n1,n2,n3); + h_data = Kokkos::create_mirror_view(data); + return data; +} + + /* ---------------------------------------------------------------------- - grow or shrink 1st dim of a 2d array - last dim must stay the same + grow or shrink a 3d array ------------------------------------------------------------------------- */ template -TYPE grow_kokkos(TYPE &data, typename TYPE::value_type **&array, - int n1, int n2, const char *name) +TYPE grow_kokkos(TYPE &data, typename TYPE::value_type ***&array, + int n1, int n2, int n3, const char *name) { - if (array == nullptr) return create_kokkos(data,array,n1,n2,name); - data.resize(n1,n2); - bigint nbytes = ((bigint) sizeof(typename TYPE::value_type *)) * n1; - array = (typename TYPE::value_type**) srealloc(array,nbytes,name); + if (array == nullptr) return create_kokkos(data,array,n1,n2,n3,name); + data.resize(n1,n2,n3); + bigint nbytes = ((bigint) sizeof(typename TYPE::value_type **)) * n1; + array = (typename TYPE::value_type ***) smalloc(nbytes,name); - for (int i = 0; i < n1; i++) - if (n2 == 0) + for (int i = 0; i < n1; i++) { + if (n2 == 0) { array[i] = nullptr; - else - array[i] = &data.h_view(i,0); - + } else { + nbytes = ((bigint) sizeof(typename TYPE::value_type *)) * n2; + array[i] = (typename TYPE::value_type **) smalloc(nbytes,name); + for (int j = 0; j < n2; j++) { + if (n3 == 0) + array[i][j] = nullptr; + else + array[i][j] = &data.h_view(i,j,0); + } + } + } return data; } -template -TYPE create_kokkos(TYPE &data, typename TYPE::value_type **&array, - int n1, const char *name) -{ - data = TYPE(std::string(name),n1); - bigint nbytes = ((bigint) sizeof(typename TYPE::value_type *)) * n1; - array = (typename TYPE::value_type **) smalloc(nbytes,name); - - for (int i = 0; i < n1; i++) - if (data.h_view.extent(1) == 0) - array[i] = nullptr; - else - array[i] = &data.h_view(i,0); - - return data; -} - -template -TYPE grow_kokkos(TYPE &data, typename TYPE::value_type **&array, - int n1, const char *name) -{ - if (array == nullptr) return create_kokkos(data,array,n1,name); - - data.resize(n1); - - bigint nbytes = ((bigint) sizeof(typename TYPE::value_type *)) * n1; - array = (typename TYPE::value_type **) srealloc(array,nbytes,name); - - for (int i = 0; i < n1; i++) - if (data.h_view.extent(1) == 0) - array[i] = nullptr; - else - array[i] = &data.h_view(i,0); - - return data; -} - -/* ---------------------------------------------------------------------- - destroy a 2d array -------------------------------------------------------------------------- */ - -template -void destroy_kokkos(TYPE data, typename TYPE::value_type** &array) -{ - if (array == nullptr) return; - data = TYPE(); - sfree(array); - array = nullptr; -} - /* ---------------------------------------------------------------------- destroy a 3d array ------------------------------------------------------------------------- */ @@ -374,6 +346,65 @@ static double memory_usage(TYPE &data) return data.span() * sizeof(typename TYPE::value_type); } +/* ---------------------------------------------------------------------- + legacy functions +------------------------------------------------------------------------- */ + +template +TYPE destroy_kokkos(TYPE &data) +{ + data = TYPE(); + return data; +} + +template +TYPE create_kokkos(TYPE &data, int n1, const char *name) +{ + data = TYPE(); + data = TYPE(std::string(name),n1); + return data; +} + +template +TYPE create_kokkos(TYPE &data, int n1, int n2, const char *name) +{ + data = TYPE(); + data = TYPE(std::string(name),n1,n2); + return data; +} + +template +TYPE create_kokkos(TYPE &data, int n1, int n2, int n3 ,const char *name) +{ + data = TYPE(); + data = TYPE(std::string(name),n1,n2,n3); + return data; +} + +template +TYPE create_kokkos(TYPE &data, int n1, int n2, int n3, int n4 ,const char *name) +{ + data = TYPE(); + data = TYPE(std::string(name),n1,n2,n3,n4); + return data; +} + +template +TYPE create_kokkos(TYPE &data, int n1, int n2, int n3, int n4, int n5 ,const char *name) +{ + data = TYPE(); + data = TYPE(std::string(name),n1,n2,n3,n4,n5); + return data; +} + +template +TYPE create_kokkos(TYPE &data, int n1, int n2, int n3, int n4, int n5 , int n6 ,const char *name) +{ + data = TYPE(); + data = TYPE(std::string(name) ,n1,n2,n3,n4,n5,n6); + return data; +} + }; } diff --git a/src/KOKKOS/mliap_data_kokkos.cpp b/src/KOKKOS/mliap_data_kokkos.cpp index 8ff266c820..fd5a852114 100644 --- a/src/KOKKOS/mliap_data_kokkos.cpp +++ b/src/KOKKOS/mliap_data_kokkos.cpp @@ -57,7 +57,6 @@ MLIAPDataKokkos::~MLIAPDataKokkos() { memoryKK->destroy_kokkos(k_pair_i,pair_i); memoryKK->destroy_kokkos(k_jelems,jelems); memoryKK->destroy_kokkos(k_elems,elems); - memoryKK->destroy_kokkos(k_ij); memoryKK->destroy_kokkos(k_rij,rij); memoryKK->destroy_kokkos(k_graddesc,graddesc); } @@ -211,7 +210,6 @@ void MLIAPDataKokkos::grow_neigharrays() { memoryKK->create_kokkos(k_iatoms, iatoms, natomneigh_max, "mliap_data:iatoms"); memoryKK->destroy_kokkos(k_ielems,ielems); memoryKK->create_kokkos(k_ielems, ielems, natomneigh_max, "mliap_data:ielems"); - memoryKK->destroy_kokkos(k_ij); memoryKK->create_kokkos(k_ij, natomneigh_max, "mliap_data:ij"); memoryKK->destroy_kokkos(k_numneighs,numneighs); memoryKK->create_kokkos(k_numneighs, numneighs, natomneigh_max, "mliap_data:numneighs"); diff --git a/src/KOKKOS/mliap_descriptor_kokkos.h b/src/KOKKOS/mliap_descriptor_kokkos.h index 075f0e9fed..d4ab72ff96 100644 --- a/src/KOKKOS/mliap_descriptor_kokkos.h +++ b/src/KOKKOS/mliap_descriptor_kokkos.h @@ -29,13 +29,11 @@ template class MLIAPDescriptorKokkos : virtual protected Poin MLIAPDescriptorKokkos(LAMMPS *lmp, MLIAPDescriptor *descriptor_in) : Pointers(lmp), descriptor(descriptor_in) { - memoryKK->destroy_kokkos(k_wjelem); } void init_data() { int num_elems = descriptor->nelements; - memoryKK->destroy_kokkos(k_wjelem); memoryKK->create_kokkos(k_wjelem, num_elems, "MLIAPDescriptorKokkos::k_wjelem"); for (int i = 0; i < num_elems; ++i) k_wjelem.h_view(i) = descriptor->wjelem[i]; k_wjelem.modify(); @@ -44,7 +42,6 @@ template class MLIAPDescriptorKokkos : virtual protected Poin virtual ~MLIAPDescriptorKokkos() { - memoryKK->destroy_kokkos(k_wjelem); } MLIAPDescriptor *descriptor; diff --git a/src/KOKKOS/mliap_model_kokkos.h b/src/KOKKOS/mliap_model_kokkos.h index 72077f5988..4840798cc1 100644 --- a/src/KOKKOS/mliap_model_kokkos.h +++ b/src/KOKKOS/mliap_model_kokkos.h @@ -29,14 +29,12 @@ template class MLIAPModelKokkos : protected Pointers { MLIAPModelKokkos(LAMMPS *lmp, MLIAPModel *model_in) : Pointers(lmp), model(model_in) {} virtual ~MLIAPModelKokkos() { - memoryKK->destroy_kokkos(k_coeffelem); model->coeffelem = nullptr; } void set_k_coeffelem() { double **tmp = nullptr; - memoryKK->destroy_kokkos(k_coeffelem); memoryKK->create_kokkos(k_coeffelem, tmp, model->nelements, model->nparams, "MLIAPModelKokkos::coeffelem"); for (int i = 0; i < model->nelements; ++i) diff --git a/src/KOKKOS/mliap_so3_kokkos.cpp b/src/KOKKOS/mliap_so3_kokkos.cpp index 83f8deb3ee..155bee9294 100644 --- a/src/KOKKOS/mliap_so3_kokkos.cpp +++ b/src/KOKKOS/mliap_so3_kokkos.cpp @@ -59,44 +59,6 @@ MLIAP_SO3Kokkos::MLIAP_SO3Kokkos(LAMMPS *lmp, double vrcut, int vlma template MLIAP_SO3Kokkos::~MLIAP_SO3Kokkos() { - memoryKK->destroy_kokkos(m_ellpl1); - memoryKK->destroy_kokkos(m_ellm1); - memoryKK->destroy_kokkos(m_pfac); - memoryKK->destroy_kokkos(m_Ylms); - memoryKK->destroy_kokkos(m_dfac0); - memoryKK->destroy_kokkos(m_dfac1); - memoryKK->destroy_kokkos(m_dfac2); - memoryKK->destroy_kokkos(m_dfac3); - memoryKK->destroy_kokkos(m_dfac4); - memoryKK->destroy_kokkos(m_dfac5); - memoryKK->destroy_kokkos(m_w); - memoryKK->destroy_kokkos(m_g_array); - - memoryKK->destroy_kokkos(m_rootpq); - memoryKK->destroy_kokkos(m_idxu_block); - memoryKK->destroy_kokkos(m_idxylm); - - memoryKK->destroy_kokkos(m_rip_array); - memoryKK->destroy_kokkos(m_rip_darray); - - memoryKK->destroy_kokkos(m_sbes_array); - memoryKK->destroy_kokkos(m_sbes_darray); - - memoryKK->destroy_kokkos(m_plist_r); - - memoryKK->destroy_kokkos(m_ulist_r); - memoryKK->destroy_kokkos(m_ulist_i); - - memoryKK->destroy_kokkos(m_dYlm_r); - memoryKK->destroy_kokkos(m_dYlm_i); - - memoryKK->destroy_kokkos(k_dplist_r); - - memoryKK->destroy_kokkos(m_dclist); - - memoryKK->destroy_kokkos(m_clisttot_r); - memoryKK->destroy_kokkos(m_clisttot_i); - t_numneighs = int_1d(); t_jelems = int_1d(); t_wjelem = float_1d(); @@ -120,9 +82,7 @@ void MLIAP_SO3Kokkos::init() int totali; totali = m_lmax + 1; - memoryKK->destroy_kokkos(m_ellpl1); memoryKK->create_kokkos(m_ellpl1, totali, "MLIAP_SO3Kokkos:m_ellpl1"); - memoryKK->destroy_kokkos(m_ellm1); memoryKK->create_kokkos(m_ellm1, totali, "MLIAP_SO3Kokkos:m_ellm1"); alloc_init = 2.0 * totali * sizeof(double); using range=Kokkos::RangePolicy; @@ -138,9 +98,7 @@ void MLIAP_SO3Kokkos::init() m_pfac_l1 = m_lmax + 2; m_pfac_l2 = (m_lmax + 2) * (m_lmax + 2) + 1; totali = m_pfac_l1 * m_pfac_l2; - memoryKK->destroy_kokkos(m_pfac); memoryKK->create_kokkos(m_pfac, totali, "MLIAP_SO3Kokkos:m_pfac"); - memoryKK->destroy_kokkos(m_Ylms); memoryKK->create_kokkos(m_Ylms, totali, "MLIAP_SO3Kokkos:m_Ylms"); alloc_init += 2 * totali * sizeof(double); @@ -160,17 +118,11 @@ void MLIAP_SO3Kokkos::init() m_dfac_l1 = m_lmax + 1; m_dfac_l2 = m_numYlms + 1; totali = m_dfac_l1 * m_dfac_l2; - memoryKK->destroy_kokkos(m_dfac0); memoryKK->create_kokkos(m_dfac0, totali, "MLIAP_SO3Kokkos:m_dfac0"); - memoryKK->destroy_kokkos(m_dfac1); memoryKK->create_kokkos(m_dfac1, totali, "MLIAP_SO3Kokkos:m_dfac1"); - memoryKK->destroy_kokkos(m_dfac2); memoryKK->create_kokkos(m_dfac2, totali, "MLIAP_SO3Kokkos:m_dfac2"); - memoryKK->destroy_kokkos(m_dfac3); memoryKK->create_kokkos(m_dfac3, totali, "MLIAP_SO3Kokkos:m_dfac3"); - memoryKK->destroy_kokkos(m_dfac4); memoryKK->create_kokkos(m_dfac4, totali, "MLIAP_SO3Kokkos:m_dfac4"); - memoryKK->destroy_kokkos(m_dfac5); memoryKK->create_kokkos(m_dfac5, totali, "MLIAP_SO3Kokkos:m_dfac5"); alloc_init += 6.0 * totali * sizeof(double); @@ -196,12 +148,10 @@ void MLIAP_SO3Kokkos::init() }); totali = m_nmax * m_nmax; - memoryKK->destroy_kokkos(m_w); memoryKK->create_kokkos(m_w, totali, "MLIAP_SO3Kokkos:w"); alloc_init += totali * sizeof(double); totali = m_nmax * m_Nmax; - memoryKK->destroy_kokkos(m_g_array); memoryKK->create_kokkos(m_g_array, totali, "MLIAP_SO3Kokkos:g_array"); alloc_init += totali * sizeof(double); @@ -217,7 +167,6 @@ void MLIAP_SO3Kokkos::init() twolmax = 2 * (m_lmax + 1); int m_ldim = twolmax + 1; totali = m_ldim * m_ldim; - memoryKK->destroy_kokkos(m_rootpq); memoryKK->create_kokkos(m_rootpq, totali, "MLIAP_SO3Kokkos:rootpq"); alloc_init += totali * sizeof(double); @@ -228,12 +177,10 @@ void MLIAP_SO3Kokkos::init() rootpq[p * ldim + q] = sqrt(static_cast(p) / q); }); - memoryKK->destroy_kokkos(m_idxu_block); memoryKK->create_kokkos(m_idxu_block, m_ldim, "MLIAP_SO3Kokkos:idxu_bloc"); alloc_init += totali * sizeof(double); totali = square(m_lmax + 2); - memoryKK->destroy_kokkos(m_idxylm); memoryKK->create_kokkos(m_idxylm, totali, "MLIAP_SO3Kokkos:idxylm"); alloc_init += totali * sizeof(double); @@ -277,7 +224,6 @@ void MLIAP_SO3Kokkos::init_arrays(int nlocal, int ncoefs) int totali = nlocal * ncoefs; if ( nlocal > (int)m_plist_r.extent(0)) { - memoryKK->destroy_kokkos(m_plist_r); memoryKK->create_kokkos(m_plist_r, nlocal, ncoefs, "MLIAP_SO3Kokkos:m_plist_r"); alloc_arrays = totali * sizeof(double); } @@ -285,26 +231,19 @@ void MLIAP_SO3Kokkos::init_arrays(int nlocal, int ncoefs) int num_of_temp = std::min(nlocal, m_chunk_size); if ((int)m_ulist_r.extent(0) < num_of_temp ) { totali = m_idxu_count; - memoryKK->destroy_kokkos(m_ulist_r); memoryKK->create_kokkos(m_ulist_r, num_of_temp, totali, "MLIAP_SO3Kokkos:m_ulist_r"); - memoryKK->destroy_kokkos(m_ulist_i); memoryKK->create_kokkos(m_ulist_i, num_of_temp, totali, "MLIAP_SO3Kokkos:m_ulist_i"); alloc_arrays += 2.0 * totali * num_of_temp * sizeof(double); totali = m_numYlms * 3; - memoryKK->destroy_kokkos(m_dYlm_r); memoryKK->create_kokkos(m_dYlm_r, num_of_temp, m_numYlms, 3, "MLIAP_SO3Kokkos:m_dYlm_r"); - memoryKK->destroy_kokkos(m_dYlm_i); memoryKK->create_kokkos(m_dYlm_i, num_of_temp, m_numYlms, 3, "MLIAP_SO3Kokkos:m_dYlm_i"); alloc_arrays += 2.0 * m_numYlms * 3 * num_of_temp * sizeof(double); - memoryKK->destroy_kokkos(m_dclist); memoryKK->create_kokkos(m_dclist, num_of_temp, m_nmax, m_numYlms, 3, "MLIAP_SO3Kokkos:k_dclist_r"); alloc_arrays += m_nmax * m_numYlms * 3 * num_of_temp* sizeof(double); - memoryKK->destroy_kokkos(m_clisttot_r); memoryKK->create_kokkos(m_clisttot_r, num_of_temp, m_nmax, m_numYlms, "MLIAP_SO3Kokkos:m_clisttot_r"); - memoryKK->destroy_kokkos(m_clisttot_i); memoryKK->create_kokkos(m_clisttot_i, num_of_temp, m_nmax, m_numYlms, "MLIAP_SO3Kokkos:m_clisttot_i"); alloc_arrays += 2.0 * m_nmax * m_numYlms * num_of_temp * sizeof(double); m_init_arrays = 1; @@ -849,21 +788,15 @@ void MLIAP_SO3Kokkos::spectrum_dxdr(int nlocal, DAT::tdual_int_1d nu bigint totali; if ( nlocal > (int)m_clisttot_r.extent(0)){ - memoryKK->destroy_kokkos(m_clisttot_r); memoryKK->create_kokkos(m_clisttot_r, nlocal, m_nmax, m_numYlms, "MLIAP_SO3Kokkos:m_clisttot_r"); - memoryKK->destroy_kokkos(m_clisttot_i); memoryKK->create_kokkos(m_clisttot_i, nlocal, m_nmax, m_numYlms, "MLIAP_SO3Kokkos:m_clisttot_i"); int num_of_temp = std::min(nlocal, m_chunk_size); int delta=num_of_temp-m_ulist_r.extent(0); if (delta > 0){ - memoryKK->destroy_kokkos(m_ulist_r); memoryKK->create_kokkos(m_ulist_r, num_of_temp, m_idxu_count, "MLIAP_SO3Kokkos:m_ulist_r"); - memoryKK->destroy_kokkos(m_ulist_i); memoryKK->create_kokkos(m_ulist_i, num_of_temp, m_idxu_count, "MLIAP_SO3Kokkos:m_ulist_i"); alloc_arrays += 2.0 * m_idxu_count * delta * sizeof(double); - memoryKK->destroy_kokkos(m_dYlm_r); memoryKK->create_kokkos(m_dYlm_r, num_of_temp, m_numYlms, 3, "MLIAP_SO3Kokkos:m_dYlm_r"); - memoryKK->destroy_kokkos(m_dYlm_i); memoryKK->create_kokkos(m_dYlm_i, num_of_temp, m_numYlms, 3, "MLIAP_SO3Kokkos:m_dYlm_i"); alloc_arrays += 2.0 * m_numYlms * 3 * delta * sizeof(double); } @@ -871,18 +804,13 @@ void MLIAP_SO3Kokkos::spectrum_dxdr(int nlocal, DAT::tdual_int_1d nu totali = totaln * m_Nmax * (m_lmax + 1); if ( totali > (int)m_sbes_array.extent(0)) { - memoryKK->destroy_kokkos(m_sbes_array); memoryKK->create_kokkos(m_sbes_array, totali, "MLIAP_SO3Kokkos:m_sbes_array"); - memoryKK->destroy_kokkos(m_sbes_darray); memoryKK->create_kokkos(m_sbes_darray, totali, "MLIAP_SO3Kokkos:m_sbes_darray"); totali = totaln * m_nmax * (m_lmax + 1); - memoryKK->destroy_kokkos(m_rip_array); memoryKK->create_kokkos(m_rip_array, totali, "MLIAP_SO3Kokkos:m_rip_array"); - memoryKK->destroy_kokkos(m_rip_darray); memoryKK->create_kokkos(m_rip_darray, totali, "MLIAP_SO3Kokkos:m_rip_darray"); - memoryKK->destroy_kokkos(k_dplist_r); memoryKK->create_kokkos(k_dplist_r, (int)totaln, ncoefs, 3, "MLIAP_SO3Kokkos:m_dplist_r"); } diff --git a/src/KOKKOS/pair_adp_kokkos.cpp b/src/KOKKOS/pair_adp_kokkos.cpp index d02edc43ab..1297d62651 100644 --- a/src/KOKKOS/pair_adp_kokkos.cpp +++ b/src/KOKKOS/pair_adp_kokkos.cpp @@ -472,12 +472,11 @@ void PairADPKokkos::interpolate(int n, double delta, double *f, t_ho /* ---------------------------------------------------------------------- */ template -int PairADPKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d k_sendlist, - int iswap_in, DAT::tdual_xfloat_1d &buf, +int PairADPKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_1d &buf, int /*pbc_flag*/, int * /*pbc*/) { d_sendlist = k_sendlist.view(); - iswap = iswap_in; v_buf = buf.view(); Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); return n*10; @@ -486,7 +485,7 @@ int PairADPKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d template KOKKOS_INLINE_FUNCTION void PairADPKokkos::operator()(TagPairADPPackForwardComm, const int &i) const { - int j = d_sendlist(iswap, i); + int j = d_sendlist(i); v_buf[10 * i] = d_fp(j); v_buf[10 * i + 1] = d_mu(j, 0); v_buf[10 * i + 2] = d_mu(j, 1); diff --git a/src/KOKKOS/pair_adp_kokkos.h b/src/KOKKOS/pair_adp_kokkos.h index 5714bdb699..41328a567e 100644 --- a/src/KOKKOS/pair_adp_kokkos.h +++ b/src/KOKKOS/pair_adp_kokkos.h @@ -108,7 +108,7 @@ class PairADPKokkos : public PairADP, public KokkosBase const F_FLOAT &epair, const F_FLOAT &fx, const F_FLOAT &fy, const F_FLOAT &fz, const F_FLOAT &delx, const F_FLOAT &dely, const F_FLOAT &delz) const; - int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, + int pack_forward_comm_kokkos(int, DAT::tdual_int_1d, DAT::tdual_xfloat_1d&, int, int *) override; void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) override; int pack_forward_comm(int, int *, double *, int, int *) override; @@ -185,9 +185,8 @@ class PairADPKokkos : public PairADP, public KokkosBase typename AT::t_int_1d d_ilist; typename AT::t_int_1d d_numneigh; - int iswap; int first; - typename AT::t_int_2d d_sendlist; + typename AT::t_int_1d d_sendlist; typename AT::t_xfloat_1d_um v_buf; int neighflag,newton_pair; diff --git a/src/KOKKOS/pair_eam_alloy_kokkos.cpp b/src/KOKKOS/pair_eam_alloy_kokkos.cpp index 93ed9fc620..b02faced1e 100644 --- a/src/KOKKOS/pair_eam_alloy_kokkos.cpp +++ b/src/KOKKOS/pair_eam_alloy_kokkos.cpp @@ -449,12 +449,11 @@ void PairEAMAlloyKokkos::interpolate(int n, double delta, double *f, /* ---------------------------------------------------------------------- */ template -int PairEAMAlloyKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d k_sendlist, - int iswap_in, DAT::tdual_xfloat_1d &buf, +int PairEAMAlloyKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_1d &buf, int /*pbc_flag*/, int * /*pbc*/) { d_sendlist = k_sendlist.view(); - iswap = iswap_in; v_buf = buf.view(); Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); return n; @@ -463,7 +462,7 @@ int PairEAMAlloyKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_i template KOKKOS_INLINE_FUNCTION void PairEAMAlloyKokkos::operator()(TagPairEAMAlloyPackForwardComm, const int &i) const { - int j = d_sendlist(iswap, i); + int j = d_sendlist(i); v_buf[i] = d_fp[j]; } diff --git a/src/KOKKOS/pair_eam_alloy_kokkos.h b/src/KOKKOS/pair_eam_alloy_kokkos.h index 2eb40189ac..572dc1aca8 100644 --- a/src/KOKKOS/pair_eam_alloy_kokkos.h +++ b/src/KOKKOS/pair_eam_alloy_kokkos.h @@ -122,7 +122,7 @@ class PairEAMAlloyKokkos : public PairEAM, public KokkosBase { const F_FLOAT &epair, const F_FLOAT &fpair, const F_FLOAT &delx, const F_FLOAT &dely, const F_FLOAT &delz) const; - int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, + int pack_forward_comm_kokkos(int, DAT::tdual_int_1d, DAT::tdual_xfloat_1d&, int, int *) override; void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) override; int pack_forward_comm(int, int *, double *, int, int *) override; @@ -190,9 +190,8 @@ class PairEAMAlloyKokkos : public PairEAM, public KokkosBase { typename AT::t_int_1d d_ilist; typename AT::t_int_1d d_numneigh; - int iswap; int first; - typename AT::t_int_2d d_sendlist; + typename AT::t_int_1d d_sendlist; typename AT::t_xfloat_1d_um v_buf; int neighflag,newton_pair; diff --git a/src/KOKKOS/pair_eam_fs_kokkos.cpp b/src/KOKKOS/pair_eam_fs_kokkos.cpp index 5dee601302..4da146e68e 100644 --- a/src/KOKKOS/pair_eam_fs_kokkos.cpp +++ b/src/KOKKOS/pair_eam_fs_kokkos.cpp @@ -449,12 +449,11 @@ void PairEAMFSKokkos::interpolate(int n, double delta, double *f, t_ /* ---------------------------------------------------------------------- */ template -int PairEAMFSKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d k_sendlist, - int iswap_in, DAT::tdual_xfloat_1d &buf, +int PairEAMFSKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_1d &buf, int /*pbc_flag*/, int * /*pbc*/) { d_sendlist = k_sendlist.view(); - iswap = iswap_in; v_buf = buf.view(); Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); return n; @@ -463,7 +462,7 @@ int PairEAMFSKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_ template KOKKOS_INLINE_FUNCTION void PairEAMFSKokkos::operator()(TagPairEAMFSPackForwardComm, const int &i) const { - int j = d_sendlist(iswap, i); + int j = d_sendlist(i); v_buf[i] = d_fp[j]; } diff --git a/src/KOKKOS/pair_eam_fs_kokkos.h b/src/KOKKOS/pair_eam_fs_kokkos.h index bd03ab0015..8e4ee7851e 100644 --- a/src/KOKKOS/pair_eam_fs_kokkos.h +++ b/src/KOKKOS/pair_eam_fs_kokkos.h @@ -122,7 +122,7 @@ class PairEAMFSKokkos : public PairEAM, public KokkosBase { const F_FLOAT &epair, const F_FLOAT &fpair, const F_FLOAT &delx, const F_FLOAT &dely, const F_FLOAT &delz) const; - int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, + int pack_forward_comm_kokkos(int, DAT::tdual_int_1d, DAT::tdual_xfloat_1d&, int, int *) override; void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) override; int pack_forward_comm(int, int *, double *, int, int *) override; @@ -190,9 +190,8 @@ class PairEAMFSKokkos : public PairEAM, public KokkosBase { typename AT::t_int_1d d_ilist; typename AT::t_int_1d d_numneigh; - int iswap; int first; - typename AT::t_int_2d d_sendlist; + typename AT::t_int_1d d_sendlist; typename AT::t_xfloat_1d_um v_buf; int neighflag,newton_pair; diff --git a/src/KOKKOS/pair_eam_kokkos.cpp b/src/KOKKOS/pair_eam_kokkos.cpp index 32f4afe225..54ffa84f2d 100644 --- a/src/KOKKOS/pair_eam_kokkos.cpp +++ b/src/KOKKOS/pair_eam_kokkos.cpp @@ -444,12 +444,11 @@ void PairEAMKokkos::interpolate(int n, double delta, double *f, t_ho /* ---------------------------------------------------------------------- */ template -int PairEAMKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d k_sendlist, - int iswap_in, DAT::tdual_xfloat_1d &buf, +int PairEAMKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_1d k_sendlist, + DAT::tdual_xfloat_1d &buf, int /*pbc_flag*/, int * /*pbc*/) { d_sendlist = k_sendlist.view(); - iswap = iswap_in; v_buf = buf.view(); Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); return n; @@ -458,7 +457,7 @@ int PairEAMKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d template KOKKOS_INLINE_FUNCTION void PairEAMKokkos::operator()(TagPairEAMPackForwardComm, const int &i) const { - int j = d_sendlist(iswap, i); + int j = d_sendlist(i); v_buf[i] = d_fp[j]; } diff --git a/src/KOKKOS/pair_eam_kokkos.h b/src/KOKKOS/pair_eam_kokkos.h index 9d066d40a0..950db43fb2 100644 --- a/src/KOKKOS/pair_eam_kokkos.h +++ b/src/KOKKOS/pair_eam_kokkos.h @@ -120,7 +120,7 @@ class PairEAMKokkos : public PairEAM, public KokkosBase { const F_FLOAT &epair, const F_FLOAT &fpair, const F_FLOAT &delx, const F_FLOAT &dely, const F_FLOAT &delz) const; - int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, + int pack_forward_comm_kokkos(int, DAT::tdual_int_1d, DAT::tdual_xfloat_1d&, int, int *) override; void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) override; int pack_forward_comm(int, int *, double *, int, int *) override; @@ -186,9 +186,8 @@ class PairEAMKokkos : public PairEAM, public KokkosBase { typename AT::t_int_1d d_ilist; typename AT::t_int_1d d_numneigh; - int iswap; int first; - typename AT::t_int_2d d_sendlist; + typename AT::t_int_1d d_sendlist; typename AT::t_xfloat_1d_um v_buf; int neighflag,newton_pair; diff --git a/src/KOKKOS/pair_meam_kokkos.cpp b/src/KOKKOS/pair_meam_kokkos.cpp index 4361a387ba..9082c410e0 100644 --- a/src/KOKKOS/pair_meam_kokkos.cpp +++ b/src/KOKKOS/pair_meam_kokkos.cpp @@ -338,11 +338,10 @@ void PairMEAMKokkos::init_style() /* ---------------------------------------------------------------------- */ template -int PairMEAMKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d k_sendlist, int iswap_in, DAT::tdual_xfloat_1d &buf, +int PairMEAMKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_1d &buf, int /*pbc_flag*/, int * /*pbc*/) { d_sendlist = k_sendlist.view(); - iswap = iswap_in; v_buf = buf.view(); Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); return n*comm_forward; @@ -353,7 +352,7 @@ int PairMEAMKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2 template KOKKOS_INLINE_FUNCTION void PairMEAMKokkos::operator()(TagPairMEAMPackForwardComm, const int &i) const { - int j = d_sendlist(iswap, i); + int j = d_sendlist(i); int m = i*comm_forward; v_buf[m++] = d_rho0[j]; v_buf[m++] = d_rho1[j]; @@ -782,10 +781,9 @@ int PairMEAMKokkos::pack_reverse_comm(int n, int first, double *buf) /* ---------------------------------------------------------------------- */ template -void PairMEAMKokkos::unpack_reverse_comm_kokkos(int n, DAT::tdual_int_2d k_sendlist, int iswap_in, DAT::tdual_xfloat_1d &buf) +void PairMEAMKokkos::unpack_reverse_comm_kokkos(int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_1d &buf) { d_sendlist = k_sendlist.view(); - iswap = iswap_in; v_buf = buf.view(); Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); } @@ -795,7 +793,7 @@ void PairMEAMKokkos::unpack_reverse_comm_kokkos(int n, DAT::tdual_in template KOKKOS_INLINE_FUNCTION void PairMEAMKokkos::operator()(TagPairMEAMUnpackReverseComm, const int &i) const { - int j = d_sendlist(iswap, i); + int j = d_sendlist(i); //int m = i*30; int m = i*comm_reverse; diff --git a/src/KOKKOS/pair_meam_kokkos.h b/src/KOKKOS/pair_meam_kokkos.h index 0d0d7667f3..66b5700a72 100644 --- a/src/KOKKOS/pair_meam_kokkos.h +++ b/src/KOKKOS/pair_meam_kokkos.h @@ -76,15 +76,15 @@ class PairMEAMKokkos : public PairMEAM, public KokkosBase { KOKKOS_INLINE_FUNCTION void operator()(TagPairMEAMOffsets, const int, int&) const; - int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, + int pack_forward_comm_kokkos(int, DAT::tdual_int_1d, DAT::tdual_xfloat_1d&, int, int *) override; int pack_forward_comm(int, int *, double *, int, int *) override; void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) override; void unpack_forward_comm(int, int, double *) override; int pack_reverse_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) override; int pack_reverse_comm(int, int, double *) override; - void unpack_reverse_comm_kokkos(int, DAT::tdual_int_2d, - int, DAT::tdual_xfloat_1d&) override; + void unpack_reverse_comm_kokkos(int, DAT::tdual_int_1d, + DAT::tdual_xfloat_1d&) override; void unpack_reverse_comm(int, int *, double *) override; protected: @@ -108,10 +108,10 @@ class PairMEAMKokkos : public PairMEAM, public KokkosBase { typename AT::t_neighbors_2d d_neighbors_half; typename AT::t_int_1d d_numneigh_full; typename AT::t_neighbors_2d d_neighbors_full; - typename AT::t_int_2d d_sendlist; + typename AT::t_int_1d d_sendlist; typename AT::t_xfloat_1d_um v_buf; - int iswap,first; + int first; int neighflag,nlocal,nall,eflag,vflag; typename ArrayTypes::t_ffloat_1d d_rho, d_rho0, d_rho1, d_rho2, d_rho3, d_frhop; diff --git a/src/KOKKOS/pair_multi_lucy_rx_kokkos.cpp b/src/KOKKOS/pair_multi_lucy_rx_kokkos.cpp index 41fcac126d..2a20c9e013 100644 --- a/src/KOKKOS/pair_multi_lucy_rx_kokkos.cpp +++ b/src/KOKKOS/pair_multi_lucy_rx_kokkos.cpp @@ -646,12 +646,11 @@ void PairMultiLucyRXKokkos::getMixingWeights(int id, double &mixWtSi /* ---------------------------------------------------------------------- */ template -int PairMultiLucyRXKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_2d k_sendlist, int iswap_in, DAT::tdual_xfloat_1d &buf, int /*pbc_flag*/, int * /*pbc*/) +int PairMultiLucyRXKokkos::pack_forward_comm_kokkos(int n, DAT::tdual_int_1d k_sendlist, DAT::tdual_xfloat_1d &buf, int /*pbc_flag*/, int * /*pbc*/) { atomKK->sync(execution_space,DPDRHO_MASK); d_sendlist = k_sendlist.view(); - iswap = iswap_in; v_buf = buf.view(); Kokkos::parallel_for(Kokkos::RangePolicy(0,n),*this); return n; @@ -660,7 +659,7 @@ int PairMultiLucyRXKokkos::pack_forward_comm_kokkos(int n, DAT::tdua template KOKKOS_INLINE_FUNCTION void PairMultiLucyRXKokkos::operator()(TagPairMultiLucyRXPackForwardComm, const int &i) const { - int j = d_sendlist(iswap, i); + int j = d_sendlist(i); v_buf[i] = rho[j]; } diff --git a/src/KOKKOS/pair_multi_lucy_rx_kokkos.h b/src/KOKKOS/pair_multi_lucy_rx_kokkos.h index c335ed526f..753012e0c7 100644 --- a/src/KOKKOS/pair_multi_lucy_rx_kokkos.h +++ b/src/KOKKOS/pair_multi_lucy_rx_kokkos.h @@ -61,7 +61,7 @@ class PairMultiLucyRXKokkos : public PairMultiLucyRX, public KokkosBase { void compute_style(int, int); void init_style() override; - int pack_forward_comm_kokkos(int, DAT::tdual_int_2d, int, DAT::tdual_xfloat_1d&, + int pack_forward_comm_kokkos(int, DAT::tdual_int_1d, DAT::tdual_xfloat_1d&, int, int *) override; void unpack_forward_comm_kokkos(int, int, DAT::tdual_xfloat_1d&) override; int pack_forward_comm(int, int *, double *, int, int *) override; @@ -181,9 +181,8 @@ class PairMultiLucyRXKokkos : public PairMultiLucyRX, public KokkosBase { typename AT::tdual_ffloat_2d k_cutsq; typename AT::t_ffloat_2d d_cutsq; - int iswap; int first; - typename AT::t_int_2d d_sendlist; + typename AT::t_int_1d d_sendlist; typename AT::t_xfloat_1d_um v_buf; friend void pair_virial_fdotr_compute(PairMultiLucyRXKokkos*); diff --git a/src/comm_tiled.cpp b/src/comm_tiled.cpp index 65cbfad0b5..b864e0523d 100644 --- a/src/comm_tiled.cpp +++ b/src/comm_tiled.cpp @@ -47,14 +47,9 @@ CommTiled::CommTiled(LAMMPS *lmp) : Comm(lmp) { style = Comm::TILED; layout = Comm::LAYOUT_UNIFORM; - pbc_flag = nullptr; - buf_send = nullptr; - buf_recv = nullptr; - overlap = nullptr; - rcbinfo = nullptr; - cutghostmulti = nullptr; - cutghostmultiold = nullptr; - init_buffers(); + init_pointers(); + init_buffers_flag = 0; + maxswap = 0; } /* ---------------------------------------------------------------------- */ @@ -69,7 +64,9 @@ CommTiled::CommTiled(LAMMPS * /*lmp*/, Comm *oldcomm) : Comm(*oldcomm) style = Comm::TILED; layout = oldcomm->layout; Comm::copy_arrays(oldcomm); - init_buffers(); + init_pointers(); + init_buffers_flag = 0; + maxswap = 0; } /* ---------------------------------------------------------------------- */ @@ -85,24 +82,59 @@ CommTiled::~CommTiled() memory->destroy(cutghostmultiold); } +/* ---------------------------------------------------------------------- + initialize comm pointers to nullptr +------------------------------------------------------------------------- */ + +void CommTiled::init_pointers() +{ + buf_send = buf_recv = nullptr; + overlap = nullptr; + rcbinfo = nullptr; + cutghostmulti = nullptr; + cutghostmultiold = nullptr; + + nsendproc = nullptr; + nrecvproc = nullptr; + sendother = nullptr; + recvother = nullptr; + sendself = nullptr; + sendproc = nullptr; + recvproc = nullptr; + sendnum = nullptr; + recvnum = nullptr; + size_forward_recv = nullptr; + firstrecv = nullptr; + size_reverse_send = nullptr; + size_reverse_recv = nullptr; + forward_recv_offset = nullptr; + reverse_recv_offset = nullptr; + pbc_flag = nullptr; + pbc = nullptr; + sendbox = nullptr; + sendbox_multi = nullptr; + sendbox_multiold = nullptr; + maxsendlist = nullptr; + sendlist = nullptr; + requests = nullptr; + nprocmax = nullptr; + nexchproc = nullptr; + nexchprocmax = nullptr; + exchproc = nullptr; + exchnum = nullptr; +} + /* ---------------------------------------------------------------------- initialize comm buffers and other data structs local to CommTiled ------------------------------------------------------------------------- */ void CommTiled::init_buffers() { - buf_send = buf_recv = nullptr; maxsend = maxrecv = BUFMIN; grow_send(maxsend,2); - memory->create(buf_recv,maxrecv,"comm:buf_recv"); + grow_recv(maxrecv,1); maxoverlap = 0; - overlap = nullptr; - rcbinfo = nullptr; - cutghostmulti = nullptr; - cutghostmultiold = nullptr; - sendbox_multi = nullptr; - sendbox_multiold = nullptr; // Note this may skip growing multi arrays, will call again in init() maxswap = 6; @@ -113,6 +145,11 @@ void CommTiled::init_buffers() void CommTiled::init() { + if (!init_buffers_flag) { + init_buffers(); + init_buffers_flag = 1; + } + Comm::init(); // cannot set nswap in init_buffers() b/c @@ -2236,12 +2273,15 @@ void CommTiled::grow_send(int n, int flag) } /* ---------------------------------------------------------------------- - free/malloc the size of the recv buffer as needed with BUFFACTOR + free/malloc the size of the recv buffer as needed + flag = 0, realloc with BUFFACTOR + flag = 1, free/malloc w/out BUFFACTOR ------------------------------------------------------------------------- */ -void CommTiled::grow_recv(int n) +void CommTiled::grow_recv(int n, int flag) { - maxrecv = static_cast (BUFFACTOR * n); + if (flag) maxrecv = n; + else maxrecv = static_cast (BUFFACTOR * n); memory->destroy(buf_recv); memory->create(buf_recv,maxrecv,"comm:buf_recv"); } @@ -2428,8 +2468,10 @@ void CommTiled::deallocate_swap(int n) delete [] maxsendlist[i]; - for (int j = 0; j < nprocmax[i]; j++) memory->destroy(sendlist[i][j]); - delete [] sendlist[i]; + if (sendlist && sendlist[i]) { + for (int j = 0; j < nprocmax[i]; j++) memory->destroy(sendlist[i][j]); + delete [] sendlist[i]; + } } delete [] sendproc; diff --git a/src/comm_tiled.h b/src/comm_tiled.h index c9434e6164..857cddf033 100644 --- a/src/comm_tiled.h +++ b/src/comm_tiled.h @@ -51,7 +51,7 @@ class CommTiled : public Comm { double memory_usage() override; - private: + protected: int nswap; // # of swaps to perform = 2*dim int maxswap; // largest nswap can be = 6 @@ -117,8 +117,9 @@ class CommTiled : public Comm { double *sublo, *subhi; int dimension; - // NOTE: init_buffers is called from a constructor and must not be made virtual + void init_pointers(); void init_buffers(); + int init_buffers_flag; // box drop and other functions @@ -145,11 +146,11 @@ class CommTiled : public Comm { int point_drop_tiled_recurse(double *, int, int); int closer_subbox_edge(int, double *); - void grow_send(int, int); // reallocate send buffer - void grow_recv(int); // free/allocate recv buffer - void grow_list(int, int, int); // reallocate sendlist for one swap/proc + virtual void grow_send(int, int); // reallocate send buffer + virtual void grow_recv(int, int flag = 0); // free/allocate recv buffer + virtual void grow_list(int, int, int); // reallocate sendlist for one swap/proc void allocate_swap(int); // allocate swap arrays - void grow_swap_send(int, int, int); // grow swap arrays for send and recv + virtual void grow_swap_send(int, int, int); // grow swap arrays for send and recv void grow_swap_send_multi(int, int); // grow multi swap arrays for send and recv void grow_swap_recv(int, int); void deallocate_swap(int); // deallocate swap arrays diff --git a/unittest/force-styles/tests/in.conp b/unittest/force-styles/tests/in.conp index 92d2f63cd1..08673ec20b 100644 --- a/unittest/force-styles/tests/in.conp +++ b/unittest/force-styles/tests/in.conp @@ -22,3 +22,4 @@ angle_coeff * group bot type 1 group top type 2 +group ele type 1 2 diff --git a/unittest/force-styles/tests/kspace-ewald_conp_charge.yaml b/unittest/force-styles/tests/kspace-ewald_conp_charge.yaml index d0eaee6b92..9bc190a766 100644 --- a/unittest/force-styles/tests/kspace-ewald_conp_charge.yaml +++ b/unittest/force-styles/tests/kspace-ewald_conp_charge.yaml @@ -1,6 +1,6 @@ --- -lammps_version: 23 Jun 2022 -date_generated: Wed Sep 21 13:52:53 2022 +lammps_version: 7 Feb 2024 +date_generated: Mon Mar 4 09:44:30 2024 epsilon: 1e-12 skip_tests: gpu kokkos_omp omp prerequisites: ! | @@ -16,6 +16,7 @@ post_commands: ! | kspace_modify gewald 0.23118 kspace_modify slab ew2d fix fxcpm bot electrode/conp -1.0 1.805 couple top 1.0 symm on + fix fxforce ele setforce 0 0 0 input_file: in.conp pair_style: coul/long 15.0 pair_coeff: ! | @@ -27,97 +28,97 @@ init_coul: 2.215589572896434 init_stress: ! |2- 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 init_forces: ! |2 - 1 2.0780648532795694e-04 1.9949672015209204e-03 3.1005914149473996e+00 - 2 -1.6777235182686288e-02 2.1481432256290419e-03 3.0881659196467988e+00 - 3 6.0082164895554737e-04 5.1573260226633801e-03 3.1029192412328555e+00 - 4 -1.6728974802490675e-02 6.1174723156886242e-03 3.0909324782862346e+00 - 5 4.2029366155132378e-02 -2.3455526736195693e-03 -1.5659617577954634e+00 - 6 5.5635790919204904e-02 -2.4542947062522369e-03 -1.5693827709331334e+00 - 7 4.2014920784252008e-02 -7.5287470219125008e-04 -1.5671265392163820e+00 - 8 5.5808767852333470e-02 -9.9105389808573120e-04 -1.5707104957299389e+00 - 9 -5.0959878750421551e-02 -2.3630298689785601e-03 -1.5769250181497101e+00 - 10 -3.3526564930579039e-02 -2.3802275431282884e-03 -1.5617801011657175e+00 - 11 -5.1236396351794389e-02 -4.9531100598979201e-04 -1.5779995894034005e+00 - 12 -3.3740693032952060e-02 -1.0210406243572182e-03 -1.5630986537874150e+00 - 13 -1.1437102611353016e-03 -4.6454866413029015e-05 5.4282837980149448e-03 - 14 2.3914999373115431e-03 -1.6478680244651469e-04 2.9802178734319239e-02 - 15 3.9287193302652786e-05 -2.5715673267285659e-05 2.8944525105129479e-03 - 16 2.0458480716482328e-03 -1.2119161321908735e-04 3.3689550843809452e-02 - 17 -2.7146073277767471e-03 -8.2376243258224663e-04 2.6564130941474612e-02 - 18 1.3669692885198135e-03 -4.2357196145489820e-04 3.2396141113926739e-02 - 19 3.0143371860819995e-04 -8.6218593339583785e-04 2.6284521141350669e-02 - 20 1.1542435168435056e-03 -2.7252318260838826e-04 3.4237916528138110e-02 - 21 -1.2350056952573553e-03 4.8655691135364269e-04 5.9284283442393631e-03 - 22 2.3656743884722890e-03 9.6575340844312705e-04 2.9811074931784823e-02 - 23 4.6754986244969657e-05 3.0149464050350903e-04 3.4630785686112129e-03 - 24 2.0301227080749633e-03 6.3879578068684812e-04 3.3653437189053413e-02 - 25 -2.3656211013513076e-03 -8.0454594828768334e-04 2.8476980555362911e-02 - 26 1.1566723797447039e-03 -3.9614599888570504e-04 3.2873323713155905e-02 - 27 2.8784994028036400e-04 -8.3661697184444898e-04 2.8317655886021253e-02 - 28 9.3882364605486020e-04 -2.3327601777843495e-04 3.4334676606415648e-02 - 29 -4.7969977052124917e-04 -1.2933334305373028e-04 -1.2336987392568071e-02 - 30 6.4733118786851766e-05 -1.3190918849005797e-04 -1.2737933567178844e-02 - 31 2.4269094157913586e-04 -1.3093943526788584e-04 -1.2136133260085013e-02 - 32 1.7452552740941527e-04 -1.1792779046242341e-04 -1.4181538324619835e-02 - 33 -3.8366266481516803e-04 -7.1061854758754556e-05 -1.3699106365426135e-02 - 34 2.8849004082563746e-05 -5.7838605310673531e-05 -1.3764181266896890e-02 - 35 2.2648059665862587e-04 -7.2851385190891320e-05 -1.3537361892926607e-02 - 36 1.2929221129083645e-04 -4.2862960950045859e-05 -1.4926105930886896e-02 - 37 -4.7698025941707008e-04 2.9971529466656788e-04 -1.2393604822896313e-02 - 38 6.4231095731188766e-05 2.7548977518460050e-04 -1.2789498345723021e-02 - 39 2.4169204779864826e-04 3.0552093685810269e-04 -1.2193908285665961e-02 - 40 1.7324998349441456e-04 2.2898000918153004e-04 -1.4225267020837207e-02 - 41 -3.4345772150395188e-04 -9.8012060153887415e-05 -1.4482722052972283e-02 - 42 2.0345466940577010e-05 -8.5250083485342566e-05 -1.4497101004472062e-02 - 43 2.0917627239292995e-04 -1.0051271468149899e-04 -1.4335313646556430e-02 - 44 1.1456796622437295e-04 -6.7553675788598551e-05 -1.5543196158604005e-02 + 1 2.0780648532797705e-04 1.9949672015210172e-03 3.1005914149473988e+00 + 2 -1.6777235182686239e-02 2.1481432256291962e-03 3.0881659196467979e+00 + 3 6.0082164895566240e-04 5.1573260226632518e-03 3.1029192412328550e+00 + 4 -1.6728974802490665e-02 6.1174723156885227e-03 3.0909324782862333e+00 + 5 4.2029366155132364e-02 -2.3455526736195940e-03 -1.5659617577954636e+00 + 6 5.5635790919204904e-02 -2.4542947062522933e-03 -1.5693827709331336e+00 + 7 4.2014920784251980e-02 -7.5287470219118655e-04 -1.5671265392163822e+00 + 8 5.5808767852333491e-02 -9.9105389808568046e-04 -1.5707104957299391e+00 + 9 -5.0959878750421538e-02 -2.3630298689785965e-03 -1.5769250181497101e+00 + 10 -3.3526564930579081e-02 -2.3802275431283552e-03 -1.5617801011657175e+00 + 11 -5.1236396351794437e-02 -4.9531100598972577e-04 -1.5779995894034005e+00 + 12 -3.3740693032952088e-02 -1.0210406243571744e-03 -1.5630986537874152e+00 + 13 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 14 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 15 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 16 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 17 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 18 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 19 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 25 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 26 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 27 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 28 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 29 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 30 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 31 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 32 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 33 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 34 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 35 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 36 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 37 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 38 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 39 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 40 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 41 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 42 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 43 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 44 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 run_vdwl: 0 -run_coul: 6.662694629990089 +run_coul: 6.662694556930397 run_stress: ! |2- 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 run_forces: ! |2 - 1 2.4590612609445102e-04 1.9614041218568861e-03 3.0874291949281147e+00 - 2 -1.6646393233505193e-02 2.1136941574790400e-03 3.0751132981100078e+00 - 3 6.3535217476586373e-04 5.1012487117746350e-03 3.0897301317927290e+00 - 4 -1.6598677148313409e-02 6.0535154567108685e-03 3.0778495346381409e+00 - 5 4.2257888534896988e-02 -2.3028533365965051e-03 -1.5593100596807521e+00 - 6 5.5690508027606708e-02 -2.4104721624763235e-03 -1.5626897542440843e+00 - 7 4.2243973130370149e-02 -7.6153220413259775e-04 -1.5604618260035832e+00 - 8 5.5862703939049158e-02 -9.9825803703216718e-04 -1.5640031014325448e+00 - 9 -5.1059409954744304e-02 -2.3195553026588347e-03 -1.5701677851024036e+00 - 10 -3.3824298857146967e-02 -2.3375522139358631e-03 -1.5551647619109401e+00 - 11 -5.1334079184640377e-02 -5.0583705005136689e-04 -1.5712298444761112e+00 - 12 -3.4037363466305925e-02 -1.0275978089057873e-03 -1.5564691026885336e+00 - 13 -1.1767076011504501e-03 -4.7681963272732406e-05 5.6177800544716262e-03 - 14 2.3826294437743331e-03 -1.6349140124449633e-04 2.9836275824428962e-02 - 15 4.1635367214843796e-05 -2.7287283914685102e-05 3.0967012748694773e-03 - 16 2.0334138778396313e-03 -1.1986039772787527e-04 3.3679727731055195e-02 - 17 -2.7026084826568797e-03 -8.1815079485725360e-04 2.6574868248546435e-02 - 18 1.3603406762441243e-03 -4.1902595052936860e-04 3.2373613783594497e-02 - 19 2.9940467686436986e-04 -8.5646794759970863e-04 2.6296909514905095e-02 - 20 1.1469475577225402e-03 -2.6907093945665336e-04 3.4197589258157073e-02 - 21 -1.2662578686531134e-03 4.9770031968890231e-04 6.1141650873547037e-03 - 22 2.3568409810395020e-03 9.5671841592085381e-04 2.9844352492872490e-02 - 23 4.8965507374742117e-05 3.1616579858329929e-04 3.6613180489820005e-03 - 24 2.0177821554069170e-03 6.3083810187911310e-04 3.3643353017422439e-02 - 25 -2.3537455003017457e-03 -7.9846295760147956e-04 2.8468250829639500e-02 - 26 1.1507655048236000e-03 -3.9159985067612060e-04 3.2839870487003708e-02 - 27 2.8582562554448814e-04 -8.3038492818152999e-04 2.8309777443009273e-02 - 28 9.3274285761092680e-04 -2.2997823984283208e-04 3.4287630335266286e-02 - 29 -4.7502414048888327e-04 -1.2847214455389489e-04 -1.2453998829891042e-02 - 30 6.3675154563755000e-05 -1.3104204562344653e-04 -1.2848240218511071e-02 - 31 2.4068203429808906e-04 -1.3007692195448562e-04 -1.2254443488117142e-02 - 32 1.7286880375665112e-04 -1.1713944254614034e-04 -1.4279748536149278e-02 - 33 -3.7975304094097439e-04 -7.0481503989778179e-05 -1.3805675914786045e-02 - 34 2.8172580422574018e-05 -5.7414812953860394e-05 -1.3867744309035916e-02 - 35 2.2448042926710853e-04 -7.2258368796568220e-05 -1.3645037267085249e-02 - 36 1.2804302797390986e-04 -4.2547023166907131e-05 -1.5019384166440140e-02 - 37 -4.7231656130619122e-04 2.9759414220405656e-04 -1.2510308090752414e-02 - 38 6.3181133759042352e-05 2.7366531591578288e-04 -1.2899551129187765e-02 - 39 2.3968383978790597e-04 3.0338116638639894e-04 -1.2311919409216509e-02 - 40 1.7159804905743131e-04 2.2744508340904917e-04 -1.4323246783684936e-02 - 41 -3.3986046011853923e-04 -9.7274166717457145e-05 -1.4583591616566860e-02 - 42 1.9775995840422978e-05 -8.4675117269364898e-05 -1.4595729099929700e-02 - 43 2.0725822207231137e-04 -9.9764702521265135e-05 -1.4437236974797743e-02 - 44 1.1345006523014360e-04 -6.7103771021504086e-05 -1.5632251527466189e-02 + 1 2.4590683616588566e-04 1.9614031577864796e-03 3.0874292323214036e+00 + 2 -1.6646391056109287e-02 2.1136931488459688e-03 3.0751133344119794e+00 + 3 6.3535284261976926e-04 5.1012486499620825e-03 3.0897301693141319e+00 + 4 -1.6598674977089559e-02 6.0535154273402107e-03 3.0778495712965124e+00 + 5 4.2257890248609438e-02 -2.3028528771736243e-03 -1.5593100743454236e+00 + 6 5.5690508840794850e-02 -2.4104716736066006e-03 -1.5626897684026868e+00 + 7 4.2243974848895645e-02 -7.6153214117129057e-04 -1.5604618407191602e+00 + 8 5.5862704771247280e-02 -9.9825804058299890e-04 -1.5640031157582626e+00 + 9 -5.1059412079591346e-02 -2.3195548367148894e-03 -1.5701677996288432e+00 + 10 -3.3824301875619085e-02 -2.3375517362837230e-03 -1.5551647759943836e+00 + 11 -5.1334081278836916e-02 -5.0583707575582921e-04 -1.5712298590599834e+00 + 12 -3.4037366496628307e-02 -1.0275977984217173e-03 -1.5564691169384559e+00 + 13 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 14 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 15 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 16 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 17 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 18 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 19 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 25 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 26 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 27 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 28 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 29 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 30 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 31 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 32 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 33 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 34 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 35 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 36 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 37 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 38 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 39 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 40 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 41 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 42 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 43 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 44 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 ... diff --git a/unittest/force-styles/tests/kspace-pppm_conp_charge.yaml b/unittest/force-styles/tests/kspace-pppm_conp_charge.yaml index 0555d12ed4..38161ee044 100644 --- a/unittest/force-styles/tests/kspace-pppm_conp_charge.yaml +++ b/unittest/force-styles/tests/kspace-pppm_conp_charge.yaml @@ -1,6 +1,6 @@ --- -lammps_version: 23 Jun 2022 -date_generated: Wed Sep 21 13:52:39 2022 +lammps_version: 7 Feb 2024 +date_generated: Mon Mar 4 09:44:31 2024 epsilon: 3e-12 skip_tests: gpu kokkos_omp omp prerequisites: ! | @@ -16,6 +16,7 @@ post_commands: ! | kspace_modify gewald 0.23118 kspace_modify slab 3.0 fix fxcpm bot electrode/conp -1.0 1.805 couple top 1.0 symm on + fix fxforce ele setforce 0 0 0 input_file: in.conp pair_style: coul/long 15.0 pair_coeff: ! | @@ -23,101 +24,101 @@ pair_coeff: ! | extract: ! "" natoms: 44 init_vdwl: 0 -init_coul: 2.2156402256727614 +init_coul: 2.215640225672775 init_stress: ! |2- 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 init_forces: ! |2 - 1 2.0996096688279944e-04 1.9837586784580306e-03 3.1004822661058822e+00 - 2 -1.6783332510617883e-02 2.1368843599407611e-03 3.0880130470329230e+00 - 3 6.0300296042517466e-04 5.1688381279905342e-03 3.1028182137891114e+00 - 4 -1.6735061532950901e-02 6.1290626039690339e-03 3.0907879891042755e+00 - 5 4.2014131860757913e-02 -2.3478381081742388e-03 -1.5658874682481487e+00 - 6 5.5659823770659422e-02 -2.4566144388410410e-03 -1.5693278833316506e+00 - 7 4.1999624791768865e-02 -7.5066218795240259e-04 -1.5670569809441617e+00 - 8 5.5832732887661884e-02 -9.8883264742169940e-04 -1.5706605160409139e+00 - 9 -5.0976953599115804e-02 -2.3653810185280950e-03 -1.5768945194236066e+00 - 10 -3.3513771125456657e-02 -2.3824712764543426e-03 -1.5616806812004886e+00 - 11 -5.1253442064492741e-02 -4.9304425051529275e-04 -1.5779738349804424e+00 - 12 -3.3727836471637192e-02 -1.0188844490582761e-03 -1.5630041309277038e+00 - 13 -1.1453068449918257e-03 -4.7335833322794788e-05 5.4292779404649470e-03 - 14 2.3900993287279790e-03 -1.6878550058260119e-04 2.9808528147740175e-02 - 15 4.0078428215627730e-05 -2.6184607051201481e-05 2.8941780231019881e-03 - 16 2.0473353699190459e-03 -1.2552209515766962e-04 3.3684989110502959e-02 - 17 -2.7210216747431955e-03 -8.2349543008294359e-04 2.6567504438257068e-02 - 18 1.3656002828979516e-03 -4.2323438710338486e-04 3.2404938547366383e-02 - 19 3.0785575286292939e-04 -8.6186674263511191e-04 2.6288541663855129e-02 - 20 1.1555469330548321e-03 -2.7230960410720359e-04 3.4235148032534163e-02 - 21 -1.2368093613861506e-03 4.8760847861882366e-04 5.9296798954256557e-03 - 22 2.3643140421916085e-03 9.6975102599399746e-04 2.9817231402721564e-02 - 23 4.7705653522709085e-05 3.0203836842154655e-04 3.4631818106649337e-03 - 24 2.0316297431160258e-03 6.4335031755788927e-04 3.3648629802522749e-02 - 25 -2.3728144718995455e-03 -8.0497592536520339e-04 2.8474707915345274e-02 - 26 1.1555985481661916e-03 -3.9649433660109970e-04 3.2876098209196375e-02 - 27 2.9459292459149998e-04 -8.3700881746301306e-04 2.8316136079038545e-02 - 28 9.4027352090446912e-04 -2.3371025598546553e-04 3.4325153603153732e-02 - 29 -5.2133856931286127e-04 -1.4498587872629142e-04 -1.2345168780426297e-02 - 30 7.0344538924238829e-05 -1.4805754895657979e-04 -1.2765142487049358e-02 - 31 2.7857644686035687e-04 -1.4667349483298643e-04 -1.2140095836769501e-02 - 32 1.7479865631996218e-04 -1.3335074368636031e-04 -1.4152171307753206e-02 - 33 -4.2607366742485959e-04 -7.2661709209033136e-05 -1.3713642029394900e-02 - 34 3.4224570995904750e-05 -5.9352423088202727e-05 -1.3797063100154012e-02 - 35 2.6332638434852483e-04 -7.4573909050170201e-05 -1.3548481212572565e-02 - 36 1.2956589882656260e-04 -4.4469640559387641e-05 -1.4903750420442119e-02 - 37 -5.1855202137555164e-04 3.1768672664149645e-04 -1.2402413876588990e-02 - 38 6.9744637010106164e-05 2.9379923413403201e-04 -1.2817238930047764e-02 - 39 2.7753815671547851e-04 3.2364879063853462e-04 -1.2198687630220518e-02 - 40 1.7359211286247436e-04 2.4661766514410969e-04 -1.4196607980261094e-02 - 41 -3.8501793941197521e-04 -9.8818538537990245e-05 -1.4472863167957050e-02 - 42 2.5779944975443997e-05 -8.5975255466014692e-05 -1.4504933662725301e-02 - 43 2.4535595442148292e-04 -1.0127263490049206e-04 -1.4321758087878972e-02 - 44 1.1457678622968817e-04 -6.8200688092186871e-05 -1.5499407046729242e-02 + 1 2.0996096688288336e-04 1.9837586784579777e-03 3.1004822661058866e+00 + 2 -1.6783332510618088e-02 2.1368843599407052e-03 3.0880130470329270e+00 + 3 6.0300296042527755e-04 5.1688381279906869e-03 3.1028182137891140e+00 + 4 -1.6735061532951116e-02 6.1290626039692056e-03 3.0907879891042778e+00 + 5 4.2014131860757857e-02 -2.3478381081742123e-03 -1.5658874682481501e+00 + 6 5.5659823770659547e-02 -2.4566144388410201e-03 -1.5693278833316524e+00 + 7 4.1999624791768810e-02 -7.5066218795247393e-04 -1.5670569809441637e+00 + 8 5.5832732887661961e-02 -9.8883264742177161e-04 -1.5706605160409157e+00 + 9 -5.0976953599115846e-02 -2.3653810185280759e-03 -1.5768945194236084e+00 + 10 -3.3513771125456573e-02 -2.3824712764543218e-03 -1.5616806812004898e+00 + 11 -5.1253442064492769e-02 -4.9304425051536007e-04 -1.5779738349804435e+00 + 12 -3.3727836471637081e-02 -1.0188844490583557e-03 -1.5630041309277052e+00 + 13 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 14 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 15 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 16 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 17 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 18 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 19 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 25 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 26 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 27 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 28 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 29 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 30 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 31 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 32 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 33 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 34 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 35 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 36 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 37 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 38 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 39 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 40 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 41 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 42 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 43 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 44 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 run_vdwl: 0 -run_coul: 6.662844717848837 +run_coul: 6.662844644802024 run_stress: ! |2- 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 run_forces: ! |2 - 1 2.4838374656870440e-04 1.9503798034564181e-03 3.0873204052231675e+00 - 2 -1.6652792550963507e-02 2.1026197438206527e-03 3.0749612313228378e+00 - 3 6.3785681925848106e-04 5.1125747842690368e-03 3.0896293583134606e+00 - 4 -1.6605065971975488e-02 6.0649203428150876e-03 3.0777057441315305e+00 - 5 4.2242720963296274e-02 -2.3050719334346786e-03 -1.5592361839228894e+00 - 6 5.5714272244614366e-02 -2.4127241272198356e-03 -1.5626351053810128e+00 - 7 4.2228744507856318e-02 -7.5938680980830215e-04 -1.5603926173148708e+00 - 8 5.5886400463161408e-02 -9.9610508394880446e-04 -1.5639532943562677e+00 - 9 -5.1076260774663269e-02 -2.3218376339398856e-03 -1.5701372580807029e+00 - 10 -3.3811558405906099e-02 -2.3397301017438945e-03 -1.5550660295253020e+00 - 11 -5.1350900750795785e-02 -5.0363945411724615e-04 -1.5712039970018119e+00 - 12 -3.4024561045577786e-02 -1.0255079139096881e-03 -1.5563752017113657e+00 - 13 -1.1783355827329363e-03 -4.8584425213699084e-05 5.6187810005819084e-03 - 14 2.3812433011153062e-03 -1.6745821939573657e-04 2.9842604329757397e-02 - 15 4.2472634867315832e-05 -2.7784504406519571e-05 3.0964622176844602e-03 - 16 2.0348857368272344e-03 -1.2415016403438035e-04 3.3675205082768264e-02 - 17 -2.7089567432503573e-03 -8.1788662401764114e-04 2.6578231998707000e-02 - 18 1.3589859834844708e-03 -4.1869284075205220e-04 3.2382362625908642e-02 - 19 3.0575998684987288e-04 -8.5615261685325662e-04 2.6300918365183709e-02 - 20 1.1482382726252934e-03 -2.6885864047674810e-04 3.4194853807722227e-02 - 21 -1.2680891310638792e-03 4.9877122346546224e-04 6.1154164862940522e-03 - 22 2.3554944751877239e-03 9.6068685589809240e-04 2.9850487598267021e-02 - 23 4.9959016556344255e-05 3.1673714227676154e-04 3.6614479955528112e-03 - 24 2.0192733259603224e-03 6.3534849028298586e-04 3.3638585635455770e-02 - 25 -2.3608563352120440e-03 -7.9888874314704573e-04 2.8465994834953420e-02 - 26 1.1497012824588045e-03 -3.9194609517719160e-04 3.2842627585052867e-02 - 27 2.9249325092285189e-04 -8.3077344407106490e-04 2.8308269755484061e-02 - 28 9.3417705968603434e-04 -2.3040781495046246e-04 3.4278191255128133e-02 - 29 -5.1652528928022433e-04 -1.4404353042683099e-04 -1.2462150875064196e-02 - 30 6.9288940488795056e-05 -1.4710788156542239e-04 -1.2875332550432134e-02 - 31 2.7644608312646314e-04 -1.4573040212804145e-04 -1.2258366148270420e-02 - 32 1.7312052380602741e-04 -1.3246895843787418e-04 -1.4250473428514749e-02 - 33 -4.2201273060055557e-04 -7.2075937985441126e-05 -1.3820153961237609e-02 - 34 3.3549241776445280e-05 -5.8924381188893540e-05 -1.3900492261623465e-02 - 35 2.6119063773180797e-04 -7.3975274656908229e-05 -1.3656086631368676e-02 - 36 1.2829798186810219e-04 -4.4146305074977061e-05 -1.4997087695938056e-02 - 37 -5.1375024459660446e-04 3.1547360096919003e-04 -1.2519087424517190e-02 - 38 6.8697062203298403e-05 2.9188411177715840e-04 -1.2927175328444108e-02 - 39 2.7540798890579723e-04 3.2141722701930868e-04 -1.2316658300695350e-02 - 40 1.7191884579607650e-04 2.4497453169432579e-04 -1.4294679585099376e-02 - 41 -3.8125358429239129e-04 -9.8073404256391242e-05 -1.4573806404289218e-02 - 42 2.5208712883704254e-05 -8.5394829999053783e-05 -1.4603558816163261e-02 - 43 2.4329125095209453e-04 -1.0051714757303402e-04 -1.4423743772053488e-02 - 44 1.1343880007511943e-04 -6.7742613833467660e-05 -1.5588639087563531e-02 + 1 2.4838446863956616e-04 1.9503788466163226e-03 3.0873204426106526e+00 + 2 -1.6652790386577014e-02 2.1026187422225435e-03 3.0749612676149027e+00 + 3 6.3785749905510489e-04 5.1125747155211397e-03 3.0896293958296610e+00 + 4 -1.6605063813845172e-02 6.0649203065202620e-03 3.0777057807809554e+00 + 5 4.2242722672783749e-02 -2.3050714764837649e-03 -1.5592361985876177e+00 + 6 5.5714273062644336e-02 -2.4127236407636803e-03 -1.5626351195306318e+00 + 7 4.2228746222139832e-02 -7.5938674438442760e-04 -1.5603926320308752e+00 + 8 5.5886401300220948e-02 -9.9610508505008281e-04 -1.5639533086735800e+00 + 9 -5.1076262902731158e-02 -2.3218371704875301e-03 -1.5701372726008263e+00 + 10 -3.3811561421032657e-02 -2.3397296264742822e-03 -1.5550660436064543e+00 + 11 -5.1350902848165500e-02 -5.0363947736732217e-04 -1.5712040115797643e+00 + 12 -3.4024564072498521e-02 -1.0255079009805182e-03 -1.5563752159595889e+00 + 13 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 14 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 15 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 16 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 17 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 18 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 19 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 25 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 26 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 27 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 28 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 29 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 30 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 31 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 32 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 33 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 34 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 35 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 36 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 37 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 38 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 39 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 40 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 41 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 42 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 43 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 44 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 ...