Skip to content

Commit

Permalink
Merge pull request #5776 from hzhou/2201_op_predef
Browse files Browse the repository at this point in the history
op: replace predefined datatype on input

Approved-by: Ken Raffenetti
  • Loading branch information
hzhou authored Feb 21, 2022
2 parents ca34c9c + bc7f81a commit 908c021
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 @@ -2287,6 +2287,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 908c021

Please sign in to comment.