- int ret = MPI_SUCCESS;
-
- for (auto const& it : *(datatype->attributes())) {
- smpi_key_elem elem = keyvals_.at(it.first);
- if (elem != nullptr) {
- int flag = 0;
- void* value_out;
- if (elem->copy_fn.type_copy_fn != MPI_NULL_COPY_FN && elem->copy_fn.type_copy_fn != MPI_TYPE_DUP_FN)
- ret = elem->copy_fn.type_copy_fn(datatype, it.first, elem->extra_state, it.second, &value_out, &flag);
- else if (elem->copy_fn.type_copy_fn_fort != MPI_NULL_COPY_FN && (*(int*)*elem->copy_fn.type_copy_fn_fort) != 1) {
- value_out = (int*)xbt_malloc(sizeof(int));
- elem->copy_fn.type_copy_fn_fort(datatype, it.first, elem->extra_state, it.second, value_out, &flag, &ret);
+
+ set_contents(MPI_COMBINER_DUP, 0, nullptr, 0, nullptr, 1, &datatype);
+ for (auto const& [key, value] : datatype->attributes()) {
+ auto elem_it = keyvals_.find(key);
+ xbt_assert(elem_it != keyvals_.end(), "Keyval not found for Datatype: %d", key);
+
+ smpi_key_elem& elem = elem_it->second;
+ int ret = MPI_SUCCESS;
+ int flag = 0;
+ void* value_out = nullptr;
+ if (elem.copy_fn.type_copy_fn == MPI_TYPE_DUP_FN) {
+ value_out = value;
+ flag = 1;
+ } else if (elem.copy_fn.type_copy_fn != MPI_NULL_COPY_FN) {
+ ret = elem.copy_fn.type_copy_fn(datatype, key, elem.extra_state, value, &value_out, &flag);
+ }
+ if (ret != MPI_SUCCESS)
+ return ret;
+
+ if (elem.copy_fn.type_copy_fn_fort != MPI_NULL_COPY_FN) {
+ value_out = xbt_new(int, 1);
+ if (*(int*)*elem.copy_fn.type_copy_fn_fort == 1) { // MPI_TYPE_DUP_FN
+ memcpy(value_out, value, sizeof(int));
+ flag = 1;
+ } else { // not null, nor dup
+ elem.copy_fn.type_copy_fn_fort(datatype, key, elem.extra_state, value, value_out, &flag, &ret);