Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a deleted flag to keep track of invalid but not actually deleted handles
authorAugustin Degomme <adegomme@gmail.com>
Fri, 2 Apr 2021 09:23:03 +0000 (11:23 +0200)
committerAugustin Degomme <adegomme@gmail.com>
Fri, 2 Apr 2021 18:03:31 +0000 (20:03 +0200)
We can then crash if someone tries to use it later on.
just do it for Comm for now, will extend later.

src/smpi/include/private.hpp
src/smpi/include/smpi_f2c.hpp
src/smpi/mpi/smpi_comm.cpp

index fd6c957..e890605 100644 (file)
@@ -536,8 +536,12 @@ XBT_PRIVATE void private_execute_flops(double flops);
              "%s: param %d %s cannot be negative", __func__, (num), _XBT_STRINGIFY(val));
 #define CHECK_COMM2(num, comm)                                                                                         \
   CHECK_MPI_NULL((num), MPI_COMM_NULL, MPI_ERR_COMM, (comm))
+#define CHECK_DELETED(num, err, obj)                                                                                  \
+  CHECK_ARGS((obj->deleted() == true), (err),                                                \
+            "%s: param %d %s has already been freed", __func__, (num), _XBT_STRINGIFY(obj));
 #define CHECK_COMM(num)                                                                                                \
-  CHECK_COMM2((num), comm)
+  CHECK_COMM2((num), comm)                                                                                             \
+  CHECK_DELETED((num), MPI_ERR_COMM, comm)
 #define CHECK_REQUEST(num)                                                                                             \
   CHECK_ARGS(request == nullptr, MPI_ERR_REQUEST,                                                                      \
              "%s: param %d request cannot be NULL",__func__, (num));
index c839d1c..b5f50d0 100644 (file)
@@ -25,7 +25,7 @@ private:
   static int f2c_id_;
   static f2c_lookup_type::size_type num_default_handles_;
   int my_f2c_id_ = -1;
-
+  bool deleted_ = false;
 protected:
   static void allocate_lookup()
   {
@@ -34,8 +34,9 @@ protected:
   }
   static int f2c_id() { return f2c_id_; }
   static void f2c_id_increment() { f2c_id_++; }
-
+  void mark_as_deleted(){deleted_=true;};
 public:
+  bool deleted(){return deleted_;}
   static f2c_lookup_type* lookup() { return f2c_lookup_.get(); }
   F2C();
   virtual ~F2C() = default;
index 84751b0..fb45970 100644 (file)
@@ -65,6 +65,8 @@ void Comm::destroy(Comm* comm)
     Comm::destroy(smpi_process()->comm_world());
     return;
   }
+  if(comm != MPI_COMM_WORLD && comm != MPI_COMM_SELF)
+    comm->mark_as_deleted();
   Comm::unref(comm);
 }