|
| 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 ([email protected]) |
| 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 | +} |
0 commit comments