@@ -356,89 +356,93 @@ namespace mpi {
356
356
};
357
357
358
358
/* *
359
- * @brief A shared memory window abstraction using MPI .
360
- *
361
- * @details This class provides an interface for creating and managing an MPI shared memory window.
362
- *
363
- * @tparam BaseType The data type stored in the shared memory window.
364
- */
359
+ * @brief A C++ wrapper around `MPI_Win` representing a shared memory window .
360
+ *
361
+ * @details This class provides an interface for creating and managing an MPI shared memory window.
362
+ *
363
+ * @tparam BaseType The type of elements stored in the shared memory window.
364
+ */
365
365
template <class BaseType > class shared_window : public window <BaseType> {
366
366
public:
367
- // / Default constructor
367
+ // /Construct a shared memory window with `MPI_WIN_NULL`.
368
368
shared_window () = default ;
369
369
370
370
/* *
371
- * @brief Constructs a shared memory window.
371
+ * @brief Construct a shared memory window by dynamically allocating memory .
372
372
*
373
- * @details This constructor allocates shared memory within the given communicator.
373
+ * @details This constructor allocates a shared memory window within the given communicator by calling
374
+ * `MPI_Win_allocate_shared`. The allocated memory is automatically freed when the window is destroyed.
374
375
*
375
- * @param c The shared communicator .
376
- * @param size The number of elements of type @p BaseType to allocate .
377
- * @param info MPI_Info object for optimization hints .
376
+ * @param c mpi::shared_communicator object .
377
+ * @param sz Number of elements to allocate for the calling process .
378
+ * @param info Additional MPI information .
378
379
*/
379
- explicit shared_window (shared_communicator const &c, MPI_Aint size, MPI_Info info = MPI_INFO_NULL) noexcept {
380
- ASSERT (size >= 0 )
380
+ explicit shared_window (shared_communicator const &c, MPI_Aint sz, MPI_Info info = MPI_INFO_NULL) {
381
+ ASSERT (sz >= 0 )
382
+ comm_ = c.get ();
383
+ size_ = sz;
381
384
if (has_env) {
382
- void *baseptr = nullptr ;
383
- MPI_Win_allocate_shared (size * sizeof (BaseType), sizeof (BaseType), info, c.get (), &baseptr, &(this ->win_ ));
384
- this ->comm_ = c.get ();
385
- this ->data_ = static_cast <BaseType *>(baseptr);
386
- this ->size_ = size;
385
+ check_mpi_call (MPI_Win_allocate_shared (size_ * sizeof (BaseType), sizeof (BaseType), info, c.get (), &data_, &win_), " MPI_Win_allocate_shared" );
387
386
} else {
388
- this ->owned_ = true ;
389
- this ->comm_ = c.get ();
390
- this ->data_ = new BaseType[size];
391
- this ->size_ = size;
387
+ owned_ = true ;
388
+ data_ = new BaseType[size_]; // NOLINT (new is fine here)
392
389
}
393
390
}
394
391
395
392
/* *
396
- * @brief Queries attributes of a shared memory window.
393
+ * @brief Query attributes of a shared memory window.
397
394
*
398
- * @details Retrieves the size, displacement unit, and base address of the shared memory region for a given rank.
395
+ * @details Retrieves the size, displacement unit, and a pointer to the beginning of the shared memory region for a
396
+ * specific rank.
399
397
*
400
- * @param rank The rank within the communicator (defaults to @p MPI_PROC_NULL for querying all ranks) .
401
- * @return A tuple containing ( size in bytes, displacement unit, base pointer) .
398
+ * @param rank Rank within the shared communicator .
399
+ * @return A tuple containing the size in bytes, the displacement unit in bytes and the base pointer.
402
400
*/
403
- std::tuple<MPI_Aint, int , void *> query (int rank = MPI_PROC_NULL) const noexcept {
401
+ [[nodiscard]] std::tuple<MPI_Aint, int , void *> query (int rank = MPI_PROC_NULL) const {
404
402
if (has_env) {
405
- MPI_Aint size = 0 ;
406
- int disp_unit = 0 ;
403
+ MPI_Aint sz = 0 ;
404
+ int du = 0 ;
407
405
void *baseptr = nullptr ;
408
- MPI_Win_shared_query (this -> win_ , rank, &size , &disp_unit , &baseptr);
409
- return {size, disp_unit , baseptr};
406
+ check_mpi_call ( MPI_Win_shared_query (win_, rank, &sz , &du , &baseptr), " MPI_Win_shared_query " );
407
+ return {sz, du , baseptr};
410
408
} else {
411
- return {this -> size_ * sizeof (BaseType) , sizeof (BaseType), this -> data_ };
409
+ return {size_, sizeof (BaseType), data_};
412
410
}
413
411
}
414
412
415
- // Override the commonly used attributes of the window base class
416
-
417
413
/* *
418
- * @brief Returns the base address of the shared memory for a specific rank.
414
+ * @brief Get a pointer to the beginning of the shared memory region of a specific rank.
419
415
*
420
- * @param rank The rank whose base address should be retrieved .
421
- * @return A pointer to the base address .
416
+ * @param rank Rank within the shared communicator .
417
+ * @return Pointer to the shared window of the given rank .
422
418
*/
423
- BaseType *base (int rank = MPI_PROC_NULL) const noexcept { return static_cast <BaseType *>(std::get<2 >(query (rank))); }
419
+ [[nodiscard]] BaseType *base (int rank = MPI_PROC_NULL) const { return static_cast <BaseType *>(std::get<2 >(query (rank))); }
424
420
425
421
/* *
426
- * @brief Returns the number of elements stored in the shared memory window .
422
+ * @brief Get the size of the shared memory region of a specific rank .
427
423
*
428
- * @param rank The rank whose memory size should be retrieved .
429
- * @return The number of elements in the shared window.
424
+ * @param rank Rank within the shared communicator .
425
+ * @return Number of elements in the shared window of the given rank .
430
426
*/
431
- MPI_Aint size (int rank = MPI_PROC_NULL) const noexcept { return std::get<0 >(query (rank)) / sizeof (BaseType); }
427
+ [[nodiscard]] MPI_Aint size (int rank = MPI_PROC_NULL) const { return std::get<0 >(query (rank)) / sizeof (BaseType); }
432
428
433
429
/* *
434
- * @brief Returns the displacement unit of the shared memory.
430
+ * @brief Get the displacement unit of the shared memory region of a specific rank .
435
431
*
436
- * @param rank The rank whose displacement unit should be retrieved .
437
- * @return The displacement unit.
432
+ * @param rank Rank within the shared communicator .
433
+ * @return Displacement unit in bytes .
438
434
*/
439
- int disp_unit (int rank = MPI_PROC_NULL) const noexcept { return std::get<1 >(query (rank)); }
435
+ [[nodiscard]] int disp_unit (int rank = MPI_PROC_NULL) const { return std::get<1 >(query (rank)); }
436
+
437
+ // / Get the mpi::shared_communicator associated with the window.
438
+ [[nodiscard]] shared_communicator get_communicator () const { return comm_.get (); }
440
439
441
- shared_communicator get_communicator () { return this ->comm_ .get (); }
440
+ private:
441
+ using window<BaseType>::win_;
442
+ using window<BaseType>::comm_;
443
+ using window<BaseType>::owned_;
444
+ using window<BaseType>::data_;
445
+ using window<BaseType>::size_;
442
446
};
443
447
444
448
/* * @} */
0 commit comments