This source file includes following definitions.
- ADIO_Type_create_subarray
1
2
3
4
5
6
7
8 #include "adio.h"
9 #include "adio_extern.h"
10
11 int ADIO_Type_create_subarray(int ndims,
12 int *array_of_sizes,
13 int *array_of_subsizes,
14 int *array_of_starts,
15 int order,
16 MPI_Datatype oldtype,
17 MPI_Datatype *newtype)
18 {
19 MPI_Aint extent, disp, size, lb, ub;
20 int i, blklen;
21 MPI_Datatype tmp1, tmp2, inttype;
22
23 MPI_Type_get_extent(oldtype, &lb, &extent);
24
25 if (order == MPI_ORDER_FORTRAN) {
26
27 if (ndims == 1) {
28 MPI_Type_contiguous(array_of_subsizes[0], oldtype, &tmp1);
29 }
30 else {
31 MPI_Type_vector(array_of_subsizes[1],
32 array_of_subsizes[0],
33 array_of_sizes[0], oldtype, &tmp1);
34
35 size = (MPI_Aint)array_of_sizes[0]*extent;
36 for (i=2; i<ndims; i++) {
37 size *= (MPI_Aint)array_of_sizes[i-1];
38 MPI_Type_create_hvector(array_of_subsizes[i], 1, size, tmp1, &tmp2);
39 MPI_Type_free(&tmp1);
40 tmp1 = tmp2;
41 }
42 }
43
44
45 disp = array_of_starts[0];
46 size = 1;
47 for (i=1; i<ndims; i++) {
48 size *= (MPI_Aint)array_of_sizes[i-1];
49 disp += size*(MPI_Aint)array_of_starts[i];
50 }
51
52 }
53
54 else {
55
56 if (ndims == 1) {
57 MPI_Type_contiguous(array_of_subsizes[0], oldtype, &tmp1);
58 }
59 else {
60 MPI_Type_vector(array_of_subsizes[ndims-2],
61 array_of_subsizes[ndims-1],
62 array_of_sizes[ndims-1], oldtype, &tmp1);
63
64 size = (MPI_Aint)array_of_sizes[ndims-1]*extent;
65 for (i=ndims-3; i>=0; i--) {
66 size *= (MPI_Aint)array_of_sizes[i+1];
67 MPI_Type_create_hvector(array_of_subsizes[i], 1, size, tmp1, &tmp2);
68 MPI_Type_free(&tmp1);
69 tmp1 = tmp2;
70 }
71 }
72
73
74 disp = array_of_starts[ndims-1];
75 size = 1;
76 for (i=ndims-2; i>=0; i--) {
77 size *= (MPI_Aint)array_of_sizes[i+1];
78 disp += size*(MPI_Aint)array_of_starts[i];
79 }
80 }
81
82 disp *= extent;
83
84 ub = extent;
85 for (i=0; i<ndims; i++) ub *= (MPI_Aint)array_of_sizes[i];
86
87 blklen = 1;
88
89 MPI_Type_create_struct(1, &blklen, &disp, &tmp1, &inttype);
90 MPI_Type_create_resized (inttype, 0, ub, newtype);
91 MPI_Type_free(&inttype);
92
93 MPI_Type_free(&tmp1);
94
95 return MPI_SUCCESS;
96 }