Skip to content

Commit

Permalink
op: replace predefined datatype on input
Browse files Browse the repository at this point in the history
We are supposed to support operations on some predefined datatype, such
as those from MPI_Type_create_f90_xxx. However, those types are in fact
derived types wraps around a basic type. Check and replace the input
datatype with the basic type if that is the case so the reduction can
work. Since the datatype in these case are all input only parameters,
there shouldn't be any side effects replacing them.
  • Loading branch information
hzhou committed Feb 10, 2022
1 parent 8242b3b commit 0b172fa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions maint/local_python/binding_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -2245,6 +2245,14 @@ def dump_validate_op(op, dt, is_coll):
if dt:
G.out.append("} else {")
G.out.append(" mpi_errno = (*MPIR_OP_HDL_TO_DTYPE_FN(%s)) (%s);" % (op, dt))
# check predefined datatype and replace with basic_type if necessary
G.out.append(" if (mpi_errno != MPI_SUCCESS) {")
G.out.append(" MPI_Datatype alt_dt = MPIR_Op_get_alt_datatype(%s, %s);" % (op, dt))
G.out.append(" if (alt_dt != MPI_DATATYPE_NULL) {")
G.out.append(" %s = alt_dt;" % dt)
G.out.append(" mpi_errno = MPI_SUCCESS;")
G.out.append(" }")
G.out.append(" }")
G.out.append("}")
dump_error_check("")

Expand Down
4 changes: 4 additions & 0 deletions src/include/mpir_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,8 @@ extern MPIR_Op_check_dtype_fn *MPIR_Op_check_dtype_table[];

int MPIR_Op_is_commutative(MPI_Op);

/* for some predefined datatypes, e.g. from MPI_Type_create_f90_xxx, we need
* use its basic type for operations */
MPI_Datatype MPIR_Op_get_alt_datatype(MPI_Op op, MPI_Datatype datatype);

#endif /* MPIR_OP_H_INCLUDED */
22 changes: 22 additions & 0 deletions src/mpi/coll/op/oputil.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,25 @@ const char *MPIR_Op_builtin_get_shortname(MPI_Op op)
}
return "";
}

/* for some predefined datatypes, e.g. from MPI_Type_create_f90_xxx, we need
* use its basic type for operations */
MPI_Datatype MPIR_Op_get_alt_datatype(MPI_Op op, MPI_Datatype datatype)
{
MPI_Datatype alt_dt = MPI_DATATYPE_NULL;
if (!HANDLE_IS_BUILTIN(datatype)) {
MPIR_Datatype *dt_ptr;
MPIR_Datatype_get_ptr(datatype, dt_ptr);

if (dt_ptr && dt_ptr->contents) {
int combiner = dt_ptr->contents->combiner;
if (combiner == MPI_COMBINER_F90_REAL ||
combiner == MPI_COMBINER_F90_COMPLEX || combiner == MPI_COMBINER_F90_INTEGER) {
if (MPI_SUCCESS == (*MPIR_OP_HDL_TO_DTYPE_FN(op)) (dt_ptr->basic_type)) {
alt_dt = dt_ptr->basic_type;
}
}
}
}
return alt_dt;
}

0 comments on commit 0b172fa

Please sign in to comment.