]> AND Public Git Repository - simgrid.git/blobdiff - src/smpi/mpi/smpi_datatype_derived.cpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add ability to restrict maximum subset size
[simgrid.git] / src / smpi / mpi / smpi_datatype_derived.cpp
index b9c9cf7b5743f7fdd87411d44135efee04405f5e..fd756811eb35da0643b98d984cd59c5dc212ac18 100644 (file)
@@ -1,5 +1,5 @@
 /* smpi_datatype.cpp -- MPI primitives to handle datatypes                  */
-/* Copyright (c) 2009-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2009-2023. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -11,8 +11,7 @@
 #include <array>
 #include <cstring>
 
-namespace simgrid{
-namespace smpi{
+namespace simgrid::smpi {
 
 Datatype_contents::Datatype_contents(int combiner, int number_of_integers, const int* integers, int number_of_addresses,
                                      const MPI_Aint* addresses, int number_of_datatypes, const MPI_Datatype* datatypes)
@@ -21,6 +20,14 @@ Datatype_contents::Datatype_contents(int combiner, int number_of_integers, const
     , addresses_(addresses, addresses + number_of_addresses)
     , datatypes_(datatypes, datatypes + number_of_datatypes)
 {
+  for (auto& datatype : datatypes_)
+    datatype->ref();
+}
+
+Datatype_contents::~Datatype_contents()
+{
+  for (auto& datatype : datatypes_)
+    Datatype::unref(datatype);
 }
 
 Type_Contiguous::Type_Contiguous(int size, MPI_Aint lb, MPI_Aint ub, int flags, int block_count, MPI_Datatype old_type)
@@ -46,7 +53,7 @@ void Type_Contiguous::serialize(const void* noncontiguous_buf, void* contiguous_
 {
   auto* contiguous_buf_char          = static_cast<char*>(contiguous_buf);
   const auto* noncontiguous_buf_char = static_cast<const char*>(noncontiguous_buf) + lb();
-  memcpy(contiguous_buf_char, noncontiguous_buf_char, count * block_count_ * old_type_->size());
+  memcpy(contiguous_buf_char, noncontiguous_buf_char, old_type_->size() * count * block_count_);
 }
 
 void Type_Contiguous::unserialize(const void* contiguous_buf, void* noncontiguous_buf, int count, MPI_Op op)
@@ -237,7 +244,7 @@ Type_Indexed::Type_Indexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int co
 }
 
 int Type_Indexed::clone(MPI_Datatype* type)
-{ 
+{
   *type = new Type_Indexed(this->size(), this->lb(), this->ub(), this->flags(), this->block_count_, this->block_lengths_, (int*)(this->block_indices_), this->old_type_);
   (*type)->copy_attrs(this);
   return MPI_SUCCESS;
@@ -327,5 +334,4 @@ void Type_Struct::unserialize(const void* contiguous_buf, void *noncontiguous_bu
   }
 }
 
-}
-}
+} // namespace simgrid::smpi