| 1 | /* -*- Mode: C; c-basic-offset:4 ; -*- */ |
|---|
| 2 | /* |
|---|
| 3 | * |
|---|
| 4 | * (C) 2001 by Argonne National Laboratory. |
|---|
| 5 | * See COPYRIGHT in top-level directory. |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | #include "mpiimpl.h" |
|---|
| 9 | |
|---|
| 10 | /* -- Begin Profiling Symbol Block for routine MPI_Type_create_hindexed */ |
|---|
| 11 | #if defined(HAVE_PRAGMA_WEAK) |
|---|
| 12 | #pragma weak MPI_Type_create_hindexed = PMPI_Type_create_hindexed |
|---|
| 13 | #elif defined(HAVE_PRAGMA_HP_SEC_DEF) |
|---|
| 14 | #pragma _HP_SECONDARY_DEF PMPI_Type_create_hindexed MPI_Type_create_hindexed |
|---|
| 15 | #elif defined(HAVE_PRAGMA_CRI_DUP) |
|---|
| 16 | #pragma _CRI duplicate MPI_Type_create_hindexed as PMPI_Type_create_hindexed |
|---|
| 17 | #endif |
|---|
| 18 | /* -- End Profiling Symbol Block */ |
|---|
| 19 | |
|---|
| 20 | /* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build |
|---|
| 21 | the MPI routines */ |
|---|
| 22 | #ifndef MPICH_MPI_FROM_PMPI |
|---|
| 23 | #undef MPI_Type_create_hindexed |
|---|
| 24 | #define MPI_Type_create_hindexed PMPI_Type_create_hindexed |
|---|
| 25 | |
|---|
| 26 | #endif |
|---|
| 27 | |
|---|
| 28 | #undef FUNCNAME |
|---|
| 29 | #define FUNCNAME MPI_Type_create_hindexed |
|---|
| 30 | |
|---|
| 31 | /*@ |
|---|
| 32 | MPI_Type_create_hindexed - Create a datatype for an indexed datatype with |
|---|
| 33 | displacements in bytes |
|---|
| 34 | |
|---|
| 35 | Input Parameters: |
|---|
| 36 | + count - number of blocks --- also number of entries in |
|---|
| 37 | displacements and blocklengths (integer) |
|---|
| 38 | . blocklengths - number of elements in each block (array of nonnegative integers) |
|---|
| 39 | . displacements - byte displacement of each block (array of address integers) |
|---|
| 40 | - oldtype - old datatype (handle) |
|---|
| 41 | |
|---|
| 42 | Output Parameter: |
|---|
| 43 | . newtype - new datatype (handle) |
|---|
| 44 | |
|---|
| 45 | .N ThreadSafe |
|---|
| 46 | |
|---|
| 47 | .N Fortran |
|---|
| 48 | |
|---|
| 49 | .N Errors |
|---|
| 50 | .N MPI_SUCCESS |
|---|
| 51 | .N MPI_ERR_TYPE |
|---|
| 52 | .N MPI_ERR_ARG |
|---|
| 53 | @*/ |
|---|
| 54 | int MPI_Type_create_hindexed(int count, |
|---|
| 55 | int blocklengths[], |
|---|
| 56 | MPI_Aint displacements[], |
|---|
| 57 | MPI_Datatype oldtype, |
|---|
| 58 | MPI_Datatype *newtype) |
|---|
| 59 | { |
|---|
| 60 | static const char FCNAME[] = "MPI_Type_create_hindexed"; |
|---|
| 61 | int mpi_errno = MPI_SUCCESS; |
|---|
| 62 | MPID_Datatype *new_dtp; |
|---|
| 63 | int i, *ints; |
|---|
| 64 | MPIU_CHKLMEM_DECL(1); |
|---|
| 65 | MPID_MPI_STATE_DECL(MPID_STATE_MPI_TYPE_CREATE_HINDEXED); |
|---|
| 66 | |
|---|
| 67 | MPIR_ERRTEST_INITIALIZED_ORDIE(); |
|---|
| 68 | |
|---|
| 69 | MPIU_THREAD_CS_ENTER(ALLFUNC,); |
|---|
| 70 | MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_TYPE_CREATE_HINDEXED); |
|---|
| 71 | |
|---|
| 72 | # ifdef HAVE_ERROR_CHECKING |
|---|
| 73 | { |
|---|
| 74 | MPID_BEGIN_ERROR_CHECKS; |
|---|
| 75 | { |
|---|
| 76 | int i; |
|---|
| 77 | MPID_Datatype *datatype_ptr = NULL; |
|---|
| 78 | |
|---|
| 79 | MPIR_ERRTEST_COUNT(count, mpi_errno); |
|---|
| 80 | if (count > 0) { |
|---|
| 81 | MPIR_ERRTEST_ARGNULL(blocklengths, "blocklens", mpi_errno); |
|---|
| 82 | MPIR_ERRTEST_ARGNULL(displacements, "indices", mpi_errno); |
|---|
| 83 | } |
|---|
| 84 | if (mpi_errno != MPI_SUCCESS) goto fn_fail; |
|---|
| 85 | |
|---|
| 86 | MPIR_ERRTEST_DATATYPE(oldtype, "datatype", mpi_errno); |
|---|
| 87 | if (mpi_errno != MPI_SUCCESS) goto fn_fail; |
|---|
| 88 | |
|---|
| 89 | if (HANDLE_GET_KIND(oldtype) != HANDLE_KIND_BUILTIN) { |
|---|
| 90 | MPID_Datatype_get_ptr(oldtype, datatype_ptr); |
|---|
| 91 | MPID_Datatype_valid_ptr(datatype_ptr, mpi_errno); |
|---|
| 92 | } |
|---|
| 93 | for (i=0; i < count; i++) { |
|---|
| 94 | MPIR_ERRTEST_ARGNEG(blocklengths[i], "blocklen", mpi_errno); |
|---|
| 95 | } |
|---|
| 96 | if (mpi_errno != MPI_SUCCESS) goto fn_fail; |
|---|
| 97 | } |
|---|
| 98 | MPID_END_ERROR_CHECKS; |
|---|
| 99 | } |
|---|
| 100 | # endif /* HAVE_ERROR_CHECKING */ |
|---|
| 101 | |
|---|
| 102 | /* ... body of routine ... */ |
|---|
| 103 | |
|---|
| 104 | mpi_errno = MPID_Type_indexed(count, |
|---|
| 105 | blocklengths, |
|---|
| 106 | displacements, |
|---|
| 107 | 1, /* displacements in bytes */ |
|---|
| 108 | oldtype, |
|---|
| 109 | newtype); |
|---|
| 110 | |
|---|
| 111 | if (mpi_errno != MPI_SUCCESS) goto fn_fail; |
|---|
| 112 | |
|---|
| 113 | MPIU_CHKLMEM_MALLOC_ORJUMP(ints, int *, (count + 1) * sizeof(int), mpi_errno, "content description"); |
|---|
| 114 | |
|---|
| 115 | ints[0] = count; |
|---|
| 116 | |
|---|
| 117 | for (i=0; i < count; i++) |
|---|
| 118 | { |
|---|
| 119 | ints[i+1] = blocklengths[i]; |
|---|
| 120 | } |
|---|
| 121 | MPID_Datatype_get_ptr(*newtype, new_dtp); |
|---|
| 122 | mpi_errno = MPID_Datatype_set_contents(new_dtp, |
|---|
| 123 | MPI_COMBINER_HINDEXED, |
|---|
| 124 | count+1, /* ints (count, blocklengths) */ |
|---|
| 125 | count, /* aints (displacements) */ |
|---|
| 126 | 1, /* types */ |
|---|
| 127 | ints, |
|---|
| 128 | displacements, |
|---|
| 129 | &oldtype); |
|---|
| 130 | |
|---|
| 131 | if (mpi_errno != MPI_SUCCESS) goto fn_fail; |
|---|
| 132 | |
|---|
| 133 | /* ... end of body of routine ... */ |
|---|
| 134 | |
|---|
| 135 | fn_exit: |
|---|
| 136 | MPIU_CHKLMEM_FREEALL(); |
|---|
| 137 | MPID_MPI_FUNC_EXIT(MPID_STATE_MPI_TYPE_CREATE_HINDEXED); |
|---|
| 138 | MPIU_THREAD_CS_EXIT(ALLFUNC,); |
|---|
| 139 | return mpi_errno; |
|---|
| 140 | |
|---|
| 141 | fn_fail: |
|---|
| 142 | /* --BEGIN ERROR HANDLING-- */ |
|---|
| 143 | # ifdef HAVE_ERROR_CHECKING |
|---|
| 144 | { |
|---|
| 145 | mpi_errno = MPIR_Err_create_code( |
|---|
| 146 | mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER, "**mpi_type_create_hindexed", |
|---|
| 147 | "**mpi_type_create_hindexed %d %p %p %D %p", count, blocklengths, displacements, oldtype, newtype); |
|---|
| 148 | } |
|---|
| 149 | # endif |
|---|
| 150 | mpi_errno = MPIR_Err_return_comm(NULL, FCNAME, mpi_errno); |
|---|
| 151 | goto fn_exit; |
|---|
| 152 | /* --END ERROR HANDLING-- */ |
|---|
| 153 | } |
|---|