This source file includes following definitions.
- ompi_datatype_create_subarray
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 #include "ompi_config.h"
26
27 #include <stddef.h>
28
29 #include "ompi/datatype/ompi_datatype.h"
30
31 int32_t ompi_datatype_create_subarray(int ndims,
32 int const* size_array,
33 int const* subsize_array,
34 int const* start_array,
35 int order,
36 const ompi_datatype_t* oldtype,
37 ompi_datatype_t** newtype)
38 {
39 ompi_datatype_t *last_type;
40 int32_t i, step, end_loop;
41 MPI_Aint size, displ, extent;
42
43
44
45
46
47
48
49 ompi_datatype_type_extent( oldtype, &extent );
50
51
52 if( ndims < 2 ) {
53 if( 0 == ndims ) {
54 ompi_datatype_duplicate(&ompi_mpi_datatype_null.dt, newtype);
55 return MPI_SUCCESS;
56 }
57 ompi_datatype_create_contiguous( subsize_array[0], oldtype, &last_type );
58 size = size_array[0];
59 displ = start_array[0];
60 goto replace_subarray_type;
61 }
62
63 if( MPI_ORDER_C == order ) {
64 i = ndims - 1;
65 step = -1;
66 end_loop = -1;
67 } else {
68 i = 0;
69 step = 1;
70 end_loop = ndims;
71 }
72
73
74
75
76
77 ompi_datatype_create_vector( subsize_array[i+step], subsize_array[i], size_array[i],
78 oldtype, newtype );
79
80 last_type = *newtype;
81 size = (MPI_Aint)size_array[i] * (MPI_Aint)size_array[i+step];
82 displ = (MPI_Aint)start_array[i] + (MPI_Aint)start_array[i+step] * (MPI_Aint)size_array[i];
83 for( i += 2 * step; i != end_loop; i += step ) {
84 ompi_datatype_create_hvector( subsize_array[i], 1, size * extent,
85 last_type, newtype );
86 ompi_datatype_destroy( &last_type );
87
88 displ += size * start_array[i];
89 size *= size_array[i];
90 last_type = *newtype;
91 }
92
93 replace_subarray_type:
94
95
96
97
98
99
100
101
102 *newtype = ompi_datatype_create( last_type->super.desc.used );
103 ompi_datatype_add( *newtype, last_type, 1, displ * extent, size * extent);
104 ompi_datatype_destroy( &last_type );
105 opal_datatype_resize( &(*newtype)->super, 0, size * extent );
106
107 return OMPI_SUCCESS;
108 }