00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "dataloop.h"
00011
00012 int PREPEND_PREFIX(Type_convert_subarray)(int ndims,
00013 int *array_of_sizes,
00014 int *array_of_subsizes,
00015 int *array_of_starts,
00016 int order,
00017 MPI_Datatype oldtype,
00018 MPI_Datatype *newtype)
00019 {
00020 MPI_Aint extent, disps[3], size;
00021 int i, blklens[3];
00022 MPI_Datatype tmp1, tmp2, types[3];
00023
00024 MPI_Type_extent(oldtype, &extent);
00025
00026 if (order == MPI_ORDER_FORTRAN) {
00027
00028 if (ndims == 1) {
00029 MPI_Type_contiguous(array_of_subsizes[0], oldtype, &tmp1);
00030 }
00031 else {
00032 MPI_Type_vector(array_of_subsizes[1],
00033 array_of_subsizes[0],
00034 array_of_sizes[0], oldtype, &tmp1);
00035
00036 size = array_of_sizes[0]*extent;
00037 for (i=2; i<ndims; i++) {
00038 size *= array_of_sizes[i-1];
00039 MPI_Type_hvector(array_of_subsizes[i], 1, size, tmp1, &tmp2);
00040 MPI_Type_free(&tmp1);
00041 tmp1 = tmp2;
00042 }
00043 }
00044
00045
00046 disps[1] = array_of_starts[0];
00047 size = 1;
00048 for (i=1; i<ndims; i++) {
00049 size *= array_of_sizes[i-1];
00050 disps[1] += size*array_of_starts[i];
00051 }
00052
00053 }
00054
00055 else {
00056
00057 if (ndims == 1) {
00058 MPI_Type_contiguous(array_of_subsizes[0], oldtype, &tmp1);
00059 }
00060 else {
00061 MPI_Type_vector(array_of_subsizes[ndims-2],
00062 array_of_subsizes[ndims-1],
00063 array_of_sizes[ndims-1], oldtype, &tmp1);
00064
00065 size = array_of_sizes[ndims-1]*extent;
00066 for (i=ndims-3; i>=0; i--) {
00067 size *= array_of_sizes[i+1];
00068 MPI_Type_hvector(array_of_subsizes[i], 1, size, tmp1, &tmp2);
00069 MPI_Type_free(&tmp1);
00070 tmp1 = tmp2;
00071 }
00072 }
00073
00074
00075 disps[1] = array_of_starts[ndims-1];
00076 size = 1;
00077 for (i=ndims-2; i>=0; i--) {
00078 size *= array_of_sizes[i+1];
00079 disps[1] += size*array_of_starts[i];
00080 }
00081 }
00082
00083 disps[1] *= extent;
00084
00085 disps[2] = extent;
00086 for (i=0; i<ndims; i++) disps[2] *= array_of_sizes[i];
00087
00088 disps[0] = 0;
00089 blklens[0] = blklens[1] = blklens[2] = 1;
00090 types[0] = MPI_LB;
00091 types[1] = tmp1;
00092 types[2] = MPI_UB;
00093
00094 MPI_Type_struct(3, blklens, disps, types, newtype);
00095
00096 MPI_Type_free(&tmp1);
00097
00098 return MPI_SUCCESS;
00099 }