6#include "Utility/IpplException.h"
12 template <TargetComm Target>
13 Window<Target>::~Window() {
14 if (win_m != MPI_WIN_NULL) {
20 template <TargetComm Target>
21 template <std::contiguous_iterator Iter>
22 bool Window<Target>::create(
const Communicator& comm, Iter first, Iter last) {
23 static_assert(isActiveTarget<Target>::value,
24 "No active target communication window");
31 count_m = std::distance(first, last);
32 int dispUnit =
sizeof(
typename Iter::value_type);
33 MPI_Aint size = (MPI_Aint)count_m * dispUnit;
34 MPI_Win_create(&(*first), size, dispUnit, MPI_INFO_NULL, comm, &win_m);
39 template <TargetComm Target>
40 template <std::contiguous_iterator Iter>
41 bool Window<Target>::attach(
const Communicator& comm, Iter first, Iter last) {
48 MPI_Win_create_dynamic(MPI_INFO_NULL, comm, &win_m);
52 count_m = std::distance(first, last);
53 MPI_Aint size = (MPI_Aint)count_m *
sizeof(
typename Iter::value_type);
54 MPI_Win_attach(win_m, &(*first), size);
59 template <TargetComm Target>
60 template <std::contiguous_iterator Iter>
61 bool Window<Target>::detach(Iter first) {
66 MPI_Win_detach(win_m, &(*first));
70 template <TargetComm Target>
71 void Window<Target>::fence(
int asrt) {
72 static_assert(isActiveTarget<Target>::value,
73 "No active target communication window");
74 MPI_Win_fence(asrt, win_m);
77 template <TargetComm Target>
78 template <std::contiguous_iterator Iter>
79 void Window<Target>::put(Iter first, Iter last,
int dest,
unsigned int pos,
81 MPI_Datatype datatype = get_mpi_datatype<typename Iter::value_type>(*first);
82 auto count = std::distance(first, last);
83 if (count > count_m) {
84 throw IpplException(
"Window::put",
"Count exceeds RMA window size.");
86 if (request ==
nullptr) {
87 MPI_Put(&(*first), count, datatype, dest, (MPI_Aint)pos, count, datatype,
90 MPI_Rput(&(*first), count, datatype, dest, (MPI_Aint)pos, count, datatype,
95 template <TargetComm Target>
97 void Window<Target>::put(
const T* value,
int dest,
unsigned int pos, Request* request) {
98 MPI_Datatype datatype = get_mpi_datatype<T>(*value);
99 if (request ==
nullptr) {
100 MPI_Put(value, 1, datatype, dest, (MPI_Aint)pos, 1, datatype, win_m);
102 MPI_Rput(value, 1, datatype, dest, (MPI_Aint)pos, 1, datatype, win_m, *request);
106 template <TargetComm Target>
107 template <std::contiguous_iterator Iter>
108 void Window<Target>::get(Iter first, Iter last,
int source,
unsigned int pos,
110 MPI_Datatype datatype = get_mpi_datatype<typename Iter::value_type>(*first);
111 auto count = std::distance(first, last);
112 if (count > count_m) {
113 throw IpplException(
"Window::put",
"Count exceeds RMA window size.");
115 if (request ==
nullptr) {
116 MPI_Get(&(*first), count, datatype, source, (MPI_Aint)pos, count, datatype,
119 MPI_Rget(&(*first), count, datatype, source, (MPI_Aint)pos, count, datatype,
124 template <TargetComm Target>
125 template <
typename T>
126 void Window<Target>::get(T* value,
int source,
unsigned int pos, Request* request) {
127 MPI_Datatype datatype = get_mpi_datatype<T>(*value);
128 if (request ==
nullptr) {
129 MPI_Get(value, 1, datatype, source, (MPI_Aint)pos, 1, datatype, win_m);
131 MPI_Rget(value, 1, datatype, source, (MPI_Aint)pos, 1, datatype, win_m,
139 template <TargetComm Target>
140 void Window<Target>::flush(
int rank) {
141 static_assert(!isActiveTarget<Target>::value,
142 "No passive target communication window");
143 MPI_Win_flush(rank, win_m);
146 template <TargetComm Target>
147 void Window<Target>::flushall() {
148 static_assert(!isActiveTarget<Target>::value,
149 "No passive target communication window");
150 MPI_Win_flush_all(win_m);
153 template <TargetComm Target>
154 void Window<Target>::lock(
int locktype,
int rank,
int asrt) {
155 static_assert(!isActiveTarget<Target>::value,
156 "No passive target communication window");
157 MPI_Win_lock(locktype, rank, asrt, win_m);
160 template <TargetComm Target>
161 void Window<Target>::lockall(
int asrt) {
162 static_assert(!isActiveTarget<Target>::value,
163 "No passive target communication window");
164 MPI_Win_lock_all(asrt, win_m);
167 template <TargetComm Target>
168 void Window<Target>::unlock(
int rank) {
169 static_assert(!isActiveTarget<Target>::value,
170 "No passive target communication window");
171 MPI_Win_unlock(rank, win_m);
174 template <TargetComm Target>
175 void Window<Target>::unlockall() {
176 static_assert(!isActiveTarget<Target>::value,
177 "No passive target communication window");
178 MPI_Win_unlock_all(win_m);
Definition IpplException.h:6