This source file includes following definitions.
- opal_convertor_create_stack_with_pos_general
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #include "opal_config.h"
24
25 #include <stddef.h>
26 #include <stdlib.h>
27
28 #ifdef HAVE_ALLOCA_H
29 #include <alloca.h>
30 #endif
31
32 #include "opal/datatype/opal_datatype.h"
33 #include "opal/datatype/opal_convertor.h"
34 #include "opal/datatype/opal_datatype_internal.h"
35
36
37 extern int opal_convertor_create_stack_with_pos_general( opal_convertor_t* convertor,
38 size_t starting_point, const size_t* sizes );
39
40 int opal_convertor_create_stack_with_pos_general( opal_convertor_t* pConvertor,
41 size_t starting_point, const size_t* sizes )
42 {
43 dt_stack_t* pStack;
44 int pos_desc;
45 size_t lastLength = 0;
46 const opal_datatype_t* pData = pConvertor->pDesc;
47 size_t loop_length, *remoteLength, remote_size;
48 size_t resting_place = starting_point;
49 dt_elem_desc_t* pElems;
50 size_t count;
51
52 assert( 0 != starting_point );
53 assert( pConvertor->bConverted != starting_point );
54 assert( starting_point <=(pConvertor->count * pData->size) );
55
56
57
58
59 pConvertor->stack_pos = 0;
60 pStack = pConvertor->pStack;
61
62
63
64
65 pElems = pConvertor->use_desc->desc;
66
67 if( (pConvertor->flags & CONVERTOR_HOMOGENEOUS) && (pData->flags & OPAL_DATATYPE_FLAG_CONTIGUOUS) ) {
68
69 int32_t cnt = (int32_t)(starting_point / pData->size);
70 ptrdiff_t extent = pData->ub - pData->lb;
71
72 loop_length = GET_FIRST_NON_LOOP( pElems );
73 pStack[0].disp = pElems[loop_length].elem.disp;
74 pStack[0].type = OPAL_DATATYPE_LOOP;
75 pStack[0].count = pConvertor->count - cnt;
76 cnt = (int32_t)(starting_point - cnt * pData->size);
77 pStack[1].index = 0;
78 pStack[1].type = OPAL_DATATYPE_UINT1;
79 pStack[1].disp = pStack[0].disp;
80 pStack[1].count = pData->size - cnt;
81
82 if( (ptrdiff_t)pData->size == extent ) {
83 pStack[1].disp += starting_point;
84 } else {
85 pStack[1].disp += (pConvertor->count - pStack[0].count) * extent + cnt;
86 }
87
88 pConvertor->bConverted = starting_point;
89 pConvertor->stack_pos = 1;
90 return OPAL_SUCCESS;
91 }
92
93
94 assert (! (pConvertor->flags & CONVERTOR_SEND));
95 remote_size = opal_convertor_compute_remote_size( pConvertor );
96 count = starting_point / remote_size;
97 resting_place -= (remote_size * count);
98 pStack->count = pConvertor->count - count;
99 pStack->index = -1;
100
101 loop_length = GET_FIRST_NON_LOOP( pElems );
102 pStack->disp = count * (pData->ub - pData->lb) + pElems[loop_length].elem.disp;
103
104 pos_desc = 0;
105 remoteLength = (size_t*)alloca( sizeof(size_t) * (pConvertor->pDesc->loops + 1));
106 remoteLength[0] = 0;
107 loop_length = 0;
108
109
110
111
112 while( pos_desc < (int32_t)pConvertor->use_desc->used ) {
113 if( OPAL_DATATYPE_END_LOOP == pElems->elem.common.type ) {
114 ddt_endloop_desc_t* end_loop = (ddt_endloop_desc_t*)pElems;
115 ptrdiff_t extent;
116
117 if( (loop_length * pStack->count) > resting_place ) {
118
119
120
121
122
123 int32_t cnt = (int32_t)(resting_place / loop_length);
124 if( pStack->index == -1 ) {
125 extent = pData->ub - pData->lb;
126 } else {
127 assert( OPAL_DATATYPE_LOOP == (pElems - end_loop->items)->loop.common.type );
128 extent = ((ddt_loop_desc_t*)(pElems - end_loop->items))->extent;
129 }
130 pStack->count -= (cnt + 1);
131 resting_place -= cnt * loop_length;
132 pStack->disp += (cnt + 1) * extent;
133
134 pos_desc -= (end_loop->items - 1);
135 pElems -= (end_loop->items - 1);
136 remoteLength[pConvertor->stack_pos] = 0;
137 loop_length = 0;
138 continue;
139 }
140
141
142
143 resting_place -= (loop_length * (pStack->count - 1));
144 pStack--;
145 pConvertor->stack_pos--;
146 pos_desc++;
147 pElems++;
148 remoteLength[pConvertor->stack_pos] += (loop_length * pStack->count);
149 loop_length = remoteLength[pConvertor->stack_pos];
150 continue;
151 }
152 if( OPAL_DATATYPE_LOOP == pElems->elem.common.type ) {
153 remoteLength[pConvertor->stack_pos] += loop_length;
154 PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, OPAL_DATATYPE_LOOP,
155 pElems->loop.loops, pStack->disp );
156 pos_desc++;
157 pElems++;
158 remoteLength[pConvertor->stack_pos] = 0;
159 loop_length = 0;
160 }
161 while( pElems->elem.common.flags & OPAL_DATATYPE_FLAG_DATA ) {
162
163 const opal_datatype_t* basic_type = BASIC_DDT_FROM_ELEM( (*pElems) );
164 lastLength = pElems->elem.count * basic_type->size;
165 if( resting_place < lastLength ) {
166 int32_t cnt = (int32_t)(resting_place / basic_type->size);
167 loop_length += (cnt * basic_type->size);
168 resting_place -= (cnt * basic_type->size);
169 PUSH_STACK( pStack, pConvertor->stack_pos, pos_desc, pElems->elem.common.type,
170 pElems->elem.count - cnt,
171 pElems->elem.disp + cnt * pElems->elem.extent );
172 pConvertor->bConverted = starting_point - resting_place;
173 DDT_DUMP_STACK( pConvertor->pStack, pConvertor->stack_pos,
174 pConvertor->pDesc->desc.desc, pConvertor->pDesc->name );
175 return OPAL_SUCCESS;
176 }
177 loop_length += lastLength;
178 resting_place -= lastLength;
179 pos_desc++;
180 pElems++;
181 }
182 }
183
184
185 pConvertor->flags |= CONVERTOR_COMPLETED;
186 pConvertor->bConverted = pConvertor->local_size;
187 return OPAL_SUCCESS;
188 }