Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make smpi::Keyval::attribute() return a reference.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 22 May 2021 11:20:02 +0000 (13:20 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 25 May 2021 08:43:38 +0000 (10:43 +0200)
src/smpi/include/smpi_keyvals.hpp
src/smpi/mpi/smpi_comm.cpp
src/smpi/mpi/smpi_datatype.cpp
src/smpi/mpi/smpi_keyvals.cpp

index 2c93473..6835f52 100644 (file)
@@ -44,7 +44,8 @@ class Keyval{
   private:
     std::unordered_map<int, void*> attributes_;
   protected:
-    std::unordered_map<int, void*>* attributes();
+    std::unordered_map<int, void*>& attributes() { return attributes_; }
+
   public:
 // Each subclass should have two members, as we want to separate the ones for Win, Comm, and Datatypes :
 //    static std::unordered_map<int, smpi_key_elem> keyvals_;
@@ -106,9 +107,9 @@ template <typename T> int Keyval::attr_delete(int keyval){
     if(ret!=MPI_SUCCESS)
         return ret;
   }
-  if(attributes()->empty())
+  if (attributes().empty())
     return MPI_ERR_ARG;
-  attributes()->erase(keyval);
+  attributes().erase(keyval);
   return MPI_SUCCESS;
 }
 
@@ -118,9 +119,8 @@ template <typename T> int Keyval::attr_get(int keyval, void* attr_value, int* fl
   if(elem==nullptr)
     return MPI_ERR_ARG;
 
-  const auto& attribs = attributes();
-  auto attr           = attribs->find(keyval);
-  if (attr != attribs->end()) {
+  auto attr = attributes().find(keyval);
+  if (attr != attributes().end()) {
     *static_cast<void**>(attr_value) = attr->second;
     *flag=1;
   } else {
@@ -135,7 +135,7 @@ template <typename T> int Keyval::attr_put(int keyval, void* attr_value){
     return MPI_ERR_ARG;
   elem->refcount++;
   int flag=0;
-  auto p = attributes()->insert({keyval, attr_value});
+  auto p  = attributes().insert({keyval, attr_value});
   if (not p.second) {
     int ret = call_deleter<T>((T*)this, elem, keyval,p.first->second,&flag);
     // overwrite previous value
@@ -148,7 +148,7 @@ template <typename T> int Keyval::attr_put(int keyval, void* attr_value){
 
 template <typename T> void Keyval::cleanup_attr(){
   int flag = 0;
-  for (auto const& it : attributes_) {
+  for (auto const& it : attributes()) {
     auto elm = T::keyvals_.find(it.first);
     if (elm != T::keyvals_.end()) {
       smpi_key_elem elem = elm->second;
index 1ef564d..db2fb04 100644 (file)
@@ -79,7 +79,7 @@ int Comm::dup(MPI_Comm* newcomm){
   (*newcomm)   = new  Comm(cp, this->topo());
   int ret      = MPI_SUCCESS;
 
-  for (auto const& it : *attributes()) {
+  for (auto const& it : attributes()) {
     smpi_key_elem elem = keyvals_.at(it.first);
     if (elem != nullptr) {
       int flag        = 0;
@@ -98,10 +98,10 @@ int Comm::dup(MPI_Comm* newcomm){
       if (elem->copy_fn.comm_copy_fn == MPI_COMM_DUP_FN ||
           ((elem->copy_fn.comm_copy_fn_fort != MPI_NULL_COPY_FN) && *(int*)*elem->copy_fn.comm_copy_fn_fort == 1)) {
         elem->refcount++;
-        (*newcomm)->attributes()->insert({it.first, it.second});
+        (*newcomm)->attributes().insert({it.first, it.second});
       } else if (flag) {
         elem->refcount++;
-        (*newcomm)->attributes()->insert({it.first, value_out});
+        (*newcomm)->attributes().insert({it.first, value_out});
       }
     }
   }
index cb1bee7..4d940c4 100644 (file)
@@ -163,7 +163,7 @@ int Datatype::copy_attrs(Datatype* datatype){
   flags_ &= ~DT_FLAG_PREDEFINED;
   int ret = MPI_SUCCESS;
 
-  for (auto const& it : *(datatype->attributes())) {
+  for (auto const& it : datatype->attributes()) {
     smpi_key_elem elem = keyvals_.at(it.first);
     if (elem != nullptr) {
       int flag = 0;
@@ -180,10 +180,10 @@ int Datatype::copy_attrs(Datatype* datatype){
       if (elem->copy_fn.type_copy_fn == MPI_TYPE_DUP_FN ||
           ((elem->copy_fn.type_copy_fn_fort != MPI_NULL_COPY_FN) && (*(int*)*elem->copy_fn.type_copy_fn_fort == 1))) {
         elem->refcount++;
-        attributes()->insert({it.first, it.second});
+        attributes().insert({it.first, it.second});
       } else if (flag) {
         elem->refcount++;
-        attributes()->insert({it.first, value_out});
+        attributes().insert({it.first, value_out});
       }
     }
   }
index 02916c8..d43605b 100644 (file)
 namespace simgrid{
 namespace smpi{
 
-std::unordered_map<int, void*>* Keyval::attributes(){
-  return &attributes_;
-}
-
 template <>
 int Keyval::call_deleter<Comm>(Comm* obj, const s_smpi_key_elem_t* elem, int keyval, void* value, int* /*flag*/)
 {