/* 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. */
#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)
, 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)
{
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)
}
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;
}
}
-}
-}
+} // namespace simgrid::smpi