23
23
#include < complex>
24
24
#include < type_traits>
25
25
#include < algorithm>
26
+ #include < utility>
26
27
#include < unistd.h>
27
28
28
29
// / Library namespace
@@ -364,9 +365,15 @@ namespace mpi {
364
365
public:
365
366
window () = default ;
366
367
window (window const &) = delete ;
367
- window (window &&) = delete ;
368
+ window (window &&other) noexcept : win{ std::exchange (other. win , MPI_WIN_NULL)} {}
368
369
window& operator =(window const &) = delete ;
369
- window& operator =(window &&) = delete ;
370
+ window& operator =(window &&rhs) noexcept {
371
+ if (this != std::addressof (rhs)) {
372
+ this ->free ();
373
+ this ->win = std::exchange (rhs.win , MPI_WIN_NULL);
374
+ }
375
+ return *this ;
376
+ }
370
377
371
378
// / Create a window over an existing local memory buffer
372
379
explicit window (communicator &c, BaseType *base, MPI_Aint size = 0 ) noexcept {
@@ -379,15 +386,17 @@ namespace mpi {
379
386
MPI_Win_allocate (size * sizeof (BaseType), alignof (BaseType), MPI_INFO_NULL, c.get (), &baseptr, &win);
380
387
}
381
388
382
- ~window () {
389
+ ~window () { free (); }
390
+
391
+ explicit operator MPI_Win () const noexcept { return win; };
392
+ explicit operator MPI_Win*() noexcept { return &win; };
393
+
394
+ void free () noexcept {
383
395
if (win != MPI_WIN_NULL) {
384
396
MPI_Win_free (&win);
385
397
}
386
398
}
387
399
388
- explicit operator MPI_Win () const noexcept { return win; };
389
- explicit operator MPI_Win*() noexcept { return &win; };
390
-
391
400
// / Synchronization routine in active target RMA. It opens and closes an access epoch.
392
401
void fence (int assert = 0 ) const noexcept {
393
402
MPI_Win_fence (assert, win);
@@ -474,8 +483,10 @@ namespace mpi {
474
483
template <class BaseType >
475
484
class shared_window : public window <BaseType> {
476
485
public:
486
+ shared_window () = default ;
487
+
477
488
// / Create a window and allocate memory for a shared memory buffer
478
- shared_window (shared_communicator& c, MPI_Aint size) noexcept {
489
+ explicit shared_window (shared_communicator& c, MPI_Aint size) noexcept {
479
490
void * baseptr = nullptr ;
480
491
MPI_Win_allocate_shared (size * sizeof (BaseType), alignof (BaseType), MPI_INFO_NULL, c.get (), &baseptr, &(this ->win ));
481
492
}
0 commit comments