Skip to content

Commit 68f4353

Browse files
committed
Move Comm into a file
Add force module that uses KRS
1 parent c051efb commit 68f4353

28 files changed

+863
-243
lines changed

input/in.lj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ atom_style atomic
55

66
newton off
77
lattice fcc 0.8442
8-
region box block 0 80 0 80 0 80
8+
region box block 0 100 0 100 0 100
99
create_box 1 box
1010
create_atoms 1 box
1111
mass 1 2.0
@@ -20,4 +20,4 @@ neigh_modify every 20 one 50
2020
fix 1 all nve
2121
thermo 10
2222

23-
run 100
23+
run 100

src/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ if(ENABLE_MPI)
1515
target_compile_definitions(ExaMiniMD PRIVATE EXAMINIMD_ENABLE_MPI)
1616
endif()
1717

18-
# Select a default set of options. We can export this as CMake options later
19-
if (ENABLE_KOKKOS_REMOTE_SPACES)
20-
target_compile_definitions(ExaMiniMD PRIVATE EXAMINIMD_ENABLE_KOKKOS_REMOTE_SPACES)
21-
target_compile_definitions(ExaMiniMD PRIVATE SHMEMTESTS_USE_SCALAR)
22-
#target_compile_definitions(ExaMiniMD PRIVATE SHMEMTESTS_USE_HALO)
23-
target_compile_definitions(ExaMiniMD PRIVATE SHMEMTESTS_USE_GLOBAL)
24-
endif()
25-
2618
target_include_directories(ExaMiniMD PRIVATE ${Kokkos_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${SUBDIRECTORIES})
2719
target_link_libraries(ExaMiniMD PRIVATE $<$<BOOL:${ENABLE_MPI}>:MPI::MPI_CXX> Kokkos::kokkos $<$<BOOL:${ENABLE_KOKKOS_REMOTE_SPACES}>:Kokkos::kokkosremotespaces>)
2820

src/binning_types/binning_kksort.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace {
7171
void BinningKKSort::create_binning(T_X_FLOAT dx_in, T_X_FLOAT dy_in, T_X_FLOAT dz_in, int halo_depth, bool do_local, bool do_ghost, bool sort) {
7272
if(do_local||do_ghost) {
7373
nhalo = halo_depth;
74-
std::pair<T_INT,T_INT> range(do_local?0:system->N_local,
74+
Kokkos::pair<T_INT,T_INT> range(do_local?0:system->N_local,
7575
do_ghost?system->N_local+system->N_ghost:system->N_local);
7676

7777
nbinx = T_INT(system->sub_domain_x/dx_in);

src/comm_lib.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//************************************************************************
2+
// ExaMiniMD v. 1.0
3+
// Copyright (2018) National Technology & Engineering Solutions of Sandia,
4+
// LLC (NTESS).
5+
//
6+
// Under the terms of Contract DE-NA-0003525 with NTESS, the U.S. Government
7+
// retains certain rights in this software.
8+
//
9+
// ExaMiniMD is licensed under 3-clause BSD terms of use: Redistribution and
10+
// use in source and binary forms, with or without modification, are
11+
// permitted provided that the following conditions are met:
12+
//
13+
// 1. Redistributions of source code must retain the above copyright notice,
14+
// this list of conditions and the following disclaimer.
15+
//
16+
// 2. Redistributions in binary form must reproduce the above copyright notice,
17+
// this list of conditions and the following disclaimer in the documentation
18+
// and/or other materials provided with the distribution.
19+
//
20+
// 3. Neither the name of the Corporation nor the names of the contributors
21+
// may be used to endorse or promote products derived from this software
22+
// without specific prior written permission.
23+
//
24+
// THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY EXPRESS OR IMPLIED
25+
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26+
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27+
// IN NO EVENT SHALL NTESS OR THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28+
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29+
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30+
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31+
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32+
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
33+
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34+
// POSSIBILITY OF SUCH DAMAGE.
35+
//
36+
// Questions? Contact Christian R. Trott (crtrott@sandia.gov)
37+
//************************************************************************
38+
39+
#include <comm_lib.h>
40+
#include <assert.h>
41+
42+
#if EXAMINIMD_ENABLE_MPI
43+
#include <mpi.h>
44+
#endif
45+
46+
#ifdef EXAMINIMD_ENABLE_KOKKOS_REMOTE_SPACES
47+
#include <Kokkos_RemoteSpaces.hpp>
48+
#endif
49+
50+
void comm_lib_init(int argc, char* argv[]) {
51+
#if defined (EXAMINIMD_ENABLE_MPI) || defined (EXAMINIMD_ENABLE_KOKKOS_REMOTE_SPACES)
52+
int mpi_thread_level_available;
53+
int mpi_thread_level_required = MPI_THREAD_MULTIPLE;
54+
55+
#ifdef KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL
56+
mpi_thread_level_required = MPI_THREAD_SINGLE;
57+
#endif
58+
59+
MPI_Init_thread(&argc, &argv, mpi_thread_level_required,
60+
&mpi_thread_level_available);
61+
assert(mpi_thread_level_available >= mpi_thread_level_required);
62+
63+
#ifdef KRS_ENABLE_SHMEMSPACE
64+
shmem_init_thread(mpi_thread_level_required, &mpi_thread_level_available);
65+
assert(mpi_thread_level_available >= mpi_thread_level_required);
66+
#endif
67+
68+
#ifdef KRS_ENABLE_NVSHMEMSPACE
69+
MPI_Comm mpi_comm;
70+
nvshmemx_init_attr_t attr;
71+
mpi_comm = MPI_COMM_WORLD;
72+
attr.mpi_comm = &mpi_comm;
73+
nvshmemx_init_attr(NVSHMEMX_INIT_WITH_MPI_COMM, &attr);
74+
#endif
75+
}
76+
77+
void comm_lib_finalize() {
78+
#if defined (EXAMINIMD_ENABLE_MPI) || defined (EXAMINIMD_ENABLE_KOKKOS_REMOTE_SPACES)
79+
#ifdef KRS_ENABLE_SHMEMSPACE
80+
shmem_finalize();
81+
#endif
82+
#ifdef KRS_ENABLE_NVSHMEMSPACE
83+
nvshmem_finalize();
84+
#endif
85+
MPI_Finalize();
86+
#endif
87+
#endif
88+
}

src/comm_lib.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//************************************************************************
2+
// ExaMiniMD v. 1.0
3+
// Copyright (2018) National Technology & Engineering Solutions of Sandia,
4+
// LLC (NTESS).
5+
//
6+
// Under the terms of Contract DE-NA-0003525 with NTESS, the U.S. Government
7+
// retains certain rights in this software.
8+
//
9+
// ExaMiniMD is licensed under 3-clause BSD terms of use: Redistribution and
10+
// use in source and binary forms, with or without modification, are
11+
// permitted provided that the following conditions are met:
12+
//
13+
// 1. Redistributions of source code must retain the above copyright notice,
14+
// this list of conditions and the following disclaimer.
15+
//
16+
// 2. Redistributions in binary form must reproduce the above copyright notice,
17+
// this list of conditions and the following disclaimer in the documentation
18+
// and/or other materials provided with the distribution.
19+
//
20+
// 3. Neither the name of the Corporation nor the names of the contributors
21+
// may be used to endorse or promote products derived from this software
22+
// without specific prior written permission.
23+
//
24+
// THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY EXPRESS OR IMPLIED
25+
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26+
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27+
// IN NO EVENT SHALL NTESS OR THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28+
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29+
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30+
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31+
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32+
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
33+
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34+
// POSSIBILITY OF SUCH DAMAGE.
35+
//
36+
// Questions? Contact Christian R. Trott (crtrott@sandia.gov)
37+
//************************************************************************
38+
39+
#pragma once
40+
41+
#ifndef COMM_INIT_H
42+
#define COMM_INIT_H
43+
44+
void comm_lib_init(int argc, char* argv[]);
45+
void comm_lib_finalize();
46+
47+
#endif

src/comm_types/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
FILE(GLOB SRCS *.cpp)
22
target_sources(ExaMiniMD PRIVATE ${SRCS})
3-
4-
if (!ENABLE_MPI AND !ENABLE_KOKKOS_REMOTE_SPACES)
5-
# Skip MPI module
6-
list(FILTER SRCS EXCLUDE REGEX ".*comm_mpi\\.cpp$")
7-
endif()
8-
93
target_sources(ExaMiniMD PRIVATE ${SRCS})

src/comm_types/comm_mpi.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
// Questions? Contact Christian R. Trott (crtrott@sandia.gov)
3737
//************************************************************************
3838

39+
#include <string>
40+
3941
#if defined(EXAMINIMD_ENABLE_MPI) || defined (EXAMINIMD_ENABLE_KOKKOS_REMOTE_SPACES)
4042
#include<comm_mpi.h>
4143

@@ -197,14 +199,12 @@ void CommMPI::exchange() {
197199
s = *system;
198200
N_local = system->N_local;
199201
N_ghost = 0;
200-
//printf("System A: %i %lf %lf %lf %i\n",s.N_local,s.x(21,0),s.x(21,1),s.x(21,2),s.type(21));
201202
Kokkos::parallel_for("CommMPI::exchange_self",
202203
Kokkos::RangePolicy<TagExchangeSelf, Kokkos::IndexType<T_INT> >(0,N_local), *this);
203204

204205
T_INT N_total_recv = 0;
205206
T_INT N_total_send = 0;
206207

207-
//printf("System B: %i %lf %lf %lf %i\n",s.N_local,s.x(21,0),s.x(21,1),s.x(21,2),s.type(21));
208208
for(phase = 0; phase < 6; phase ++) {
209209
proc_num_send[phase] = 0;
210210
proc_num_recv[phase] = 0;
@@ -390,7 +390,8 @@ void CommMPI::exchange_halo() {
390390
};
391391

392392
void CommMPI::update_halo() {
393-
#ifndef SHMEMTESTS_USE_HALO
393+
394+
#if !defined(SHMEMTESTS_USE_HALO) && defined(EXAMINIMD_ENABLE_KOKKOS_REMOTE_SPACES)
394395
return;
395396
#else
396397
Kokkos::Profiling::pushRegion("Comm::update_halo");
@@ -478,7 +479,13 @@ void CommMPI::update_force() {
478479
Kokkos::Profiling::popRegion();
479480
};
480481

481-
const char* CommMPI::name() { return "CommMPI"; }
482+
const char* CommMPI::name() {
483+
comm_name = std::string("CommMPI");
484+
#ifdef EXAMINIMD_ENABLE_KOKKOS_REMOTE_SPACES
485+
comm_name += "Distrib";
486+
#endif
487+
return comm_name.c_str();
488+
}
482489

483490
int CommMPI::process_rank() { return proc_rank; }
484491
int CommMPI::num_processes() { return proc_size; }

src/comm_types/comm_mpi.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ class CommMPI: public Comm {
7070
System s;
7171

7272
// Owned Variables
73-
7473
int phase; // Communication Phase
7574
int proc_neighbors_recv[6]; // Neighbor for each phase
7675
int proc_neighbors_send[6]; // Neighbor for each phase
@@ -81,6 +80,8 @@ class CommMPI: public Comm {
8180
int proc_rank; // My Process rank
8281
int proc_size; // Number of processes
8382

83+
std::string comm_name;
84+
8485
T_INT num_ghost[6];
8586
T_INT ghost_offsets[6];
8687

@@ -503,7 +504,9 @@ class CommMPI: public Comm {
503504
KOKKOS_INLINE_FUNCTION
504505
void operator() (const TagCreateGlobalIndecies,
505506
const T_INT& i) const {
507+
#ifdef EXAMINIMD_ENABLE_KOKKOS_REMOTE_SPACES
506508
s.global_index(i) = N_MAX_MASK * proc_rank + i;
509+
#endif
507510
}
508511

509512
const char* name();

src/comm_types/comm_serial.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
}
5353
#endif
5454

55-
5655
#if !defined(MODULES_OPTION_CHECK) && !defined(COMM_MODULES_INSTANTIATION)
5756
#ifndef COMM_SERIAL_H
5857
#define COMM_SERIAL_H

src/examinimd.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ void ExaMiniMD::init(int argc, char* argv[]) {
8383
#undef FORCE_MODULES_INSTANTIATION
8484
else comm->error("Invalid ForceType");
8585
for(int line = 0; line < input->force_coeff_lines.extent(0); line++) {
86-
//input->input_data.print_line(input->force_coeff_lines(line));
87-
//printf("init_coeff: %i %i\n",line,input->input_data.words_in_line(input->force_coeff_lines(line)));
8886
force->init_coeff(input->input_data.words_in_line(input->force_coeff_lines(line)),
8987
input->input_data.words[input->force_coeff_lines(line)]);
9088
}
@@ -108,7 +106,6 @@ void ExaMiniMD::init(int argc, char* argv[]) {
108106
if(neighbor)
109107
neighbor->comm_newton = input->comm_newton;
110108

111-
// system->print_particles();
112109
if(system->do_print) {
113110
printf("Using: %s %s %s %s\n",force->name(),neighbor->name(),comm->name(),binning->name());
114111
}
@@ -160,7 +157,7 @@ void ExaMiniMD::init(int argc, char* argv[]) {
160157
} else {
161158
printf("\n");
162159
printf("Step Temp E_pair TotEng CPU\n");
163-
printf(" %i %lf %lf %lf %lf\n",step,T,PE,PE+KE,0.0);
160+
printf("%i %lf %lf %lf %lf\n",step,T,PE,PE+KE,0.0);
164161
}
165162
}
166163
}
@@ -170,7 +167,6 @@ void ExaMiniMD::init(int argc, char* argv[]) {
170167

171168
if(input->correctnessflag)
172169
check_correctness(step);
173-
174170
}
175171

176172
void ExaMiniMD::run(int nsteps) {
@@ -190,7 +186,6 @@ void ExaMiniMD::run(int nsteps) {
190186

191187
// Timestep Loop
192188
for(int step = 1; step <= nsteps; step++ ) {
193-
194189
// Do first part of the verlet time step integration
195190
other_timer.reset();
196191
integrator->initial_integrate();
@@ -221,11 +216,12 @@ void ExaMiniMD::run(int nsteps) {
221216
neighbor->create_neigh_list(system,binning,force->half_neigh,false);
222217
neigh_time += neigh_timer.seconds();
223218
} else {
224-
// Exchange Halo
219+
// Exchange Halo data
225220
comm_timer.reset();
226221
comm->update_halo();
227222
comm_time += comm_timer.seconds();
228223
}
224+
Kokkos::Experimental::DefaultRemoteMemorySpace::fence();
229225

230226
// Zero out forces
231227
force_timer.reset();
@@ -260,7 +256,7 @@ void ExaMiniMD::run(int nsteps) {
260256
last_time = time;
261257
} else {
262258
double time = timer.seconds();
263-
printf(" %i %lf %lf %lf %lf\n",step, T, PE, PE+KE, timer.seconds());
259+
printf("%i %lf %lf %lf %lf\n",step, T, PE, PE+KE, timer.seconds());
264260
last_time = time;
265261
}
266262
}

0 commit comments

Comments
 (0)