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