Skip to content

Commit 7fa5915

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

24 files changed

+829
-148
lines changed

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ if (ENABLE_KOKKOS_REMOTE_SPACES)
2020
target_compile_definitions(ExaMiniMD PRIVATE EXAMINIMD_ENABLE_KOKKOS_REMOTE_SPACES)
2121
target_compile_definitions(ExaMiniMD PRIVATE SHMEMTESTS_USE_SCALAR)
2222
#target_compile_definitions(ExaMiniMD PRIVATE SHMEMTESTS_USE_HALO)
23+
#target_compile_definitions(ExaMiniMD PRIVATE SHMEMTESTS_USE_HALO_LOCAL)
24+
#target_compile_definitions(ExaMiniMD PRIVATE SHMEMTESTS_USE_LOCAL_GLOBAL)
2325
target_compile_definitions(ExaMiniMD PRIVATE SHMEMTESTS_USE_GLOBAL)
2426
endif()
2527

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 & 2 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

@@ -390,7 +392,8 @@ void CommMPI::exchange_halo() {
390392
};
391393

392394
void CommMPI::update_halo() {
393-
#ifndef SHMEMTESTS_USE_HALO
395+
396+
#if !defined(SHMEMTESTS_USE_HALO) && defined(EXAMINIMD_ENABLE_KOKKOS_REMOTE_SPACES)
394397
return;
395398
#else
396399
Kokkos::Profiling::pushRegion("Comm::update_halo");
@@ -478,7 +481,13 @@ void CommMPI::update_force() {
478481
Kokkos::Profiling::popRegion();
479482
};
480483

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

483492
int CommMPI::process_rank() { return proc_rank; }
484493
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ void ExaMiniMD::run(int nsteps) {
221221
neighbor->create_neigh_list(system,binning,force->half_neigh,false);
222222
neigh_time += neigh_timer.seconds();
223223
} else {
224-
// Exchange Halo
224+
// Exchange Halo data
225225
comm_timer.reset();
226226
comm->update_halo();
227227
comm_time += comm_timer.seconds();

src/force_types/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
FILE(GLOB SRCS *.cpp)
22

3-
4-
#Skip lj_ideal, snap and cell
3+
#Skip snap and cell
54
#TODO: SNAP is outdates and should likely be removed all together as it is
65
list(FILTER SRCS EXCLUDE REGEX ".*lj_cell\\.cpp$")
7-
list(FILTER SRCS EXCLUDE REGEX ".*lj_idial_neigh\\.cpp$")
86
list(FILTER SRCS EXCLUDE REGEX ".*snap_neigh\\.cpp$")
97

10-
target_sources(ExaMiniMD PRIVATE ${SRCS})
8+
# Skip force-type module if Kokkos Remote Spaces is not enabled
9+
if (ENABLE_KOKKOS_REMOTE_SPACES)
10+
message(STATUS "Building with support for force_lj_neigh_distrib")
11+
else()
12+
#Otherwise exclude
13+
list(FILTER SRCS EXCLUDE REGEX ".*distrib\\.cpp$")
14+
endif()
1115

16+
target_sources(ExaMiniMD PRIVATE ${SRCS})

src/force_types/force_lj_neigh.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
//************************************************************************
3838

3939
#include<force_lj_neigh_impl.h>
40-
4140
#define FORCETYPE_DECLARE_TEMPLATE_MACRO(NeighType) ForceLJNeigh<NeighType>
4241
#define FORCE_MODULES_TEMPLATE
4342
#include<modules_neighbor.h>

0 commit comments

Comments
 (0)