comm
Loading...
Searching...
No Matches
class_handle.impl.h
1/*
2//@HEADER
3// *****************************************************************************
4//
5// class_handle.impl.h
6// DARMA/comm => Communicator
7//
8// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
9// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
10// Government retains certain rights in this software.
11//
12// Redistribution and use in source and binary forms, with or without
13// modification, are permitted provided that the following conditions are met:
14//
15// * Redistributions of source code must retain the above copyright notice,
16// this list of conditions and the following disclaimer.
17//
18// * Redistributions in binary form, must reproduce the above copyright notice,
19// this list of conditions and the following disclaimer in the documentation
20// and/or other materials provided with the distribution.
21//
22// * Neither the name of the copyright holder nor the names of its
23// contributors may be used to endorse or promote products derived from this
24// software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36// POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact darma@sandia.gov
39//
40// *****************************************************************************
41//@HEADER
42*/
43
44#if !defined INCLUDED_COMM_COMM_CLASS_HANDLE_IMPL_H
45#define INCLUDED_COMM_COMM_CLASS_HANDLE_IMPL_H
46
47#include "class_handle.h"
48#include "comm/comm/MPI/comm_mpi.h"
49
50namespace comm {
51
52template <typename T>
53ClassHandleRank<T>::ClassHandleRank(ClassHandle<T> in_handle, int in_rank)
54 : handle_(in_handle),
55 rank_(in_rank)
56{}
57
58template <typename T>
59template <auto fn, typename... Args>
60void ClassHandleRank<T>::send(Args&&... args) {
61 handle_.template send<fn>(rank_, std::forward<Args>(args)...);
62}
63
64template <typename T>
65template <auto fn, typename... Args>
66void ClassHandleRank<T>::sendTerm(Args&&... args) {
67 handle_.template sendTerm<fn>(rank_, std::forward<Args>(args)...);
68}
69
70template <typename T>
71ClassHandle<T>::ClassHandle(int in_index, CommMPI* in_comm)
72 : index_(in_index),
73 comm_(in_comm)
74{}
75
76template <typename T>
77void ClassHandle<T>::unregister() {
78 comm_->unregisterInstanceCollective(index_);
79}
80
81template <typename T>
82T* ClassHandle<T>::get() {
83 return reinterpret_cast<T*>(comm_->getInstanceCollective(index_));
84}
85
86template <typename T>
87ClassHandleRank<T> ClassHandle<T>::operator[](int rank) {
88 return ClassHandleRank<T>{*this, rank};
89}
90
91template <typename T>
92template <auto fn, typename... Args>
93void ClassHandle<T>::send(int dest, Args&&... args) {
94 comm_->template send<fn>(dest, *this, std::forward<Args>(args)...);
95}
96
97template <typename T>
98template <auto fn, typename... Args>
99void ClassHandle<T>::sendTerm(int dest, Args&&... args) {
100 comm_->template sendImpl<fn>(dest, index_, true, std::forward<Args>(args)...);
101}
102
103template <typename T>
104template <typename U, typename V>
105void ClassHandle<T>::reduce(int root, MPI_Datatype datatype, MPI_Op op, U sendbuf, V recvbuf, int count) {
106 comm_->reduce(root, datatype, op, sendbuf, recvbuf, count);
107}
108
109template <typename T>
110template <typename U>
111void ClassHandle<T>::broadcast(int root, MPI_Datatype datatype, U buffer, int count) {
112 comm_->broadcast(root, datatype, buffer, count);
113}
114
115template <typename T>
116template <typename U>
117std::unordered_map<int, std::vector<U>> ClassHandle<T>::allgather(U const* sendbuf, int sendcount) {
118 return comm_->allgather(sendbuf, sendcount);
119}
120
121} // namespace comm
122
123#endif /*INCLUDED_COMM_COMM_CLASS_HANDLE_IMPL_H*/
Communication layer implemented in straight MPI code.
Definition comm_traits.h:52
Definition class_handle.h:75