00001
00002
00003
00004
00005
00006
00007 #include "mpioimpl.h"
00008
00009 #ifdef HAVE_WEAK_SYMBOLS
00010
00011 #if defined(HAVE_PRAGMA_WEAK)
00012 #pragma weak MPI_Type_create_subarray = PMPI_Type_create_subarray
00013 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
00014 #pragma _HP_SECONDARY_DEF PMPI_Type_create_subarray MPI_Type_create_subarray
00015 #elif defined(HAVE_PRAGMA_CRI_DUP)
00016 #pragma _CRI duplicate MPI_Type_create_subarray as PMPI_Type_create_subarray
00017
00018 #endif
00019
00020
00021 #define MPIO_BUILD_PROFILING
00022 #include "mpioprof.h"
00023 #endif
00024
00025 static char myname[] = "MPI_Type_create_subarray";
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 int MPI_Type_create_subarray(int ndims, int *array_of_sizes,
00044 int *array_of_subsizes, int *array_of_starts,
00045 int order, MPI_Datatype oldtype,
00046 MPI_Datatype *newtype)
00047 {
00048 MPI_Aint extent, size_with_aint;
00049 int i, err, error_code;
00050 MPI_Offset size_with_offset;
00051
00052
00053 if (ndims <= 0) {
00054 error_code = MPIO_Err_create_code(MPI_SUCCESS,
00055 MPIR_ERR_RECOVERABLE,
00056 myname, __LINE__, MPI_ERR_ARG,
00057 "Invalid ndims argument", 0);
00058 return MPIO_Err_return_comm(MPI_COMM_SELF, error_code);
00059 }
00060 if (array_of_sizes <= (int *) 0) {
00061 error_code = MPIO_Err_create_code(MPI_SUCCESS,
00062 MPIR_ERR_RECOVERABLE,
00063 myname, __LINE__, MPI_ERR_ARG,
00064 "Invalid array_of_sizes argument",
00065 0);
00066 return MPIO_Err_return_comm(MPI_COMM_SELF, error_code);
00067 }
00068 if (array_of_subsizes <= (int *) 0) {
00069 error_code = MPIO_Err_create_code(MPI_SUCCESS,
00070 MPIR_ERR_RECOVERABLE,
00071 myname, __LINE__, MPI_ERR_ARG,
00072 "Invalid array_of_subsizes argument",
00073 0);
00074 return MPIO_Err_return_comm(MPI_COMM_SELF, error_code);
00075 }
00076 if (array_of_starts <= (int *) 0) {
00077 error_code = MPIO_Err_create_code(MPI_SUCCESS,
00078 MPIR_ERR_RECOVERABLE,
00079 myname, __LINE__, MPI_ERR_ARG,
00080 "Invalid array_of_starts argument",
00081 0);
00082 return MPIO_Err_return_comm(MPI_COMM_SELF, error_code);
00083 }
00084
00085 for (i=0; i<ndims; i++) {
00086 if (array_of_sizes[i] <= 0) {
00087 error_code = MPIO_Err_create_code(MPI_SUCCESS,
00088 MPIR_ERR_RECOVERABLE,
00089 myname, __LINE__, MPI_ERR_ARG,
00090 "Invalid size argument", 0);
00091 return MPIO_Err_return_comm(MPI_COMM_SELF, error_code);
00092 }
00093 if (array_of_subsizes[i] <= 0) {
00094 error_code = MPIO_Err_create_code(MPI_SUCCESS,
00095 MPIR_ERR_RECOVERABLE,
00096 myname, __LINE__, MPI_ERR_ARG,
00097 "Invalid subsize argument", 0);
00098 return MPIO_Err_return_comm(MPI_COMM_SELF, error_code);
00099 }
00100 if (array_of_starts[i] < 0) {
00101 error_code = MPIO_Err_create_code(MPI_SUCCESS,
00102 MPIR_ERR_RECOVERABLE,
00103 myname, __LINE__, MPI_ERR_ARG,
00104 "Invalid start argument", 0);
00105 return MPIO_Err_return_comm(MPI_COMM_SELF, error_code);
00106 }
00107 if (array_of_subsizes[i] > array_of_sizes[i]) {
00108 error_code = MPIO_Err_create_code(MPI_SUCCESS,
00109 MPIR_ERR_RECOVERABLE,
00110 myname, __LINE__, MPI_ERR_ARG,
00111 "Invalid subsize argument", 0);
00112 return MPIO_Err_return_comm(MPI_COMM_SELF, error_code);
00113 }
00114 if (array_of_starts[i] > (array_of_sizes[i] - array_of_subsizes[i])) {
00115 error_code = MPIO_Err_create_code(MPI_SUCCESS,
00116 MPIR_ERR_RECOVERABLE,
00117 myname, __LINE__, MPI_ERR_ARG,
00118 "Invalid start argument", 0);
00119 return MPIO_Err_return_comm(MPI_COMM_SELF, error_code);
00120 }
00121 }
00122
00123
00124
00125 if (oldtype == MPI_DATATYPE_NULL) {
00126 error_code = MPIO_Err_create_code(MPI_SUCCESS,
00127 MPIR_ERR_RECOVERABLE,
00128 myname, __LINE__, MPI_ERR_ARG,
00129 "Invalid type argument", 0);
00130 return MPIO_Err_return_comm(MPI_COMM_SELF, error_code);
00131 }
00132
00133 MPI_Type_extent(oldtype, &extent);
00134
00135
00136
00137
00138 size_with_aint = extent;
00139 for (i=0; i<ndims; i++) size_with_aint *= array_of_sizes[i];
00140 size_with_offset = extent;
00141 for (i=0; i<ndims; i++) size_with_offset *= array_of_sizes[i];
00142 if (size_with_aint != size_with_offset) {
00143 error_code = MPIO_Err_create_code(MPI_SUCCESS,
00144 MPIR_ERR_RECOVERABLE,
00145 myname, __LINE__, MPI_ERR_ARG,
00146 "Invalid size argument", 0);
00147 return MPIO_Err_return_comm(MPI_COMM_SELF, error_code);
00148 }
00149
00150 if (order != MPI_ORDER_FORTRAN && order != MPI_ORDER_C) {
00151 error_code = MPIO_Err_create_code(MPI_SUCCESS,
00152 MPIR_ERR_RECOVERABLE,
00153 myname, __LINE__, MPI_ERR_ARG,
00154 "Invalid order argument", 0);
00155 return MPIO_Err_return_comm(MPI_COMM_SELF, error_code);
00156 }
00157
00158
00159 err = ADIO_Type_create_subarray(ndims,
00160 array_of_sizes,
00161 array_of_subsizes,
00162 array_of_starts,
00163 order,
00164 oldtype,
00165 newtype);
00166
00167 if (err != MPI_SUCCESS) {
00168 error_code = MPIO_Err_create_code(MPI_SUCCESS,
00169 MPIR_ERR_RECOVERABLE,
00170 myname, __LINE__, err,
00171 "Internal error", 0);
00172 }
00173
00174
00175 return MPI_SUCCESS;
00176 }