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