TIMPI
Loading...
Searching...
No Matches
attributes.h
Go to the documentation of this file.
1// The TIMPI Message-Passing Parallelism Library.
2// Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
19#ifndef TIMPI_ATTRIBUTES_H
20#define TIMPI_ATTRIBUTES_H
21
22// TIMPI includes
23#include "timpi/timpi_config.h"
24
25// Boost include if necessary for float128
26#ifdef TIMPI_DEFAULT_QUADRUPLE_PRECISION
27# include <boost/multiprecision/float128.hpp>
28#endif
29
30// C++ includes
31#include <limits>
32#include <set>
33#include <vector>
34
35namespace TIMPI
36{
37//-------------------------------------------------------------------
38
39/*
40 * The unspecialized class gives default, lowest-common-denominator
41 * attributes, for values which can't be used with Parallel min/max.
42 * Specialized classes can set this to true, and should define
43 * the lowest and highest values possible for the type.
44 */
45template<typename T>
47{
48 static const bool has_min_max = false;
49 /*
50 static void set_lowest(T & x) { x = as_low_as_it_can_be; }
51 static void set_highest(T & x) { x = as_high_as_it_can_be; }
52 */
53};
54
55// ------------------------------------------------------------
56// Declare Attributes specializations for C++ built-in types
57
58#define TIMPI_INT_TYPE(cxxtype) \
59 template<> \
60 struct Attributes<cxxtype> \
61 { \
62 static const bool has_min_max = true; \
63 static void set_lowest(cxxtype & x) { x = std::numeric_limits<cxxtype>::min(); } \
64 static void set_highest(cxxtype & x) { x = std::numeric_limits<cxxtype>::max(); } \
65 }
66
67#define TIMPI_FLOAT_TYPE(cxxtype) \
68 template<> \
69 struct Attributes<cxxtype> \
70 { \
71 static const bool has_min_max = true; \
72 static void set_lowest(cxxtype & x) { x = -std::numeric_limits<cxxtype>::infinity(); } \
73 static void set_highest(cxxtype & x) { x = std::numeric_limits<cxxtype>::infinity(); } \
74 }
75
76#define TIMPI_CONTAINER_TYPE(cxxtype) \
77 struct Attributes<cxxtype> \
78 { \
79 static const bool has_min_max = Attributes<T>::has_min_max; \
80 static void set_lowest(cxxtype & x) { \
81 for (auto & val : x) \
82 Attributes<T>::set_lowest(val); } \
83 static void set_highest(cxxtype & x) { \
84 for (auto & val : x) \
85 Attributes<T>::set_highest(val); } \
86 }
87
88
90TIMPI_INT_TYPE(signed char);
91TIMPI_INT_TYPE(unsigned char);
92TIMPI_INT_TYPE(short int);
93TIMPI_INT_TYPE(unsigned short int);
95TIMPI_INT_TYPE(unsigned int);
97TIMPI_INT_TYPE(long long);
98TIMPI_INT_TYPE(unsigned long);
99TIMPI_INT_TYPE(unsigned long long);
100
103TIMPI_FLOAT_TYPE(long double);
104#ifdef TIMPI_DEFAULT_QUADRUPLE_PRECISION
106#endif
107
108#define TIMPI_ATTRIBUTES_COMMA ,
109
110template <typename T, typename C, typename A>
111TIMPI_CONTAINER_TYPE(std::set<T TIMPI_ATTRIBUTES_COMMA C TIMPI_ATTRIBUTES_COMMA A>);
112
113template <typename T, typename A>
114TIMPI_CONTAINER_TYPE(std::vector<T TIMPI_ATTRIBUTES_COMMA A>);
115
116} // namespace TIMPI
117
118#endif // TIMPI_ATTRIBUTES_H
TIMPI_FLOAT_TYPE(float)
TIMPI_CONTAINER_TYPE(std::set< T TIMPI_ATTRIBUTES_COMMA C TIMPI_ATTRIBUTES_COMMA A >)
Tnew cast_int(Told oldvar)
TIMPI_INT_TYPE(char)
static const bool has_min_max
Definition attributes.h:48