Neko 0.9.99
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
device_mpi.c
Go to the documentation of this file.
1/*
2 Copyright (c) 2022-2023, The Neko Authors
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above
13 copyright notice, this list of conditions and the following
14 disclaimer in the documentation and/or other materials provided
15 with the distribution.
16
17 * Neither the name of the authors nor the names of its
18 contributors may be used to endorse or promote products derived
19 from this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33*/
34
40#include <stdlib.h>
41#include <mpi.h>
42#ifdef _OPENMP
43#include <omp.h>
44#endif
45
46#include <comm/comm.h>
47
48void device_mpi_init_reqs(int n, void **reqs_out) {
49 MPI_Request *reqs = malloc(n * sizeof(MPI_Request));
50 *reqs_out = reqs;
51}
52
53void device_mpi_free_reqs(void **reqs) {
54 free(*reqs);
55 *reqs = NULL;
56}
57
58void device_mpi_isend(void *buf_d, int offset, int nbytes, int rank,
59 void *vreqs, int i) {
60 MPI_Request *reqs = vreqs;
61#ifdef _OPENMP
62 int tid = omp_get_thread_num();
63#else
64 int tid = 0;
65#endif
66 MPI_Isend(buf_d+offset, nbytes, MPI_BYTE, rank, tid, NEKO_COMM, &reqs[i-1]);
67}
68
69void device_mpi_irecv(void *buf_d, int offset, int nbytes, int rank,
70 void *vreqs, int i) {
71 MPI_Request *reqs = vreqs;
72#ifdef _OPENMP
73 int tid = omp_get_thread_num();
74#else
75 int tid = 0;
76#endif
77
78 MPI_Irecv(buf_d+offset, nbytes, MPI_BYTE, rank, tid, NEKO_COMM, &reqs[i-1]);
79}
80
81int device_mpi_test(void *vreqs, int i) {
82 MPI_Request *reqs = vreqs;
83 int flag = 0;
84 MPI_Test(&reqs[i-1], &flag, MPI_STATUS_IGNORE);
85 return flag;
86}
87
88void device_mpi_waitall(int n, void *vreqs) {
89 MPI_Request *reqs = vreqs;
91}
92
93int device_mpi_waitany(int n, void *vreqs, int *i) {
94 MPI_Request *reqs = vreqs;
95 int j;
97 if (j == MPI_UNDEFINED) {
98 return 0;
99 } else {
100 *i = j + 1;
101 return 1;
102 }
103}
MPI_Comm NEKO_COMM
const int i
const int j
__global__ void dirichlet_apply_scalar_kernel(const int *__restrict__ msk, T *__restrict__ x, const T g, const int m)
void device_mpi_init_reqs(int n, void **reqs_out)
Definition device_mpi.c:48
void device_mpi_isend(void *buf_d, int offset, int nbytes, int rank, void *vreqs, int i)
Definition device_mpi.c:58
int device_mpi_test(void *vreqs, int i)
Definition device_mpi.c:81
void device_mpi_waitall(int n, void *vreqs)
Definition device_mpi.c:88
void device_mpi_irecv(void *buf_d, int offset, int nbytes, int rank, void *vreqs, int i)
Definition device_mpi.c:69
void device_mpi_free_reqs(void **reqs)
Definition device_mpi.c:53
int device_mpi_waitany(int n, void *vreqs, int *i)
Definition device_mpi.c:93