Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
mpiconversion.h
Go to the documentation of this file.
1/*
2 * This file is part of Vlasiator.
3 * Copyright 2010-2016 Finnish Meteorological Institute
4 *
5 * For details of usage, see the COPYING file and read the "Rules of the Road"
6 * at http://www.physics.helsinki.fi/vlasiator/
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#ifndef MPI_CONVERSION_H
24#define MPI_CONVERSION_H
25#include <mpi.h>
26#include <cstdlib>
27#include <iostream>
28#include <stdint.h>
29
30// Overloaded templates which return the corresponding data type
31// for C++ native data types. For example, if float has been
32// typedef'd as Real, then MPI_Type<Real>() should return MPI_FLOAT.
33// If you later on change the typedef to double, MPI_Type<Real>()
34// still works.
35template<typename T> inline MPI_Datatype MPI_Type() {
36 std::cerr << "(mpiconversion.h): NULL datatype returned, byte size of original is " << sizeof(T) << std::endl;
37 exit(1);
38 return 0;
39}
40
41template<> inline MPI_Datatype MPI_Type<char>() {return MPI_CHAR;}
42
43// Signed integer types
44template<> inline MPI_Datatype MPI_Type<signed char>() {return MPI_CHAR;}
45template<> inline MPI_Datatype MPI_Type<short>() {return MPI_SHORT;}
46template<> inline MPI_Datatype MPI_Type<int>() {return MPI_INT;}
47template<> inline MPI_Datatype MPI_Type<long int>() {return MPI_LONG;}
48template<> inline MPI_Datatype MPI_Type<long long int>() {return MPI_LONG_LONG;}
49
50// Unsigned integer types
51template<> inline MPI_Datatype MPI_Type<unsigned char>() {return MPI_UNSIGNED_CHAR;}
52template<> inline MPI_Datatype MPI_Type<unsigned short>() {return MPI_UNSIGNED_SHORT;}
53template<> inline MPI_Datatype MPI_Type<unsigned int>() {return MPI_UNSIGNED;}
54template<> inline MPI_Datatype MPI_Type<unsigned long int>() {return MPI_UNSIGNED_LONG;}
55template<> inline MPI_Datatype MPI_Type<unsigned long long int>() {return MPI_UNSIGNED_LONG_LONG;}
56
57// Floating point types
58template<> inline MPI_Datatype MPI_Type<float>() {return MPI_FLOAT;}
59template<> inline MPI_Datatype MPI_Type<double>() {return MPI_DOUBLE;}
60template<> inline MPI_Datatype MPI_Type<long double>() {return MPI_LONG_DOUBLE;}
61
62#endif
63
MPI_Datatype MPI_Type< signed char >()
MPI_Datatype MPI_Type< int >()
MPI_Datatype MPI_Type< long int >()
MPI_Datatype MPI_Type< unsigned char >()
MPI_Datatype MPI_Type< unsigned long int >()
MPI_Datatype MPI_Type< short >()
MPI_Datatype MPI_Type()
MPI_Datatype MPI_Type< unsigned short >()
MPI_Datatype MPI_Type< float >()
MPI_Datatype MPI_Type< long long int >()
MPI_Datatype MPI_Type< char >()
MPI_Datatype MPI_Type< long double >()
MPI_Datatype MPI_Type< double >()
MPI_Datatype MPI_Type< unsigned long long int >()
MPI_Datatype MPI_Type< unsigned int >()