Skip to content

Commit 793d6bb

Browse files
committed
add support for distrib array and order
for subarray type datatype constructors Signed-off-by: Howard Pritchard <[email protected]>
1 parent f525c8e commit 793d6bb

File tree

4 files changed

+80
-3
lines changed

4 files changed

+80
-3
lines changed

ompi/mpi/bindings/ompi_bindings/c.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,12 @@ def generate_comm_split_type_convert_fn(self):
525525
def generate_weight_convert_fn(self):
526526
self.generic_convert(ConvertFuncs.WEIGHTS, 'weights', 'int *', consts.RESERVED_WEIGHTS)
527527

528+
def generate_subarray_order_convert_fn(self):
529+
self.generic_convert(ConvertFuncs.SUBARRAY_ORDER, 'order', 'int', consts.SUBARRAY_ORDER_TYPES)
530+
531+
def generate_subarray_distrib_types_convert_fn(self):
532+
self.generic_convert(ConvertFuncs.SUBARRAY_DISTRIB_TYPES, 'dist', 'int', consts.SUBARRAY_DISTRIB_TYPES)
533+
528534
def generate_pointer_convert_fn(self, type_, fn_name, constants):
529535
abi_type = self.mangle_name(type_)
530536
self.dump(f'{consts.INLINE_ATTRS} void {fn_name}({abi_type} *ptr)')
@@ -677,6 +683,8 @@ def dump_code(self):
677683
self.generate_win_delete_attr_convert_fn()
678684
self.generate_comm_split_type_convert_fn()
679685
self.generate_weight_convert_fn()
686+
self.generate_subarray_order_convert_fn()
687+
self.generate_subarray_distrib_types_convert_fn()
680688

681689
#
682690
# the following only need intern to abi converters

ompi/mpi/bindings/ompi_bindings/c_type.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,6 +2578,22 @@ def init_code(self):
25782578
def type_text(self, enable_count=False):
25792579
return 'int'
25802580

2581+
@Type.add_type('SUBARRAY_ORDER', abi_type=['ompi'])
2582+
class TypeSubarrayOrderType(Type):
2583+
2584+
def type_text(self, enable_count=False):
2585+
return 'int'
2586+
2587+
@Type.add_type('SUBARRAY_ORDER', abi_type=['standard'])
2588+
class TyperSubArraOrderStandard(StandardABIType):
2589+
2590+
@property
2591+
def init_code(self):
2592+
return [f'int {self.tmpname} = {ConvertFuncs.SUBARRAY_ORDER}({self.name});']
2593+
2594+
def type_text(self, enable_count=False):
2595+
return 'int'
2596+
25812597
@Type.add_type('WEIGHTS', abi_type=['ompi'])
25822598
class TypeWeightType(Type):
25832599

@@ -2647,3 +2663,42 @@ def type_text(self, enable_count=False):
26472663
@property
26482664
def argument(self):
26492665
return f'(MPI_T_event_instance){self.name}'
2666+
2667+
@Type.add_type('DISTRIB_ARRAY', abi_type=['ompi'])
2668+
class TypeDistributionArray(Type):
2669+
2670+
def type_text(self, enable_count=False):
2671+
return 'const int *'
2672+
2673+
def parameter(self, enable_count=False, **kwargs):
2674+
return f'const int {self.name}[]'
2675+
2676+
@Type.add_type('DISTRIB_ARRAY', abi_type=['standard'])
2677+
class TypeDistributioneArrayStandard(StandardABIType):
2678+
2679+
@property
2680+
def init_code(self):
2681+
code = [f'int size_{self.tmpname} = {self.count_param};']
2682+
code.append(f'int *{self.tmpname} = NULL;')
2683+
code.append('if('+f'{self.name}' + '!= NULL)' + '{')
2684+
code.append(f'{self.tmpname} = (int *)malloc(sizeof(int) * size_{self.tmpname});')
2685+
code.append(f'for(int i=0;i<size_{self.tmpname};i++){{')
2686+
code.append(f'{self.tmpname}[i] = {ConvertFuncs.SUBARRAY_DISTRIB_TYPES}({self.name}[i]);')
2687+
code.append(f'}}')
2688+
code.append(f'}}')
2689+
return code
2690+
2691+
@property
2692+
def final_code(self):
2693+
code = [f'if({self.tmpname} != NULL){{']
2694+
code.append(f'free({self.tmpname});')
2695+
code.append('}')
2696+
return code
2697+
2698+
def type_text(self, enable_count=False):
2699+
return 'const int *'
2700+
2701+
def parameter(self, enable_count=False, **kwargs):
2702+
return f'const int {self.name}[]'
2703+
2704+

ompi/mpi/bindings/ompi_bindings/consts.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,18 @@
188188
'MPI_COMM_TYPE_RESOURCE_GUIDED',
189189
]
190190

191+
SUBARRAY_ORDER_TYPES = [
192+
'MPI_ORDER_C',
193+
'MPI_ORDER_FORTRAN',
194+
]
195+
196+
SUBARRAY_DISTRIB_TYPES = [
197+
'MPI_DISTRIBUTE_NONE',
198+
'MPI_DISTRIBUTE_BLOCK',
199+
'MPI_DISTRIBUTE_CYCLIC',
200+
'MPI_DISTRIBUTE_DFLT_DARG',
201+
]
202+
191203
RESERVED_GROUPS = [
192204
'MPI_GROUP_NULL',
193205
]
@@ -497,7 +509,8 @@ class ConvertFuncs:
497509
WIN_DELETE_ATTR_FUNCTION = 'ompi_convert_win_delete_attr_fn_intern_win_delete_attr_fn'
498510
SPLIT_TYPE = 'ompi_convert_split_type_intern_type'
499511
WEIGHTS = 'ompi_convert_weight_intern_weight'
500-
512+
SUBARRAY_ORDER = 'ompi_convert_subarray_order_intern_subarray_order'
513+
SUBARRAY_DISTRIB_TYPES = 'ompi_convert_subarray_distrib_type_intern_distrib_type'
501514

502515
class ConvertOMPIToStandard:
503516
"""Generated function for converting from OMPI to standard ABI."""
@@ -528,6 +541,7 @@ class ConvertOMPIToStandard:
528541
ATTR_KEY = 'ompi_convert_attr_key_ompi_to_standard'
529542
COMM_CMP = 'ompi_convert_comm_cmp_ompi_to_standard'
530543
SOURCE = 'ompi_convert_source_ompi_to_standard'
544+
SUBARRAY_ORDER = 'ompi_convert_subarray_order_ompi_to_standard'
531545

532546

533547
# Inline function attributes

ompi/mpi/c/type_create_darray.c.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ PROTOTYPE ERROR_CLASS type_create_darray(INT size,
4343
INT rank,
4444
INT ndims,
4545
COUNT_ARRAY gsize_array,
46-
INT_ARRAY distrib_array,
46+
DISTRIB_ARRAY distrib_array:ndims,
4747
INT_ARRAY darg_array,
4848
INT_ARRAY psize_array,
49-
INT order,
49+
SUBARRAY_ORDER order,
5050
DATATYPE oldtype,
5151
DATATYPE_OUT newtype)
5252
{

0 commit comments

Comments
 (0)