FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
dist.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
12#include <kernel/util/binary_stream.hpp>
13#include <kernel/util/type_traits.hpp>
14
15// includes, system
16#include <algorithm>
17#include <mutex>
18#include <type_traits>
19#include <typeindex>
20#include <unordered_map>
21#include <vector>
22#include <sstream>
23
24// includes, MPI
25#ifdef FEAT_HAVE_MPI
26#include <mpi.h>
27#endif // FEAT_HAVE_MPI
28
29namespace FEAT
30{
37 namespace Dist
38 {
57 bool initialize(int& argc, char**& argv);
58
69 void finalize();
70
79 struct Datatype
80 {
81#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
83 MPI_Datatype dt;
85 std::size_t bytes;
86
96 explicit Datatype(MPI_Datatype dt_, std::size_t bytes_) : dt(dt_), bytes(bytes_) {}
97#else
98 private:
99 int dt;
100 std::size_t bytes;
101
102 public:
103 explicit Datatype(int dt_, std::size_t bytes_) : dt(dt_), bytes(bytes_) {}
104#endif // FEAT_HAVE_MPI
105
106 public:
108 bool operator==(const Datatype& other) const
109 {
110 return this->dt == other.dt;
111 }
112
114 bool operator!=(const Datatype& other) const
115 {
116 return this->dt != other.dt;
117 }
118
122 std::size_t size() const
123 {
124 return bytes;
125 }
126 }; // class Datatype
127
129 extern const Datatype dt_byte;
131 extern const Datatype dt_char;
133 extern const Datatype dt_wchar;
155 extern const Datatype dt_float;
157 extern const Datatype dt_double;
177 extern const Datatype dt_packed;
178
179#if defined(FEAT_HAVE_QUADMATH) || defined(DOXYGEN)
181 extern const Datatype dt__float128;
182#endif
183
184#if defined(FEAT_HAVE_HALFMATH) || defined(DOXYGEN)
186 extern const Datatype dt__half;
187#endif
188
200 template<typename T_> const Datatype& autotype();
201
202
228 {
230 friend class TypeRegistry;
231
233 std::vector<int> _blocklengths;
235 std::vector<std::size_t> _displacements;
237 std::vector<Dist::Datatype> _types;
238
239 public:
241 Typemap() = default;
242
258 template<typename T_>
259 Typemap& add_entry(std::size_t displacement, int blocklength = 1)
260 {
261 return add_entry(displacement, Dist::autotype<T_>(), blocklength);
262 }
263
278 Typemap& add_entry(std::size_t displacement, const Dist::Datatype& type, int blocklength = 1)
279 {
280 XASSERT(blocklength > 0);
281
282 _blocklengths.push_back(blocklength);
283 _displacements.push_back(displacement);
284 _types.push_back(type);
285
286 return *this;
287 }
288
290 std::size_t count() const noexcept
291 {
292 return _blocklengths.size();
293 }
294 }; // class Typemap
295
312 template<typename T_>
314 {
317 {
318 return T_::typemap();
319 }
320 };
321
334 class TypeRegistry //NOLINT
335 {
337 std::unordered_map<std::type_index, Datatype> _types;
338
339 // NOTE(mmuegge): A recursive mutex is required here
340 // because get_type might call itself if the typemap
341 // for a type requires creating other types first.
342 // Creating a Datatype for Tiny::Matrix for example
343 // triggers creation of a Tiny::Vector Datatype first.
344
346 std::recursive_mutex _mutex;
347
348#ifndef FEAT_HAVE_MPI
349 // In non-MPI builds Datatypes contain an id, rather than
350 // a handle. We assign ids starting at 1024.
351 int next_mock_id = 1024;
352#endif
353
354 // Constructor is hidden to ensure this class is a singleton
356 TypeRegistry() = default;
357
358 public:
360 TypeRegistry(const TypeRegistry& other) = delete;
362 TypeRegistry(TypeRegistry&& other) = delete;
363
365 void operator=(const TypeRegistry& other) = delete;
367 void operator=(TypeRegistry&& other) = delete;
368
370 static TypeRegistry& instance() noexcept
371 {
372 static TypeRegistry instance;
373 return instance;
374 }
375
376#ifdef FEAT_HAVE_MPI
378 template<typename T_>
379 const Datatype& get_type()
380 {
381 // NOTE(mmuegge): The offsetof macro is only defined for "standard layout types".
382 // Any other way to take offsets is probably highly compiler dependent or UB.
383 static_assert(std::is_standard_layout_v<T_>, "MPI typemaps require standard-layout types!");
384
385 std::scoped_lock<std::recursive_mutex> lock(_mutex);
386
387 const std::type_index idx(typeid(T_));
388
389 const auto it = _types.find(idx);
390 if(it == _types.end())
391 {
392 // Type does not exist yet. Create it.
394
395 XASSERTM(desc.count() > 0, "TypeRegistry::get_type: empty typemap!");
396
397 // Unpack wrapped mpi types
398 std::vector<MPI_Datatype> mpi_types;
399 mpi_types.reserve(desc.count());
400 std::transform(
401 desc._types.begin(),
402 desc._types.end(),
403 std::back_inserter(mpi_types),
404 [](const Datatype& d) { return d.dt; });
405
406 // Cast displacements to correct type
407 std::vector<MPI_Aint> displacements;
408 displacements.reserve(desc.count());
409 std::transform(
410 desc._displacements.begin(),
411 desc._displacements.end(),
412 std::back_inserter(displacements),
413 [](const std::size_t d) { return static_cast<MPI_Aint>(d); });
414
415 // Create temporary type
416 MPI_Datatype tmptype;
417 MPI_Type_create_struct(static_cast<int>(desc.count()), desc._blocklengths.data(), displacements.data(), mpi_types.data(), &tmptype);
418
419 // The temporary might be smaller than the actual type T_, because there might be padding at the end of T_.
420 // That would lead to issues when sending multiple T_s.
421 // Resize the type to include padding.
422 MPI_Datatype newtype;
423 MPI_Type_create_resized(tmptype, 0, sizeof(T_), &newtype);
424
425 // Commit type
426 MPI_Type_commit(&newtype);
427
428 // Free temporary type
429 MPI_Type_free(&tmptype);
430
431 // Store type for later
432 const auto [iter, _] = _types.try_emplace(idx, Datatype(newtype, sizeof(T_)));
433
434 return iter->second;
435 }
436 else
437 {
438 return it->second;
439 }
440 }
441
445 void free()
446 {
447 std::scoped_lock<std::recursive_mutex> lock(_mutex);
448
449 for(auto& [_, dt] : _types)
450 {
451 MPI_Type_free(&dt.dt);
452 }
453 _types.clear();
454 }
455#else
457 template<typename T_>
459 {
460 std::scoped_lock<std::recursive_mutex> lock(_mutex);
461
462 const std::type_index idx(typeid(T_));
463
464 auto it = _types.find(idx);
465 if(it == _types.end())
466 {
467 const auto [iter, _] = _types.try_emplace(idx, Datatype(next_mock_id++, sizeof(T_)));
468 return iter->second;
469 }
470 else
471 {
472 return it->second;
473 }
474
475 return _types.at(idx);
476 }
477
481 void free()
482 {
483 std::scoped_lock<std::recursive_mutex> lock(_mutex);
484 _types.clear();
485 }
486#endif
487 };
488
489 template<typename T_>
491 {
492 return TypeRegistry::instance().get_type<T_>();
493 }
494
496 template<> inline const Datatype& autotype<char>() {return dt_char;}
497 template<> inline const Datatype& autotype<wchar_t>() {return dt_wchar;}
498 template<> inline const Datatype& autotype<signed char>() {return dt_signed_char;}
499 template<> inline const Datatype& autotype<signed short>() {return dt_signed_short;}
500 template<> inline const Datatype& autotype<signed int>() {return dt_signed_int;}
501 template<> inline const Datatype& autotype<signed long>() {return dt_signed_long;}
502 template<> inline const Datatype& autotype<signed long long>() {return dt_signed_long_long;}
503 template<> inline const Datatype& autotype<unsigned char>() {return dt_unsigned_char;}
504 template<> inline const Datatype& autotype<unsigned short>() {return dt_unsigned_short;}
505 template<> inline const Datatype& autotype<unsigned int>() {return dt_unsigned_int;}
506 template<> inline const Datatype& autotype<unsigned long>() {return dt_unsigned_long;}
507 template<> inline const Datatype& autotype<unsigned long long>(){return dt_unsigned_long_long;}
508 template<> inline const Datatype& autotype<float>() {return dt_float;}
509 template<> inline const Datatype& autotype<double>() {return dt_double;}
510 template<> inline const Datatype& autotype<long double>() {return dt_long_double;}
511
512#if defined(FEAT_HAVE_QUADMATH) || defined(DOXYGEN)
513 template<> inline const Datatype& autotype<__float128>() {return dt__float128;}
514#endif
515
516#if defined(FEAT_HAVE_HALFMATH) || defined(DOXYGEN)
517 template<> inline const Datatype& autotype<__half>() {return dt__half;}
518#endif
519
521
522 /* ************************************************************************************************************* */
523 /* ************************************************************************************************************* */
524 /* ************************************************************************************************************* */
525 /* ************************************************************************************************************* */
526 /* ************************************************************************************************************* */
527
537 {
538#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
540 MPI_Op op;
541
548 explicit Operation(MPI_Op op_) : op(op_) {}
549#else
550 private:
551 int op;
552 public:
553 explicit Operation(int op_) : op(op_) {}
554#endif // FEAT_HAVE_MPI
555
556 public:
558 bool operator==(const Operation& other) const
559 {
560 return this->op == other.op;
561 }
562
564 bool operator!=(const Operation& other) const
565 {
566 return this->op != other.op;
567 }
568 }; // class Operation
569
571 extern const Operation op_sum;
573 extern const Operation op_max;
575 extern const Operation op_min;
576
577 /* ************************************************************************************************************* */
578 /* ************************************************************************************************************* */
579 /* ************************************************************************************************************* */
580 /* ************************************************************************************************************* */
581 /* ************************************************************************************************************* */
582
594 class Status
595 {
596#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
597 public:
599 MPI_Status status;
600
603 status()
604 {
605 status.MPI_SOURCE = MPI_PROC_NULL;
606 }
607
609 Status(const Status&) = default;
611 Status& operator=(const Status&) = default;
612
614 MPI_Status* mpi_status()
615 {
616 return &status;
617 }
618
624 bool is_null() const
625 {
626 return status.MPI_SOURCE == MPI_PROC_NULL;
627 }
628
632 int source() const
633 {
634 return status.MPI_SOURCE;
635 }
636
640 int tag() const
641 {
642 return status.MPI_TAG;
643 }
644
648 int error() const
649 {
650 return status.MPI_ERROR;
651 }
652
664 std::size_t get_count(const Datatype& datatype) const
665 {
666 int c(0);
667 MPI_Get_count(&status, datatype.dt, &c);
668 return std::size_t(c);
669 }
670
672 std::size_t get_size() const
673 {
674 int c(0);
675 MPI_Get_count(&status, MPI_BYTE, &c);
676 return std::size_t(c);
677 }
678#else // non-MPI implementation
679 public:
681 int status;
682
683 Status() :
684 status(0)
685 {
686 }
687
691 int source() const
692 {
693 return 0;
694 }
695#endif // FEAT_HAVE_MPI
696 }; // class Status
697
698#ifdef FEAT_HAVE_MPI
699 // Ensure that 'Status' is a POD container for 'MPI_Status',
700 // as this is required by the RequestVector class.
701 static_assert(sizeof(Status) == sizeof(MPI_Status), "invalid Status class size; class Status must be a POD");
702#endif
703
704 /* ************************************************************************************************************* */
705 /* ************************************************************************************************************* */
706 /* ************************************************************************************************************* */
707 /* ************************************************************************************************************* */
708 /* ************************************************************************************************************* */
709
731 {
732#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
733 public:
735 MPI_Request request;
736#else
737 private:
739 int request;
740#endif // FEAT_HAVE_MPI
741
742 public:
749 Request();
750
751#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
753 explicit Request(MPI_Request req_);
754
756 MPI_Request* mpi_request()
757 {
758 return &request;
759 }
760#endif // FEAT_HAVE_MPI
761
763 Request(const Request&) = delete;
765 Request& operator=(const Request&) = delete;
766
776 Request(Request&& other);
777
793 Request& operator=(Request&& other);
794
797 {
798 XASSERTM(is_null(), "You are trying to destroy an active request!");
799 }
800
810 bool is_null() const;
811
822 void free();
823
837 void cancel();
838
855 bool test(Status& status);
856
864 bool test()
865 {
866 Status status;
867 return test(status);
868 }
869
885 bool wait(Status& status);
886
896 bool wait()
897 {
898 Status status;
899 return wait(status);
900 }
901 }; // class Request
902
903#ifdef FEAT_HAVE_MPI
904 // Ensure that 'Request' is a POD container for 'MPI_Request',
905 // as this is required by the RequestVector class.
906 static_assert(sizeof(Request) == sizeof(MPI_Request), "invalid Request class size; class Request must be a POD");
907#endif
908
909 /* ************************************************************************************************************* */
910 /* ************************************************************************************************************* */
911 /* ************************************************************************************************************* */
912 /* ************************************************************************************************************* */
913 /* ************************************************************************************************************* */
914
948 {
949 private:
951 std::vector<Request> _reqs;
953 std::vector<Status> _stats;
954
955#if defined(FEAT_HAVE_MPI)
956 int _isize() const
957 {
958 return int(_reqs.size());
959 }
960
961 MPI_Request* _reqs_array()
962 {
963 return reinterpret_cast<MPI_Request*>(_reqs.data());
964 }
965
966 MPI_Status* _stats_array()
967 {
968 return reinterpret_cast<MPI_Status*>(_stats.data());
969 }
970#endif // FEAT_HAVE_MPI
971
972 public:
979 _reqs(),
980 _stats()
981 {
982 }
983
993 explicit RequestVector(std::size_t size_) :
994 _reqs(size_),
995 _stats(size_)
996 {
997 }
998
1003
1014 _reqs(std::forward<std::vector<Request>>(other._reqs)),
1015 _stats(std::forward<std::vector<Status>>(other._stats))
1016 {
1017 other.clear();
1018 }
1019
1037 {
1038 if(this != &other)
1039 {
1040 XASSERT(is_null());
1041 _reqs = std::forward<std::vector<Request>>(other._reqs);
1042 _stats = std::forward<std::vector<Status>>(other._stats);
1043 other.clear();
1044 }
1045 return *this;
1046 }
1047
1050 {
1051 XASSERTM(is_null(), "You are trying to destroy an active request vector!");
1052 }
1053
1063 Request& get_request(std::size_t idx)
1064 {
1065 XASSERT(idx < _reqs.size());
1066 return _reqs[idx];
1067 }
1068
1070 const Request& get_request(std::size_t idx) const
1071 {
1072 XASSERT(idx < _reqs.size());
1073 return _reqs[idx];
1074 }
1075
1085 Status& get_status(std::size_t idx)
1086 {
1087 XASSERT(idx < _stats.size());
1088 return _stats[idx];
1089 }
1090
1092 const Status& get_status(std::size_t idx) const
1093 {
1094 XASSERT(idx < _stats.size());
1095 return _stats[idx];
1096 }
1097
1099 Request& operator[](std::size_t idx)
1100 {
1101 XASSERT(idx < _reqs.size());
1102 return _reqs[idx];
1103 }
1104
1106 const Request& operator[](std::size_t idx) const
1107 {
1108 XASSERT(idx < _reqs.size());
1109 return _reqs[idx];
1110 }
1111
1121 void reserve(std::size_t size_)
1122 {
1123 if(size_ <= _reqs.size())
1124 return;
1125 _reqs.reserve(size_);
1126 _stats.reserve(size_);
1127 }
1128
1142 void resize(std::size_t size_)
1143 {
1144 // make sure that all to-be-removed requests are null
1145 for(std::size_t i(size_); i < _reqs.size(); ++i)
1146 {
1147 XASSERT(_reqs.at(i).is_null());
1148 }
1149 _reqs.resize(size_);
1150 _stats.resize(size_);
1151 }
1152
1166 std::size_t compress()
1167 {
1168 std::size_t i(0), j(0), n = _reqs.size();
1169 while(i+j < n)
1170 {
1171 if(_reqs[i+j].is_null())
1172 ++j;
1173 else
1174 {
1175 _reqs[i] = std::move(_reqs[i+j]);
1176 _stats[i] = std::move(_stats[i+j]);
1177 ++i;
1178 }
1179 }
1180 _reqs.resize(n-j);
1181 _stats.resize(n-j);
1182 return n-j;
1183 }
1184
1194 void push_back(Request&& request)
1195 {
1196 _reqs.emplace_back(std::forward<Request>(request));
1197 _stats.emplace_back(Status());
1198 }
1199
1209 std::size_t size() const
1210 {
1211 return _reqs.size();
1212 }
1213
1223 std::size_t active_count() const
1224 {
1225 std::size_t count(0);
1226 for(const auto& r : _reqs)
1227 {
1228 if(!r.is_null())
1229 ++count;
1230 }
1231 return count;
1232 }
1233
1245 bool empty() const
1246 {
1247 return _reqs.empty();
1248 }
1249
1262 bool is_null() const
1263 {
1264 for(const auto& r : _reqs)
1265 {
1266 if(!r.is_null())
1267 return false;
1268 }
1269 return true;
1270 }
1271
1282 void free()
1283 {
1284 for(auto& r : _reqs)
1285 {
1286 if(!r.is_null())
1287 r.free();
1288 }
1289 }
1290
1300 void cancel()
1301 {
1302 for(auto& r : _reqs)
1303 {
1304 if(!r.is_null())
1305 r.cancel();
1306 }
1307 }
1308
1323 void clear()
1324 {
1325 XASSERT(is_null());
1326 _reqs.clear();
1327 _stats.clear();
1328 }
1329
1341 bool test_for(std::size_t idx)
1342 {
1343 return get_request(idx).test(get_status(idx));
1344 }
1345
1362 bool test_for(std::size_t idx, Status& status)
1363 {
1364 return get_request(idx).test(status);
1365 }
1366
1379 bool test_all();
1380
1403 bool test_any(std::size_t& idx, Status& status);
1404
1420 bool test_any(std::size_t& idx)
1421 {
1422 Status status;
1423 if(!test_any(idx, status))
1424 return false;
1425 _stats[idx] = status;
1426 return true;
1427 }
1428
1445 bool test_any(Status& status)
1446 {
1447 std::size_t idx;
1448 return test_any(idx, status);
1449 }
1450
1464 bool wait_for(std::size_t idx)
1465 {
1466 return get_request(idx).wait(get_status(idx));
1467 }
1468
1487 bool wait_for(std::size_t idx, Status& status)
1488 {
1489 return get_request(idx).wait(status);
1490 }
1491
1500 void wait_all();
1501
1527 bool wait_any(std::size_t& idx, Status& status);
1528
1547 bool wait_any(std::size_t& idx)
1548 {
1549 Status status;
1550 if(!wait_any(idx, status))
1551 return false;
1552 _stats[idx] = status;
1553 return true;
1554 }
1555
1575 bool wait_any(Status& status)
1576 {
1577 std::size_t idx;
1578 return wait_any(idx, status);
1579 }
1580 }; // class RequestVector
1581
1582 /* ************************************************************************************************************* */
1583 /* ************************************************************************************************************* */
1584 /* ************************************************************************************************************* */
1585 /* ************************************************************************************************************* */
1586 /* ************************************************************************************************************* */
1587
1656 class Comm
1657 {
1658#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
1659 public:
1661 MPI_Comm comm;
1662#endif // FEAT_HAVE_MPI
1663
1664 protected:
1669
1670#if !defined(FEAT_HAVE_MPI) && !defined(DOXYGEN)
1671 explicit Comm(int);
1672#endif
1673
1674 public:
1680 Comm();
1681
1682#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
1695 explicit Comm(MPI_Comm comm_);
1696#endif // FEAT_HAVE_MPI
1697
1699 Comm(const Comm&) = delete;
1701 Comm& operator=(const Comm&) = delete;
1702
1716 Comm(Comm&& other);
1717
1735 Comm& operator=(Comm&& other);
1736
1743 virtual ~Comm();
1744
1745#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
1747 const MPI_Comm& mpi_comm() const
1748 {
1749 return comm;
1750 }
1751
1753 MPI_Comm& mpi_comm()
1754 {
1755 return comm;
1756 }
1757#endif //FEAT_HAVE_MPI
1758
1762 static Comm world();
1763
1767 static Comm self();
1768
1772 static Comm null();
1773
1779 bool is_world() const;
1780
1786 bool is_self() const;
1787
1793 bool is_null() const;
1794
1802 int rank() const
1803 {
1804 return _rank;
1805 }
1806
1814 int size() const
1815 {
1816 return _size;
1817 }
1818
1823
1831 Comm comm_dup() const;
1832
1858 Comm comm_create_range_incl(int count, int first = 0, int stride = 1) const;
1859
1880 Comm comm_create_incl(int n, const int* ranks) const;
1881
1898 Comm comm_split(int color, int key) const;
1899
1901
1906
1912 void barrier() const;
1913
1921 Request ibarrier() const;
1922
1923 // end of barrier synchronization group
1925
1930
1951 void send(const void* buffer, std::size_t count, const Datatype& datatype, int dest, int tag = 0) const;
1952
1972 template<typename T_>
1973 void send(const T_* buffer, std::size_t count, int dest, int tag = 0) const
1974 {
1975 send(buffer, count, autotype<T_>(), dest, tag);
1976 }
1977
2001 void recv(void* buffer, std::size_t count, const Datatype& datatype, int source, int tag, Status& status) const;
2002
2025 void recv(void* buffer, std::size_t count, const Datatype& datatype, int source, int tag = 0) const
2026 {
2027 Status status;
2028 recv(buffer, count, datatype, source, tag, status);
2029 }
2030
2053 template<typename T_>
2054 void recv(T_* buffer, std::size_t count, int source, int tag, Status& status) const
2055 {
2056 recv(buffer, count, autotype<T_>(), source, tag, status);
2057 }
2058
2079 template<typename T_>
2080 void recv(T_* buffer, std::size_t count, int source, int tag = 0) const
2081 {
2082 Status status;
2083 recv(buffer, count, autotype<T_>(), source, tag, status);
2084 }
2085
2086 // end of blocking point-to-point group
2088
2093
2117 Request isend(const void* buffer, std::size_t count, const Datatype& datatype, int dest, int tag = 0) const;
2118
2141 template<typename T_>
2142 Request isend(const T_* buffer, std::size_t count, int dest, int tag = 0) const
2143 {
2144 return isend(buffer, count, autotype<T_>(), dest, tag);
2145 }
2146
2170 Request irecv(void* buffer, std::size_t count, const Datatype& datatype, int source, int tag = 0) const;
2171
2194 template<typename T_>
2195 Request irecv(T_* buffer, std::size_t count, int source, int tag = 0) const
2196 {
2197 return irecv(buffer, count, autotype<T_>(), source, tag);
2198 }
2199
2200 // end of nonblocking point-to-point group
2202
2207
2225 void bcast(void* buffer, std::size_t count, const Datatype& datatype, int root) const;
2226
2243 template<typename T_>
2244 void bcast(T_* buffer, std::size_t count, int root) const
2245 {
2246 bcast(buffer, count, autotype<T_>(), root);
2247 }
2248
2269 Request ibcast(void* buffer, std::size_t count, const Datatype& datatype, int root) const;
2270
2290 template<typename T_>
2291 Request ibcast(T_* buffer, std::size_t count, int root) const
2292 {
2293 return ibcast(buffer, count, autotype<T_>(), root);
2294 }
2295
2296 // end of broadcast group
2298
2303
2334 void gather(const void* sendbuf, std::size_t sendcount, const Datatype& sendtype, void* recvbuf, std::size_t recvcount, const Datatype& recvtype, int root) const;
2335
2362 template<typename ST_, typename RT_>
2363 void gather(const ST_* sendbuf, std::size_t sendcount, RT_* recvbuf, std::size_t recvcount, int root) const
2364 {
2365 gather(sendbuf, sendcount, autotype<ST_>(), recvbuf, recvcount, autotype<RT_>(), root);
2366 }
2367
2402 Request igather(const void* sendbuf, std::size_t sendcount, const Datatype& sendtype, void* recvbuf, std::size_t recvcount, const Datatype& recvtype, int root) const;
2403
2434 template<typename ST_, typename RT_>
2435 Request igather(const ST_* sendbuf, std::size_t sendcount, RT_* recvbuf, std::size_t recvcount, int root) const
2436 {
2437 return igather(sendbuf, sendcount, autotype<ST_>(), recvbuf, recvcount, autotype<RT_>(), root);
2438 }
2439
2470 void scatter(const void* sendbuf, std::size_t sendcount, const Datatype& sendtype, void* recvbuf, std::size_t recvcount, const Datatype& recvtype, int root) const;
2471
2498 template<typename ST_, typename RT_>
2499 void scatter(const ST_* sendbuf, std::size_t sendcount, RT_* recvbuf, std::size_t recvcount, int root) const
2500 {
2501 scatter(sendbuf, sendcount, autotype<ST_>(), recvbuf, recvcount, autotype<RT_>(), root);
2502 }
2503
2538 Request iscatter(const void* sendbuf, std::size_t sendcount, const Datatype& sendtype, void* recvbuf, std::size_t recvcount, const Datatype& recvtype, int root) const;
2539
2570 template<typename ST_, typename RT_>
2571 Request iscatter(const ST_* sendbuf, std::size_t sendcount, RT_* recvbuf, std::size_t recvcount, int root) const
2572 {
2573 return iscatter(sendbuf, sendcount, autotype<ST_>(), recvbuf, recvcount, autotype<RT_>(), root);
2574 }
2575
2603 void allgather(const void* sendbuf, std::size_t sendcount, const Datatype& sendtype, void* recvbuf, std::size_t recvcount, const Datatype& recvtype) const;
2604
2628 template<typename ST_, typename RT_>
2629 void allgather(const ST_* sendbuf, std::size_t sendcount, RT_* recvbuf, std::size_t recvcount) const
2630 {
2631 allgather(sendbuf, sendcount, autotype<ST_>(), recvbuf, recvcount, autotype<RT_>());
2632 }
2633
2665 Request iallgather(const void* sendbuf, std::size_t sendcount, const Datatype& sendtype, void* recvbuf, std::size_t recvcount, const Datatype& recvtype) const;
2666
2694 template<typename ST_, typename RT_>
2695 Request iallgather(const ST_* sendbuf, std::size_t sendcount, RT_* recvbuf, std::size_t recvcount) const
2696 {
2697 return iallgather(sendbuf, sendcount, autotype<ST_>(), recvbuf, recvcount, autotype<RT_>());
2698 }
2699
2734 void allgatherv(const void* sendbuf, std::size_t sendcount, const Datatype& sendtype, void* recvbuf, const int* recvcounts, const int* displs, const Datatype& recvtype) const;
2735
2766 template<typename ST_, typename RT_>
2767 void allgatherv(const ST_* sendbuf, std::size_t sendcount, RT_* recvbuf, const int* recvcounts, const int* displs) const
2768 {
2769 allgatherv(sendbuf, sendcount, autotype<ST_>(), recvbuf, recvcounts, displs, autotype<RT_>());
2770 }
2771
2799 void alltoall(const void* sendbuf, std::size_t sendcount, const Datatype& sendtype, void* recvbuf, std::size_t recvcount, const Datatype& recvtype) const;
2800
2824 template<typename ST_, typename RT_>
2825 void alltoall(const ST_* sendbuf, std::size_t sendcount, RT_* recvbuf, std::size_t recvcount) const
2826 {
2827 alltoall(sendbuf, sendcount, autotype<ST_>(), recvbuf, recvcount, autotype<RT_>());
2828 }
2829
2861 Request ialltoall(const void* sendbuf, std::size_t sendcount, const Datatype& sendtype, void* recvbuf, std::size_t recvcount, const Datatype& recvtype) const;
2862
2890 template<typename ST_, typename RT_>
2891 Request ialltoall(const ST_* sendbuf, std::size_t sendcount, RT_* recvbuf, std::size_t recvcount) const
2892 {
2893 return ialltoall(sendbuf, sendcount, autotype<ST_>(), recvbuf, recvcount, autotype<RT_>());
2894 }
2895
2933 void alltoallv(const void* sendbuf, const int* sendcounts, const int* sdispls, const Datatype& sendtype, void* recvbuf, const int* recvcounts, const int* rdispls, const Datatype& recvtype) const;
2934
2968 template<typename ST_, typename RT_>
2969 void alltoallv(const ST_* sendbuf, const int* sendcounts, const int* sdispls, RT_* recvbuf, const int* recvcounts, const int* rdispls) const
2970 {
2971 alltoallv(sendbuf, sendcounts, sdispls, autotype<ST_>(), recvbuf, recvcounts, rdispls, autotype<RT_>());
2972 }
2973
2974 // end of gather/scatter group
2976
2981
3009 void reduce(const void* sendbuf, void* recvbuf, std::size_t count, const Datatype& datatype, const Operation& op, int root) const;
3010
3037 template<typename T_>
3038 void reduce(const T_* sendbuf, T_* recvbuf, std::size_t count, const Operation& op, int root) const
3039 {
3040 reduce(sendbuf, recvbuf, count, autotype<T_>(), op, root);
3041 }
3042
3074 Request ireduce(const void* sendbuf, void* recvbuf, std::size_t count, const Datatype& datatype, const Operation& op, int root) const;
3075
3106 template<typename T_>
3107 Request ireduce(const T_* sendbuf, T_* recvbuf, std::size_t count, const Operation& op, int root) const
3108 {
3109 return ireduce(sendbuf, recvbuf, count, autotype<T_>(), op, root);
3110 }
3111
3136 void allreduce(const void* sendbuf, void* recvbuf, std::size_t count, const Datatype& datatype, const Operation& op) const;
3137
3161 template<typename T_>
3162 void allreduce(const T_* sendbuf, T_* recvbuf, std::size_t count, const Operation& op) const
3163 {
3164 allreduce(sendbuf, recvbuf, count, autotype<T_>(), op);
3165 }
3166
3195 Request iallreduce(const void* sendbuf, void* recvbuf, std::size_t count, const Datatype& datatype, const Operation& op) const;
3196
3224 template<typename T_>
3225 Request iallreduce(const T_* sendbuf, T_* recvbuf, std::size_t count, const Operation& op) const
3226 {
3227 return iallreduce(sendbuf, recvbuf, count, autotype<T_>(), op);
3228 }
3229
3254 void scan(const void* sendbuf, void* recvbuf, std::size_t count, const Datatype& datatype, const Operation& op) const;
3255
3279 template<typename T_>
3280 void scan(const T_* sendbuf, T_* recvbuf, std::size_t count, const Operation& op) const
3281 {
3282 scan(sendbuf, recvbuf, count, autotype<T_>(), op);
3283 }
3284
3285 /*Request iscan(const void* sendbuf, void* recvbuf, std::size_t count, const Datatype& datatype, const Operation& op) const;
3286
3287 template<typename T_>
3288 Request iscan(const T_* sendbuf, T_* recvbuf, std::size_t count, const Operation& op) const
3289 {
3290 return iscan(sendbuf, recvbuf, count, autotype<T_>(), op);
3291 }*/
3292
3317 void exscan(const void* sendbuf, void* recvbuf, std::size_t count, const Datatype& datatype, const Operation& op) const;
3318
3342 template<typename T_>
3343 void exscan(const T_* sendbuf, T_* recvbuf, std::size_t count, const Operation& op) const
3344 {
3345 exscan(sendbuf, recvbuf, count, autotype<T_>(), op);
3346 }
3347
3348 /*Request iexscan(const void* sendbuf, void* recvbuf, std::size_t count, const Datatype& datatype, const Operation& op) const;
3349
3350 template<typename T_>
3351 Request iexscan(const T_* sendbuf, T_* recvbuf, std::size_t count, const Operation& op) const
3352 {
3353 return iexscan(sendbuf, recvbuf, count, autotype<T_>(), op);
3354 }*/
3355
3356 // end of reductions group
3358
3363
3387 void pack(const void* inbuf, std::size_t incount, const Datatype& datatype, void* outbuf, std::size_t outsize, int* position) const;
3388
3411 template<typename T_>
3412 void pack(const T_* inbuf, std::size_t incount, void* outbuf, std::size_t outsize, int* position) const
3413 {
3414 pack(inbuf, incount, autotype<T_>(), outbuf, outsize, position);
3415 }
3416
3440 void unpack(const void* inbuf, std::size_t insize, int* position, void* outbuf, std::size_t outcount, const Datatype& datatype) const;
3441
3467 template<typename T_>
3468 void unpack(const void* inbuf, std::size_t insize, int* position, T_* outbuf, std::size_t outcount) const
3469 {
3470 unpack(inbuf, insize, position, outbuf, outcount, autotype<T_>());
3471 }
3472
3485 void pack_size(std::size_t incount, const Datatype& datatype, int* size) const;
3486
3501 template<typename T_>
3502 void pack_size(std::size_t incount, int* size) const
3503 {
3504 pack_size(incount, autotype<T_>(), size);
3505 }
3506
3507 // end of datatypes group
3509
3517
3527 void bcast_stringstream(std::stringstream& stream, int root = 0) const;
3528
3538 void bcast_binarystream(BinaryStream& stream, int root = 0) const;
3539
3553 void print(std::ostream& os, const String& msg, int root = 0) const;
3554
3565 void print(const String& msg, int root = 0) const
3566 {
3567 print(std::cout, msg, root);
3568 }
3569
3584 void allprint(std::ostream& os, const String& msg, int root = 0) const;
3585
3597 void allprint(const String& msg, int root = 0) const
3598 {
3599 allprint(std::cout, msg, root);
3600 }
3601
3611 void print_flush(std::ostream& os, int root = 0) const;
3612
3619 void print_flush(int root = 0) const
3620 {
3621 print_flush(std::cout, root);
3622 }
3623
3624 // end of extended comm group
3626 }; // class Comm
3627 } // namespace Dist
3628} // namespace FEAT
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
FEAT Kernel base header.
Binary Stream class.
Communicator class.
Definition: dist.hpp:1657
void scatter(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, std::size_t recvcount, const Datatype &recvtype, int root) const
Blocking scatter.
Definition: dist.cpp:574
Comm & operator=(const Comm &)=delete
communicators are non-copyable
void bcast(void *buffer, std::size_t count, const Datatype &datatype, int root) const
Blocking broadcast.
Definition: dist.cpp:544
void reduce(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op, int root) const
Blocking Reduce.
Definition: dist.cpp:644
Request iallgather(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, std::size_t recvcount, const Datatype &recvtype) const
Nonblocking gather-to-all.
Definition: dist.cpp:600
Comm comm_create_range_incl(int count, int first=0, int stride=1) const
Creates a new sub-communicator from a strided range of ranks.
Definition: dist.cpp:475
void allreduce(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op) const
Blocking All-Reduce.
Definition: dist.cpp:658
void barrier() const
Blocking barrier.
Definition: dist.cpp:532
Request ibcast(void *buffer, std::size_t count, const Datatype &datatype, int root) const
Nonblocking broadcast.
Definition: dist.cpp:549
int size() const
Returns the size of this communicator.
Definition: dist.hpp:1814
void exscan(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op) const
Blocking Exclusive Scan.
Definition: dist.cpp:686
Comm comm_create_incl(int n, const int *ranks) const
Creates a new sub-communicator for a given set of ranks.
Definition: dist.cpp:501
void recv(void *buffer, std::size_t count, const Datatype &datatype, int source, int tag=0) const
Blocking Receive.
Definition: dist.hpp:2025
Request igather(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, std::size_t recvcount, const Datatype &recvtype, int root) const
Nonblocking gather.
Definition: dist.cpp:564
Request isend(const T_ *buffer, std::size_t count, int dest, int tag=0) const
Nonblocking Send.
Definition: dist.hpp:2142
static Comm null()
Returns a null communicator.
Definition: dist.cpp:442
Request ibarrier() const
Nonblocking barrier.
Definition: dist.cpp:537
void print(const String &msg, int root=0) const
Prints a message line to the standard output stream cout.
Definition: dist.hpp:3565
void allreduce(const T_ *sendbuf, T_ *recvbuf, std::size_t count, const Operation &op) const
Blocking All-Reduce.
Definition: dist.hpp:3162
int _rank
our rank
Definition: dist.hpp:1666
Request igather(const ST_ *sendbuf, std::size_t sendcount, RT_ *recvbuf, std::size_t recvcount, int root) const
Nonblocking gather.
Definition: dist.hpp:2435
virtual ~Comm()
virtual destructor
Definition: dist.cpp:425
void exscan(const T_ *sendbuf, T_ *recvbuf, std::size_t count, const Operation &op) const
Blocking Exclusive Scan.
Definition: dist.hpp:3343
void gather(const ST_ *sendbuf, std::size_t sendcount, RT_ *recvbuf, std::size_t recvcount, int root) const
Blocking gather.
Definition: dist.hpp:2363
Request iallreduce(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op) const
Nonblocking All-Reduce.
Definition: dist.cpp:663
Request irecv(void *buffer, std::size_t count, const Datatype &datatype, int source, int tag=0) const
Nonblocking Receive.
Definition: dist.cpp:719
Comm()
Standard constructor.
Definition: dist.cpp:375
void print_flush(int root=0) const
Explicitly flushes cout.
Definition: dist.hpp:3619
Comm comm_split(int color, int key) const
Creates a new sub-communicator by splitting this communicator.
Definition: dist.cpp:525
void recv(T_ *buffer, std::size_t count, int source, int tag=0) const
Blocking Receive.
Definition: dist.hpp:2080
bool is_world() const
Checks whether this communicator is the world communicator.
Definition: dist.cpp:447
void recv(T_ *buffer, std::size_t count, int source, int tag, Status &status) const
Blocking Receive.
Definition: dist.hpp:2054
void bcast_binarystream(BinaryStream &stream, int root=0) const
Blocking broadcast of a BinaryStream.
Definition: dist.cpp:775
void recv(void *buffer, std::size_t count, const Datatype &datatype, int source, int tag, Status &status) const
Blocking Receive.
Definition: dist.cpp:714
void bcast(T_ *buffer, std::size_t count, int root) const
Blocking broadcast.
Definition: dist.hpp:2244
Request isend(const void *buffer, std::size_t count, const Datatype &datatype, int dest, int tag=0) const
Nonblocking Send.
Definition: dist.cpp:707
int _size
the communicator size
Definition: dist.hpp:1668
MPI_Comm comm
our MPI communicator handle
Definition: dist.hpp:1661
Request iscatter(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, std::size_t recvcount, const Datatype &recvtype, int root) const
Nonblocking scatter.
Definition: dist.cpp:582
void pack(const T_ *inbuf, std::size_t incount, void *outbuf, std::size_t outsize, int *position) const
Pack message.
Definition: dist.hpp:3412
void unpack(const void *inbuf, std::size_t insize, int *position, void *outbuf, std::size_t outcount, const Datatype &datatype) const
Unpack message.
Definition: dist.cpp:731
void scatter(const ST_ *sendbuf, std::size_t sendcount, RT_ *recvbuf, std::size_t recvcount, int root) const
Blocking scatter.
Definition: dist.hpp:2499
Comm(const Comm &)=delete
communicators are non-copyable
void gather(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, std::size_t recvcount, const Datatype &recvtype, int root) const
Blocking gather.
Definition: dist.cpp:556
static Comm self()
Returns a copy of the self communicator.
Definition: dist.cpp:437
Request iallgather(const ST_ *sendbuf, std::size_t sendcount, RT_ *recvbuf, std::size_t recvcount) const
Nonblocking gather-to-all.
Definition: dist.hpp:2695
MPI_Comm & mpi_comm()
Definition: dist.hpp:1753
bool is_self() const
Checks whether this communicator is the self communicator.
Definition: dist.cpp:452
const MPI_Comm & mpi_comm() const
Definition: dist.hpp:1747
void allgatherv(const ST_ *sendbuf, std::size_t sendcount, RT_ *recvbuf, const int *recvcounts, const int *displs) const
Blocking gather-to-all.
Definition: dist.hpp:2767
void alltoallv(const void *sendbuf, const int *sendcounts, const int *sdispls, const Datatype &sendtype, void *recvbuf, const int *recvcounts, const int *rdispls, const Datatype &recvtype) const
Blocking All-to-All Scatter/Gather.
Definition: dist.cpp:636
void pack_size(std::size_t incount, const Datatype &datatype, int *size) const
Determine upper bound on increment of position by call to pack/unpack.
Definition: dist.cpp:736
void allgather(const ST_ *sendbuf, std::size_t sendcount, RT_ *recvbuf, std::size_t recvcount) const
Blocking gather-to-all.
Definition: dist.hpp:2629
Request iscatter(const ST_ *sendbuf, std::size_t sendcount, RT_ *recvbuf, std::size_t recvcount, int root) const
Nonblocking scatter.
Definition: dist.hpp:2571
void alltoall(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, std::size_t recvcount, const Datatype &recvtype) const
Blocking All-to-All Scatter/Gather.
Definition: dist.cpp:618
void pack_size(std::size_t incount, int *size) const
Determine upper bound on increment of position by call to pack/unpack.
Definition: dist.hpp:3502
void alltoallv(const ST_ *sendbuf, const int *sendcounts, const int *sdispls, RT_ *recvbuf, const int *recvcounts, const int *rdispls) const
Blocking All-to-All Scatter/Gather.
Definition: dist.hpp:2969
void send(const void *buffer, std::size_t count, const Datatype &datatype, int dest, int tag=0) const
Blocking Send.
Definition: dist.cpp:702
void pack(const void *inbuf, std::size_t incount, const Datatype &datatype, void *outbuf, std::size_t outsize, int *position) const
Pack message.
Definition: dist.cpp:726
void print_flush(std::ostream &os, int root=0) const
Explicitly flushes the output stream.
Definition: dist.cpp:865
Request ibcast(T_ *buffer, std::size_t count, int root) const
Nonblocking broadcast.
Definition: dist.hpp:2291
void reduce(const T_ *sendbuf, T_ *recvbuf, std::size_t count, const Operation &op, int root) const
Blocking Reduce.
Definition: dist.hpp:3038
void send(const T_ *buffer, std::size_t count, int dest, int tag=0) const
Blocking Send.
Definition: dist.hpp:1973
Comm comm_dup() const
Creates a copy of this communicator.
Definition: dist.cpp:462
void allprint(std::ostream &os, const String &msg, int root=0) const
Prints the ordered messages of all processes to an output stream.
Definition: dist.cpp:807
Request ireduce(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op, int root) const
Nonblocking Reduce.
Definition: dist.cpp:650
Request ireduce(const T_ *sendbuf, T_ *recvbuf, std::size_t count, const Operation &op, int root) const
Nonblocking Reduce.
Definition: dist.hpp:3107
void scan(const T_ *sendbuf, T_ *recvbuf, std::size_t count, const Operation &op) const
Blocking Inclusive Scan.
Definition: dist.hpp:3280
void allgatherv(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, const int *recvcounts, const int *displs, const Datatype &recvtype) const
Blocking gather-to-all.
Definition: dist.cpp:610
void allprint(const String &msg, int root=0) const
Prints the ordered messages of all processes to the standard output stream cout.
Definition: dist.hpp:3597
Request ialltoall(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, std::size_t recvcount, const Datatype &recvtype) const
Nonblocking All-to-All Scatter/Gather.
Definition: dist.cpp:626
int rank() const
Returns the rank of this process in this communicator.
Definition: dist.hpp:1802
Request iallreduce(const T_ *sendbuf, T_ *recvbuf, std::size_t count, const Operation &op) const
Nonblocking All-Reduce.
Definition: dist.hpp:3225
Request irecv(T_ *buffer, std::size_t count, int source, int tag=0) const
Nonblocking Receive.
Definition: dist.hpp:2195
void alltoall(const ST_ *sendbuf, std::size_t sendcount, RT_ *recvbuf, std::size_t recvcount) const
Blocking All-to-All Scatter/Gather.
Definition: dist.hpp:2825
void unpack(const void *inbuf, std::size_t insize, int *position, T_ *outbuf, std::size_t outcount) const
Unpack message.
Definition: dist.hpp:3468
void allgather(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, std::size_t recvcount, const Datatype &recvtype) const
Blocking gather-to-all.
Definition: dist.cpp:592
bool is_null() const
Checks whether this communicator is a null communicator.
Definition: dist.cpp:457
Request ialltoall(const ST_ *sendbuf, std::size_t sendcount, RT_ *recvbuf, std::size_t recvcount) const
Nonblocking All-to-All Scatter/Gather.
Definition: dist.hpp:2891
static Comm world()
Returns a copy of the world communicator.
Definition: dist.cpp:432
void print(std::ostream &os, const String &msg, int root=0) const
Prints a message line to an output stream.
Definition: dist.cpp:800
void scan(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op) const
Blocking Inclusive Scan.
Definition: dist.cpp:670
void bcast_stringstream(std::stringstream &stream, int root=0) const
Blocking broadcast of a std::stringstream.
Definition: dist.cpp:741
Communication Request class.
Definition: dist.hpp:731
MPI_Request request
our internal MPI request handle
Definition: dist.hpp:735
bool test(Status &status)
Tests whether the request is fulfilled (or null) without blocking.
Definition: dist.cpp:265
Request(const Request &)=delete
Request objects are non-copyable.
~Request()
non-virtual destructor
Definition: dist.hpp:796
Request()
Standard constructor.
Definition: dist.cpp:221
bool wait(Status &status)
Blocks until the request is fulfilled (or null).
Definition: dist.cpp:272
bool wait()
Blocks until the request is fulfilled (or null).
Definition: dist.hpp:896
bool test()
Tests whether the request is fulfilled (or null).
Definition: dist.hpp:864
void free()
Frees the request.
Definition: dist.cpp:253
MPI_Request * mpi_request()
Definition: dist.hpp:756
void cancel()
Cancels the request.
Definition: dist.cpp:259
Request & operator=(const Request &)=delete
Request objects are non-copyable.
bool is_null() const
Checks whether this request is null.
Definition: dist.cpp:248
Communication Request vector class.
Definition: dist.hpp:948
Status & get_status(std::size_t idx)
Returns a (const) reference to a single status in the vector.
Definition: dist.hpp:1085
void resize(std::size_t size_)
Resizes the request vector.
Definition: dist.hpp:1142
RequestVector(const RequestVector &)=delete
request vectors are non-copyable
void push_back(Request &&request)
Inserts a new request at the end of the request vector.
Definition: dist.hpp:1194
RequestVector()
Standard constructor.
Definition: dist.hpp:978
void reserve(std::size_t size_)
Reserves sufficient space for a specified number of requests.
Definition: dist.hpp:1121
bool test_for(std::size_t idx)
Tests whether a specific request is fulfilled (or null).
Definition: dist.hpp:1341
std::size_t active_count() const
Returns the number of active requests in the vector.
Definition: dist.hpp:1223
void cancel()
Cancels all remaining active requests.
Definition: dist.hpp:1300
const Request & get_request(std::size_t idx) const
Returns a (const) reference to a single request in the vector.
Definition: dist.hpp:1070
Request & get_request(std::size_t idx)
Returns a (const) reference to a single request in the vector.
Definition: dist.hpp:1063
Request & operator[](std::size_t idx)
Returns a (const) reference to a single request in the vector.
Definition: dist.hpp:1099
bool wait_for(std::size_t idx, Status &status)
Blocks until a specific request is fulfilled (or null).
Definition: dist.hpp:1487
bool wait_for(std::size_t idx)
Blocks until a specific request is fulfilled (or null).
Definition: dist.hpp:1464
bool test_all()
Tests whether all active requests are fulfilled (or null).
Definition: dist.cpp:286
bool wait_any(Status &status)
Blocks until one of the active requests has been fulfilled.
Definition: dist.hpp:1575
RequestVector & operator=(RequestVector &&other)
Move-assignment operator.
Definition: dist.hpp:1036
bool empty() const
Checks whether the request vector is empty.
Definition: dist.hpp:1245
bool test_any(std::size_t &idx, Status &status)
Tests whether one of the active requests has been fulfilled.
Definition: dist.cpp:293
bool is_null() const
Checks whether all requests are null requests.
Definition: dist.hpp:1262
std::vector< Request > _reqs
internal vector of Request objects
Definition: dist.hpp:951
RequestVector(RequestVector &&other)
Move constructor.
Definition: dist.hpp:1013
const Request & operator[](std::size_t idx) const
Returns a (const) reference to a single request in the vector.
Definition: dist.hpp:1106
bool wait_any(std::size_t &idx)
Blocks until one of the active requests has been fulfilled.
Definition: dist.hpp:1547
void free()
Frees all remaining active requests.
Definition: dist.hpp:1282
bool test_any(Status &status)
Tests whether one of the active requests has been fulfilled.
Definition: dist.hpp:1445
std::size_t size() const
Returns the total number of (both active and null) requests in the vector.
Definition: dist.hpp:1209
std::vector< Status > _stats
internal vector of Status objects
Definition: dist.hpp:953
std::size_t compress()
Compresses the request vector.
Definition: dist.hpp:1166
void clear()
Clears the request vector.
Definition: dist.hpp:1323
bool wait_any(std::size_t &idx, Status &status)
Blocks until one of the active requests has been fulfilled.
Definition: dist.cpp:332
const Status & get_status(std::size_t idx) const
Returns a (const) reference to a single status in the vector.
Definition: dist.hpp:1092
bool test_any(std::size_t &idx)
Tests whether one of the active requests has been fulfilled.
Definition: dist.hpp:1420
virtual ~RequestVector()
virtual destructor
Definition: dist.hpp:1049
RequestVector & operator=(const RequestVector &)=delete
request vectors are non-copyable
RequestVector(std::size_t size_)
Sized constructor.
Definition: dist.hpp:993
void wait_all()
Blocks until all active requests are fulfilled.
Definition: dist.cpp:327
bool test_for(std::size_t idx, Status &status)
Tests whether a specific request is fulfilled (or null).
Definition: dist.hpp:1362
Communication Status class.
Definition: dist.hpp:595
std::size_t get_size() const
Definition: dist.hpp:672
Status()
standard constructor
Definition: dist.hpp:602
std::size_t get_count(const Datatype &datatype) const
Returns the size of the message.
Definition: dist.hpp:664
Status & operator=(const Status &)=default
status objects are copyable
bool is_null() const
Checks whether the source rank is MPI_PROC_NULL.
Definition: dist.hpp:624
MPI_Status status
the MPI status structure
Definition: dist.hpp:599
int source() const
Definition: dist.hpp:632
MPI_Status * mpi_status()
Definition: dist.hpp:614
Status(const Status &)=default
status objects are copyable
int error() const
Definition: dist.hpp:648
int tag() const
Definition: dist.hpp:640
Singleton for managing derived Datatypes.
Definition: dist.hpp:335
const Datatype & get_type()
Retrieve Datatype for type T_.
Definition: dist.hpp:458
TypeRegistry()=default
Constructor.
std::unordered_map< std::type_index, Datatype > _types
Mapping of C++ types to Datatypes.
Definition: dist.hpp:337
std::recursive_mutex _mutex
Mutex against concurrent access.
Definition: dist.hpp:346
void free()
Frees all commited Datatypes.
Definition: dist.hpp:481
static TypeRegistry & instance() noexcept
Singleton accessor.
Definition: dist.hpp:370
TypeRegistry(const TypeRegistry &other)=delete
Deleted copy constructor.
TypeRegistry(TypeRegistry &&other)=delete
Deleted move constructor.
void operator=(const TypeRegistry &other)=delete
Deleted copy-assignment operator.
void operator=(TypeRegistry &&other)=delete
Deleted move-assignment operator.
MPI typemap description.
Definition: dist.hpp:228
std::vector< std::size_t > _displacements
Displacements for each entry.
Definition: dist.hpp:235
Typemap()=default
Constructor.
Typemap & add_entry(std::size_t displacement, int blocklength=1)
Add a member to this typemap.
Definition: dist.hpp:259
std::size_t count() const noexcept
Returns the number of entries in this typemap.
Definition: dist.hpp:290
std::vector< int > _blocklengths
Blocklengths for each entry.
Definition: dist.hpp:233
Typemap & add_entry(std::size_t displacement, const Dist::Datatype &type, int blocklength=1)
Add a member to this typemap.
Definition: dist.hpp:278
std::vector< Dist::Datatype > _types
Types for each entry.
Definition: dist.hpp:237
String class implementation.
Definition: string.hpp:47
bool initialize(int &argc, char **&argv)
Initializes the distributed communication system.
Definition: dist.cpp:105
const Datatype dt_byte(MPI_BYTE, sizeof(char))
Datatype wrapper for MPI_BYTE.
Definition: dist.hpp:129
const Datatype dt_wchar(MPI_WCHAR, sizeof(wchar_t))
Datatype wrapper for MPI_WCHAR.
Definition: dist.hpp:133
const Datatype dt_signed_long(MPI_LONG, sizeof(long))
Datatype wrapper for MPI_LONG.
Definition: dist.hpp:141
const Datatype dt_float(MPI_FLOAT, sizeof(float))
Datatype wrapper for MPI_FLOAT.
Definition: dist.hpp:155
const Datatype dt_signed_char(MPI_SIGNED_CHAR, sizeof(signed char))
Datatype wrapper for MPI_SIGNED_CHAR.
Definition: dist.hpp:135
const Datatype dt_signed_short(MPI_SHORT, sizeof(short))
Datatype wrapper for MPI_SHORT.
Definition: dist.hpp:137
const Datatype dt_unsigned_long_long(MPI_UNSIGNED_LONG_LONG, sizeof(unsigned long long))
Datatype wrapper for MPI_UNSIGNED_LONG_LONG.
Definition: dist.hpp:153
const Datatype dt_signed_int32(MPI_INT32_T, sizeof(std::int32_t))
Datatype wrapper for MPI_INT32_T.
Definition: dist.hpp:165
const Datatype & autotype()
Automatic Datatype deduction function template.
Definition: dist.hpp:490
const Datatype dt_unsigned_int32(MPI_UINT32_T, sizeof(std::uint32_t))
Datatype wrapper for MPI_UINT32_T.
Definition: dist.hpp:173
void finalize()
Finalizes the distributed communication system.
Definition: dist.cpp:148
const Datatype dt_signed_int8(MPI_INT8_T, sizeof(std::int8_t))
Datatype wrapper for MPI_INT8_T.
Definition: dist.hpp:161
const Datatype dt_char(MPI_CHAR, sizeof(char))
Datatype wrapper for MPI_CHAR.
Definition: dist.hpp:131
const Operation op_min(MPI_MIN)
Operation wrapper for MPI_MIN.
Definition: dist.hpp:575
const Datatype dt_unsigned_int(MPI_UNSIGNED, sizeof(unsigned int))
Datatype wrapper for MPI_UNSIGNED.
Definition: dist.hpp:149
const Datatype dt_unsigned_int16(MPI_UINT16_T, sizeof(std::uint16_t))
Datatype wrapper for MPI_UINT16_T.
Definition: dist.hpp:171
const Datatype dt_unsigned_int8(MPI_UINT8_T, sizeof(std::uint8_t))
Datatype wrapper for MPI_UINT8_T.
Definition: dist.hpp:169
const Datatype dt__half
custom Datatype for __half
const Datatype dt_signed_int(MPI_INT, sizeof(int))
Datatype wrapper for MPI_INT.
Definition: dist.hpp:139
const Datatype dt_signed_long_long(MPI_LONG_LONG, sizeof(long long))
Datatype wrapper for MPI_LONG_LONG.
Definition: dist.hpp:143
const Operation op_max(MPI_MAX)
Operation wrapper for MPI_MAX.
Definition: dist.hpp:573
const Datatype dt_double(MPI_DOUBLE, sizeof(double))
Datatype wrapper for MPI_DOUBLE.
Definition: dist.hpp:157
const Datatype dt_unsigned_char(MPI_UNSIGNED_CHAR, sizeof(unsigned char))
Datatype wrapper for MPI_UNSIGNED_CHAR.
Definition: dist.hpp:145
const Datatype dt_packed(MPI_PACKED, sizeof(char))
Datatype wrapper for MPI_PACKED.
Definition: dist.hpp:177
const Datatype dt_signed_int16(MPI_INT16_T, sizeof(std::int16_t))
Datatype wrapper for MPI_INT16_T.
Definition: dist.hpp:163
const Datatype dt_unsigned_short(MPI_UNSIGNED_SHORT, sizeof(unsigned short))
Datatype wrapper for MPI_UNSIGNED_SHORT.
Definition: dist.hpp:147
const Datatype dt_unsigned_int64(MPI_UINT64_T, sizeof(std::uint64_t))
Datatype wrapper for MPI_UINT64_T.
Definition: dist.hpp:175
const Datatype dt_long_double(MPI_LONG_DOUBLE, sizeof(long double))
Datatype wrapper for MPI_LONG_DOUBLE.
Definition: dist.hpp:159
const Operation op_sum(MPI_SUM)
Operation wrapper for MPI_SUM.
Definition: dist.hpp:571
const Datatype dt__float128
custom Datatype for __float128
const Datatype dt_unsigned_long(MPI_UNSIGNED_LONG, sizeof(unsigned long))
Datatype wrapper for MPI_UNSIGNED_LONG.
Definition: dist.hpp:151
const Datatype dt_signed_int64(MPI_INT64_T, sizeof(std::int64_t))
Datatype wrapper for MPI_INT64_T.
Definition: dist.hpp:167
Status
Solver status return codes enumeration.
Definition: base.hpp:47
FEAT namespace.
Definition: adjactor.hpp:12
Communication Datatype class.
Definition: dist.hpp:80
MPI_Datatype dt
the MPI datatype handle
Definition: dist.hpp:83
Datatype(MPI_Datatype dt_, std::size_t bytes_)
MPI_Datatype handle constructor
Definition: dist.hpp:96
bool operator!=(const Datatype &other) const
inequality comparison operator
Definition: dist.hpp:114
bool operator==(const Datatype &other) const
equality comparison operator
Definition: dist.hpp:108
std::size_t size() const
Returns the size of the datatype in bytes, as given in the constructor.
Definition: dist.hpp:122
std::size_t bytes
the size of the datatype in bytes
Definition: dist.hpp:85
Communication Operation class.
Definition: dist.hpp:537
bool operator==(const Operation &other) const
equality comparison operator
Definition: dist.hpp:558
Operation(MPI_Op op_)
MPI_Op handle constructor
Definition: dist.hpp:548
bool operator!=(const Operation &other) const
inequality comparison operator
Definition: dist.hpp:564
MPI_Op op
the MPI operation handle
Definition: dist.hpp:540
Mapping from types to Typemaps.
Definition: dist.hpp:314
static Typemap typemap()
Produce a Typemap for T_.
Definition: dist.hpp:316