Muster
 All Classes Namespaces Files Functions Variables Typedefs Macros
mpi_utils.h
Go to the documentation of this file.
1 #ifndef MPI_UTILS_H
2 #define MPI_UTILS_H
3 ///
4 /// @file mpi_utils.h
5 /// @brief Overloaded utility functions to convert between arbitrary C/C++
6 /// types and MPI types, custom typedefs for cstdlib types like size_t,
7 /// and a wrapper for MPI_Pack_Size
8 ///
9 
10 #include <iostream>
11 #include <cstdlib>
12 #include <stdint.h>
13 #include <mpi.h>
14 
15 //
16 // Overloaded functions for getting corresponding MPI types for C types.
17 //
18 inline MPI_Datatype mpi_typeof(char) {return MPI_CHAR;}
19 inline MPI_Datatype mpi_typeof(signed short) {return MPI_SHORT;}
20 inline MPI_Datatype mpi_typeof(signed int) {return MPI_INT;}
21 inline MPI_Datatype mpi_typeof(signed long) {return MPI_LONG;}
22 inline MPI_Datatype mpi_typeof(unsigned char) {return MPI_UNSIGNED_CHAR;}
23 inline MPI_Datatype mpi_typeof(unsigned short) {return MPI_UNSIGNED_SHORT;}
24 inline MPI_Datatype mpi_typeof(unsigned) {return MPI_UNSIGNED;}
25 inline MPI_Datatype mpi_typeof(unsigned long) {return MPI_UNSIGNED_LONG;}
26 inline MPI_Datatype mpi_typeof(signed long long) {return MPI_LONG_LONG_INT;}
27 inline MPI_Datatype mpi_typeof(double) {return MPI_DOUBLE;}
28 inline MPI_Datatype mpi_typeof(long double) {return MPI_LONG_DOUBLE;}
29 inline MPI_Datatype mpi_typeof(std::pair<int,int>) {return MPI_2INT;}
30 inline MPI_Datatype mpi_typeof(std::pair<float,int>) {return MPI_FLOAT_INT;}
31 inline MPI_Datatype mpi_typeof(std::pair<double,int>) {return MPI_DOUBLE_INT;}
32 inline MPI_Datatype mpi_typeof(std::pair<long double,int>) {return MPI_LONG_DOUBLE_INT;}
33 inline MPI_Datatype mpi_typeof(std::pair<short,int>) {return MPI_SHORT_INT;}
34 
35 //
36 // Handy datatypes for stdlib datatypes
37 // @todo these won't work in heterogeneous environments, as it's tied to the machine type.
38 //
39 #define MPI_SIZE_T (mpi_typeof(size_t()))
40 #define MPI_INTPTR_T (mpi_typeof(intptr_t()))
41 #define MPI_UINTPTR_T (mpi_typeof(uintptr_t()))
42 
43 ///
44 /// Expression-ifies the overly C-ish MPI_Pack_size function. Just returns
45 /// the size instead of requring a temporary.
46 ///
47 inline int mpi_packed_size(int count, MPI_Datatype type, MPI_Comm comm) {
48  int size;
49  MPI_Pack_size(count, type, comm, &size);
50  return size;
51 }
52 
53 ///
54 /// PMPI binding for mpi_packed_size().
55 ///
56 inline int pmpi_packed_size(int count, MPI_Datatype type, MPI_Comm comm) {
57  int size;
58  PMPI_Pack_size(count, type, comm, &size);
59  return size;
60 }
61 
62 
63 #endif // MPI_UTILS_H
int pmpi_packed_size(int count, MPI_Datatype type, MPI_Comm comm)
PMPI binding for mpi_packed_size().
Definition: mpi_utils.h:56
MPI_Datatype mpi_typeof(char)
Definition: mpi_utils.h:18
int mpi_packed_size(int count, MPI_Datatype type, MPI_Comm comm)
Expression-ifies the overly C-ish MPI_Pack_size function.
Definition: mpi_utils.h:47
Muster. Copyright © 2010, Lawrence Livermore National Laboratory, LLNL-CODE-433662.
Distribution of Muster and its documentation is subject to terms of the Muster LICENSE.
Generated on Thu Sep 1 2016 using Doxygen 1.8.5