GADGET-4
mpi_types.cc
Go to the documentation of this file.
1 /*******************************************************************************
2  * \copyright This file is part of the GADGET4 N-body/SPH code developed
3  * \copyright by Volker Springel. Copyright (C) 2014-2020 by Volker Springel
4  * \copyright (vspringel@mpa-garching.mpg.de) and all contributing authors.
5  *******************************************************************************/
6 
12 #include "gadgetconfig.h"
13 
14 #include <math.h>
15 #include <mpi.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 
20 #include "../data/allvars.h"
21 #include "../data/dtypes.h"
22 #include "../mpi_utils/mpi_utils.h"
23 
24 static void min_MPI_MyIntPosType(void *in, void *inout, int *len, MPI_Datatype *type)
25 {
26  /* we here trust that this is called only for the correct type */
27 
28  MyIntPosType *invalues = (MyIntPosType *)in;
29  MyIntPosType *inoutvalues = (MyIntPosType *)inout;
30 
31  for(int i = 0; i < *len; i++)
32  if(invalues[i] < inoutvalues[i])
33  inoutvalues[i] = invalues[i];
34 }
35 
36 static void max_MPI_MyIntPosType(void *in, void *inout, int *len, MPI_Datatype *type)
37 {
38  /* we here trust that this is called only for the correct type */
39 
40  MyIntPosType *invalues = (MyIntPosType *)in;
41  MyIntPosType *inoutvalues = (MyIntPosType *)inout;
42 
43  for(int i = 0; i < *len; i++)
44  if(invalues[i] > inoutvalues[i])
45  inoutvalues[i] = invalues[i];
46 }
47 
48 static void min_MPI_MySignedIntPosType(void *in, void *inout, int *len, MPI_Datatype *type)
49 {
50  /* we here trust that this is called only for the correct type */
51 
52  MySignedIntPosType *invalues = (MySignedIntPosType *)in;
53  MySignedIntPosType *inoutvalues = (MySignedIntPosType *)inout;
54 
55  for(int i = 0; i < *len; i++)
56  if(invalues[i] < inoutvalues[i])
57  inoutvalues[i] = invalues[i];
58 }
59 
60 static void max_MPI_MySignedIntPosType(void *in, void *inout, int *len, MPI_Datatype *type)
61 {
62  /* we here trust that this is called only for the correct type */
63 
64  MySignedIntPosType *invalues = (MySignedIntPosType *)in;
65  MySignedIntPosType *inoutvalues = (MySignedIntPosType *)inout;
66 
67  for(int i = 0; i < *len; i++)
68  if(invalues[i] > inoutvalues[i])
69  inoutvalues[i] = invalues[i];
70 }
71 
73 {
74  /* create our new data type */
75  MPI_Type_contiguous(sizeof(MyIntPosType), MPI_BYTE, &MPI_MyIntPosType);
76  MPI_Type_commit(&MPI_MyIntPosType);
77 
78  /* create our operators */
79  MPI_Op_create(min_MPI_MyIntPosType, 1, &MPI_MIN_MyIntPosType);
80  MPI_Op_create(max_MPI_MyIntPosType, 1, &MPI_MAX_MyIntPosType);
81  MPI_Op_create(min_MPI_MySignedIntPosType, 1, &MPI_MIN_MySignedIntPosType);
82  MPI_Op_create(max_MPI_MySignedIntPosType, 1, &MPI_MAX_MySignedIntPosType);
83 }
uint32_t MyIntPosType
Definition: dtypes.h:35
int32_t MySignedIntPosType
Definition: dtypes.h:36
void my_mpi_types_init(void)
Definition: mpi_types.cc:72
MPI_Datatype MPI_MyIntPosType
Definition: mpi_vars.cc:24
MPI_Op MPI_MAX_MySignedIntPosType
Definition: mpi_vars.cc:29
MPI_Op MPI_MIN_MySignedIntPosType
Definition: mpi_vars.cc:28
MPI_Op MPI_MAX_MyIntPosType
Definition: mpi_vars.cc:27
MPI_Op MPI_MIN_MyIntPosType
Definition: mpi_vars.cc:26