Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cb5ab79f98c3ab3d2b01abae2da8e42c41562fb7
[simgrid.git] / src / smpi / include / smpi_win.hpp
1 /* Copyright (c) 2010-2021. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #ifndef SMPI_WIN_HPP_INCLUDED
8 #define SMPI_WIN_HPP_INCLUDED
9
10 #include "simgrid/s4u/Barrier.hpp"
11 #include "smpi_errhandler.hpp"
12 #include "smpi_f2c.hpp"
13 #include "smpi_keyvals.hpp"
14
15 #include <vector>
16 #include <list>
17
18 namespace simgrid{
19 namespace smpi{
20
21 class Win : public F2C, public Keyval {
22   void* base_;
23   MPI_Aint size_;
24   int disp_unit_;
25   int assert_ = 0;
26   MPI_Info info_;
27   MPI_Comm comm_;
28   std::vector<MPI_Request> requests_;
29   s4u::MutexPtr mut_ = s4u::Mutex::create();
30   s4u::Barrier* bar_ = nullptr;
31   std::vector<MPI_Win> connected_wins_;
32   std::string name_;
33   int opened_               = 0;
34   MPI_Group src_group_      = MPI_GROUP_NULL; // for post/wait
35   MPI_Group dst_group_      = MPI_GROUP_NULL; // for start/complete
36   int count_                = 0; // for ordering the accs
37   s4u::MutexPtr lock_mut_   = s4u::Mutex::create();
38   s4u::MutexPtr atomic_mut_ = s4u::Mutex::create();
39   std::list<int> lockers_;
40   int rank_; // to identify owner for barriers in MPI_COMM_WORLD
41   int mode_ = 0; // exclusive or shared lock
42   int allocated_;
43   int dynamic_;
44   MPI_Errhandler errhandler_ = MPI_ERRORS_ARE_FATAL;
45
46 public:
47   static std::unordered_map<int, smpi_key_elem> keyvals_;
48   static int keyval_id_;
49
50   Win(void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, int allocated = 0, int dynamic = 0);
51   Win(MPI_Info info, MPI_Comm comm) : Win(MPI_BOTTOM, 0, 1, info, comm, 0, 1) {};
52   Win(const Win&) = delete;
53   Win& operator=(const Win&) = delete;
54   ~Win() override;
55   int attach (void *base, MPI_Aint size);
56   int detach (const void *base);
57   void get_name(char* name, int* length) const;
58   std::string name() const override {return name_.empty() ? std::string("MPI_Win") : name_;}
59   void get_group( MPI_Group* group);
60   void set_name(const char* name);
61   int rank() const;
62   MPI_Comm comm() const;
63   int dynamic() const;
64   int start(MPI_Group group, int assert);
65   int post(MPI_Group group, int assert);
66   int complete();
67   MPI_Info info();
68   void set_info( MPI_Info info);
69   int wait();
70   MPI_Aint size() const;
71   void* base() const;
72   int disp_unit() const;
73   int fence(int assert);
74   int put(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
75               MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Request* request=nullptr);
76   int get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
77               MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Request* request=nullptr);
78   int accumulate(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank,
79               MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Request* request=nullptr);
80   int get_accumulate(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype, void *result_addr,
81               int result_count, MPI_Datatype result_datatype, int target_rank, MPI_Aint target_disp, int target_count,
82               MPI_Datatype target_datatype, MPI_Op op, MPI_Request* request=nullptr);
83   int compare_and_swap(const void* origin_addr, const void* compare_addr, void* result_addr, MPI_Datatype datatype,
84                        int target_rank, MPI_Aint target_disp);
85   static Win* f2c(int id);
86
87   int lock(int lock_type, int rank, int assert);
88   int unlock(int rank);
89   int lock_all(int assert);
90   int unlock_all();
91   int flush(int rank);
92   int flush_local(int rank);
93   int flush_all();
94   int flush_local_all();
95   int finish_comms();
96   int finish_comms(int rank);
97   int shared_query(int rank, MPI_Aint* size, int* disp_unit, void* baseptr) const;
98   MPI_Errhandler errhandler();
99   void set_errhandler( MPI_Errhandler errhandler);
100 };
101
102
103 }
104 }
105
106 #endif