1 /* Copyright (c) 2010-2022. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #ifndef SMPI_WIN_HPP_INCLUDED
8 #define SMPI_WIN_HPP_INCLUDED
10 #include "simgrid/s4u/Barrier.hpp"
11 #include "smpi_errhandler.hpp"
12 #include "smpi_f2c.hpp"
13 #include "smpi_keyvals.hpp"
14 #include "smpi_config.hpp"
22 class Win : public F2C, public Keyval {
29 std::vector<MPI_Request> requests_;
30 s4u::MutexPtr mut_ = s4u::Mutex::create();
32 std::vector<MPI_Win> connected_wins_;
35 MPI_Group src_group_ = MPI_GROUP_NULL; // for post/wait
36 MPI_Group dst_group_ = MPI_GROUP_NULL; // for start/complete
37 int count_ = 0; // for ordering the accs
38 s4u::MutexPtr lock_mut_ = s4u::Mutex::create();
39 s4u::MutexPtr atomic_mut_ = s4u::Mutex::create();
40 std::list<int> lockers_;
41 int rank_; // to identify owner for barriers in MPI_COMM_WORLD
42 int mode_ = 0; // exclusive or shared lock
45 MPI_Errhandler errhandler_ = _smpi_cfg_default_errhandler_is_error ? MPI_ERRORS_ARE_FATAL : MPI_ERRORS_RETURN;
48 static std::unordered_map<int, smpi_key_elem> keyvals_;
49 static int keyval_id_;
51 Win(void* base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, bool allocated = false,
52 bool dynamic = false);
53 Win(MPI_Info info, MPI_Comm comm) : Win(MPI_BOTTOM, 0, 1, info, comm, false, true){};
54 Win(const Win&) = delete;
55 Win& operator=(const Win&) = delete;
56 static int del(Win* win);
57 int attach (void *base, MPI_Aint size);
58 int detach (const void *base);
59 void get_name(char* name, int* length) const;
60 std::string name() const override {return name_.empty() ? std::string("MPI_Win") : name_;}
61 void get_group( MPI_Group* group);
62 void set_name(const char* name);
64 MPI_Comm comm() const;
66 int start(MPI_Group group, int assert);
67 int post(MPI_Group group, int assert);
70 void set_info( MPI_Info info);
72 MPI_Aint size() const;
74 int disp_unit() const;
75 int fence(int assert);
76 int opened() const {return opened_;}
77 int put(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
78 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Request* request=nullptr);
79 int get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
80 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Request* request=nullptr);
81 int accumulate(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
82 MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Request* request=nullptr);
83 int get_accumulate(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype, void *result_addr,
84 int result_count, MPI_Datatype result_datatype, int target_rank, MPI_Aint target_disp, int target_count,
85 MPI_Datatype target_datatype, MPI_Op op, MPI_Request* request=nullptr);
86 int compare_and_swap(const void* origin_addr, const void* compare_addr, void* result_addr, MPI_Datatype datatype,
87 int target_rank, MPI_Aint target_disp);
88 static Win* f2c(int id);
90 int lock(int lock_type, int rank, int assert);
92 int lock_all(int assert);
95 int flush_local(int rank);
97 int flush_local_all();
99 int finish_comms(int rank);
100 int shared_query(int rank, MPI_Aint* size, int* disp_unit, void* baseptr) const;
101 MPI_Errhandler errhandler();
102 void set_errhandler( MPI_Errhandler errhandler);