COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
MPIType.h
Go to the documentation of this file.
1/****************************************************************/
2/* Parallel Combinatorial BLAS Library (for Graph Computations) */
3/* version 1.6 -------------------------------------------------*/
4/* date: 6/15/2017 ---------------------------------------------*/
5/* authors: Ariful Azad, Aydin Buluc --------------------------*/
6/****************************************************************/
7/*
8 Copyright (c) 2010-2017, The Regents of the University of California
9
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 THE SOFTWARE.
27 */
28
29
30#ifndef _MPI_TYPE_H
31#define _MPI_TYPE_H
32
33#include <iostream>
34#include <typeinfo>
35#include <map>
36#include <mpi.h>
37#include <stdint.h>
38
39namespace combblas {
40
41
42// A datatype cache inspired by (mostly copied from) Boost http://www.boost.org/LICENSE_1_0.txt)
43
47{
48 bool operator()(std::type_info const* lhs, std::type_info const* rhs) const
49 {
50 return lhs->before(*rhs);
51 }
52};
53
54
56{
57private:
58 typedef std::map<std::type_info const*,MPI_Datatype,type_info_compare> stored_map_type;
59 stored_map_type map;
60
61public:
62 void clear()
63 {
64 int is_finalized=0;
66 if (! is_finalized ) // do not free after call to MPI_FInalize
67 {
68 // ignore errors in the destructor
69 for (stored_map_type::iterator it=map.begin(); it != map.end(); ++it)
70 {
71 MPI_Type_free(&(it->second));
72 }
73 }
74 }
76 {
77 clear();
78 }
79 MPI_Datatype get(const std::type_info* t)
80 {
81 stored_map_type::iterator pos = map.find(t);
82 if (pos != map.end())
83 return pos->second;
84 else
85 return MPI_DATATYPE_NULL;
86 }
87
88 void set(const std::type_info* t, MPI_Datatype datatype)
89 {
90 map[t] = datatype;
91 }
92};
93
94
102extern MPIDataTypeCache mpidtc; // global variable
103// Global variables have program scope, which means they can be accessed everywhere in the program, and they are only destroyed when the program ends.
104
105template <typename T>
107{
108 std::type_info const* t = &typeid(T);
110
112 {
115 int myrank;
117 mpidtc.set(t, datatype);
118 }
119 return datatype;
120};
121
122template<> MPI_Datatype MPIType< signed char >( void );
123template<> MPI_Datatype MPIType< signed short int >( void );
124template<> MPI_Datatype MPIType< unsigned char >( void );
125template<> MPI_Datatype MPIType< unsigned short int >( void );
126template<> MPI_Datatype MPIType< int32_t >( void );
127template<> MPI_Datatype MPIType< uint32_t >( void );
128template<> MPI_Datatype MPIType< int64_t >( void );
129template<> MPI_Datatype MPIType< uint64_t >( void );
130template<> MPI_Datatype MPIType< float >( void );
131template<> MPI_Datatype MPIType< double >( void );
132template<> MPI_Datatype MPIType< long double >( void );
133template<> MPI_Datatype MPIType< bool >( void );
134
135
136
137}
138
139#endif
void set(const std::type_info *t, MPI_Datatype datatype)
Definition MPIType.h:88
MPI_Datatype get(const std::type_info *t)
Definition MPIType.h:79
MPI_Datatype MPIType< bool >(void)
Definition MPIType.cpp:84
MPI_Datatype MPIType< int32_t >(void)
Definition MPIType.cpp:56
MPI_Datatype MPIType< double >(void)
Definition MPIType.cpp:76
MPIDataTypeCache mpidtc
Definition MPIType.h:102
MPI_Datatype MPIType< long double >(void)
Definition MPIType.cpp:80
MPI_Datatype MPIType< unsigned short int >(void)
Definition MPIType.cpp:52
MPI_Datatype MPIType(void)
Definition MPIType.h:106
MPI_Datatype MPIType< unsigned char >(void)
Definition MPIType.cpp:44
MPI_Datatype MPIType< signed short int >(void)
Definition MPIType.cpp:48
MPI_Datatype MPIType< int64_t >(void)
Definition MPIType.cpp:64
MPI_Datatype MPIType< signed char >(void)
Definition MPIType.cpp:40
MPI_Datatype MPIType< float >(void)
Definition MPIType.cpp:72
MPI_Datatype MPIType< uint64_t >(void)
Definition MPIType.cpp:68
MPI_Datatype MPIType< uint32_t >(void)
Definition MPIType.cpp:60
comparison function object for two std::type_info pointers is implemented using the before() member f...
Definition MPIType.h:47
bool operator()(std::type_info const *lhs, std::type_info const *rhs) const
Definition MPIType.h:48