SST 16.0.0
Structural Simulation Toolkit
sst_mpi.h
1// Copyright 2009-2026 NTESS. Under the terms
2// of Contract DE-NA0003525 with NTESS, the U.S.
3// Government retains certain rights in this software.
4//
5// Copyright (c) 2009-2026, NTESS
6// All rights reserved.
7//
8// This file is part of the SST software package. For license
9// information, see the LICENSE file in the top level directory of the
10// distribution.
11
12#ifndef SST_CORE_SST_MPI_H
13#define SST_CORE_SST_MPI_H
14
15#include "warnmacros.h"
16
17#ifdef SST_CONFIG_HAVE_MPI
18
19DISABLE_WARN_MISSING_OVERRIDE
20DISABLE_WARN_CAST_FUNCTION_TYPE
21
22#include <mpi.h>
23
24REENABLE_WARNING
25REENABLE_WARNING
26
27#define UNUSED_WO_MPI(x) x
28
29#else
30
31#define UNUSED_WO_MPI(x) UNUSED(x)
32
33#endif
34
35/*************************************************************************
36 Make it so that we can do simple MPI functions without having to
37 guard using SST_CONFIG_HAVE_MPI. This will include SST_MPI_*
38 versions of the supported operations, as well as definitions for
39 some of the MPI types
40 *************************************************************************/
41
43{
44 short val;
45 int rank;
46};
47
49{
50 long val;
51 int rank;
52};
53
55{
56 double val;
57 int rank;
58};
59
61{
62 double val;
63 int rank;
64};
65
66#ifndef SST_CONFIG_HAVE_MPI
67
68// Define some MPI types and some of the values for those types
69#define MPI_Datatype int
70#define MPI_Op int
71#define MPI_Comm int
72
73#define MPI_COMM_WORLD 0
74
75// MPI_datatype values. These will just be set to the sizeof() the represented type
76
77#define MPI_SIGNED_CHAR (sizeof(signed char))
78#define MPI_UNSIGNED_CHAR (sizeof(unsigned char))
79#define MPI_SHORT (sizeof(short))
80#define MPI_UNSIGNED_SHORT (sizeof(unsigned short))
81#define MPI_INT (sizeof(int))
82#define MPI_UNSIGNED (sizeof(unsigned))
83#define MPI_LONG (sizeof(long))
84#define MPI_UNSIGNED_LONG (sizeof(unsigned long))
85// MPI_LONG_LONG_INT (a.k.a MPI_LONG_LONG) / MPI_UNSIGNED_LONG_LONG
86#define MPI_CHAR (sizeof(char))
87#define MPI_WCHAR (sizeof(wchar))
88#define MPI_FLOAT (sizeof(float))
89#define MPI_DOUBLE (sizeof(double))
90// MPI_LONG_DOUBLE
91#define MPI_INT8_T (sizeof(int8_t))
92#define MPI_UINT8_T (sizeof(uint8_t))
93#define MPI_INT16_T (sizeof(int16_t))
94#define MPI_UINT16_T (sizeof(uint16_t))
95#define MPI_INT32_T (sizeof(int32_t))
96#define MPI_UINT32_T (sizeof(uint32_t))
97#define MPI_INT64_T (sizeof(int64_t))
98#define MPI_UINT64_T (sizeof(uint64_t))
99#define MPI_C_BOOL
100// MPI_C_COMPLEX
101// MPI_C_FLOAT_COMPLEX
102// MPI_C_DOUBLE_COMPLEX
103// MPI_C_LONG_DOUBLE_COMPLEX
104// MPI_AINT
105// MPI_COUNT
106// MPI_OFFSET
107// MPI_BYTE
108// MPI_PACKED
109
110// List of datatypes for reduction functions MPI_MINLOC and MPI_MAXLOC:
111#define MPI_SHORT_INT (sizeof(mpi_short_int_t))
112#define MPI_LONG_INT (sizeof(mpi_long_int_t))
113#define MPI_FLOAT_INT (sizeof(mpi_float_int_t))
114#define MPI_DOUBLE_INT (sizeof(mpi_double_int_t))
115// MPI_LONG_DOUBLE_INT
116// MPI_2INT
117
118// Allreduce operations. Numbers are unused because they are all
119// no-ops in the case of MPI
120#define MPI_SUM 0
121#define MPI_MAX 0
122#define MPI_MIN 0
123#define MPI_MAXLOC 0
124#define MPI_MINLOC 0
125
126#define MPI_Status int
127#define MPI_STATUS_IGNORE 0
128
129#endif
130
131///// Verions of typical MPI functions that will hide the SST_CONFIG_HAVE_MPI macros ////
132
133// These functions will generally copy the data from input to output and will behave as expected for a 1 rank MPI job
134// when MPI is not enabled
135int SST_MPI_Allreduce(const void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
136int SST_MPI_Allgather(const void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount,
137 MPI_Datatype recvtype, MPI_Comm comm);
138int SST_MPI_Bcast(void* buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm);
139
140// MPI_Barrier is a no-op when MPI is not enabled and can be safely called in that case
141int SST_MPI_Barrier(MPI_Comm comm);
142
143// MPI_Send and MPI_Recv are both no-ops if MPI is not present. However, they should be in segments of code that won't
144// get exectuted if MPI is not available (i.e. only run if there is more than one rank, controlled be either an
145// if-statement or for-loop, but this is generally also necessary even when MPI is enabled)
146int SST_MPI_Send(const void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm);
147int SST_MPI_Recv(void* buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status* status);
148
149int SST_MPI_GetRank();
150#endif
Definition sst_mpi.h:61
Definition sst_mpi.h:55
Definition sst_mpi.h:49
Definition sst_mpi.h:43