@@ -6791,7 +6791,7 @@ internal_co_reduce (MPI_Op op, gfc_descriptor_t *source, int result_image, int *
67916791 MPI_Datatype datatype = get_MPI_datatype (source , src_len );
67926792
67936793 size = 1 ;
6794- for (j = 0 ; j < rank ; j ++ )
6794+ for (j = 0 ; j < rank ; ++ j )
67956795 {
67966796 ptrdiff_t dimextent = source -> dim [j ]._ubound
67976797 - source -> dim [j ].lower_bound + 1 ;
@@ -6816,21 +6816,18 @@ internal_co_reduce (MPI_Op op, gfc_descriptor_t *source, int result_image, int *
68166816 goto co_reduce_cleanup ;
68176817 }
68186818
6819- for (i = 0 ; i < size ; i ++ )
6819+ for (i = 0 ; i < size ; ++ i )
68206820 {
68216821 ptrdiff_t array_offset_sr = 0 ;
6822- ptrdiff_t stride = 1 ;
6822+ ptrdiff_t tot_ext = 1 ;
68236823 ptrdiff_t extent = 1 ;
6824- for (j = 0 ; j < GFC_DESCRIPTOR_RANK ( source ) - 1 ; j ++ )
6824+ for (j = 0 ; j < rank - 1 ; ++ j )
68256825 {
6826- array_offset_sr += ((i / (extent * stride ))
6827- % (source -> dim [j ]._ubound
6828- - source -> dim [j ].lower_bound + 1 ))
6829- * source -> dim [j ]._stride ;
68306826 extent = (source -> dim [j ]._ubound - source -> dim [j ].lower_bound + 1 );
6831- stride = source -> dim [j ]._stride ;
6827+ array_offset_sr += ((i / tot_ext ) % extent ) * source -> dim [j ]._stride ;
6828+ tot_ext *= extent ;
68326829 }
6833- array_offset_sr += (i / extent ) * source -> dim [rank - 1 ]._stride ;
6830+ array_offset_sr += (i / tot_ext ) * source -> dim [rank - 1 ]._stride ;
68346831 void * sr = (void * )((char * ) source -> base_addr
68356832 + array_offset_sr * GFC_DESCRIPTOR_SIZE (source ));
68366833 if (result_image == 0 )
@@ -6884,10 +6881,9 @@ PREFIX (co_broadcast) (gfc_descriptor_t *a, int source_image, int *stat, char *e
68846881 MPI_Datatype datatype = get_MPI_datatype (a , 0 );
68856882
68866883 size = 1 ;
6887- for (j = 0 ; j < rank ; j ++ )
6884+ for (j = 0 ; j < rank ; ++ j )
68886885 {
6889- ptrdiff_t dimextent = a -> dim [j ]._ubound
6890- - a -> dim [j ].lower_bound + 1 ;
6886+ ptrdiff_t dimextent = a -> dim [j ]._ubound - a -> dim [j ].lower_bound + 1 ;
68916887 if (dimextent < 0 )
68926888 dimextent = 0 ;
68936889 size *= dimextent ;
@@ -6919,21 +6915,18 @@ PREFIX (co_broadcast) (gfc_descriptor_t *a, int source_image, int *stat, char *e
69196915 caf_runtime_error ("Co_broadcast of character arrays not yet supported\n" );
69206916 }
69216917
6922- for (i = 0 ; i < size ; i ++ )
6918+ for (i = 0 ; i < size ; ++ i )
69236919 {
69246920 ptrdiff_t array_offset_sr = 0 ;
6925- ptrdiff_t stride = 1 ;
6921+ ptrdiff_t tot_ext = 1 ;
69266922 ptrdiff_t extent = 1 ;
6927- for (j = 0 ; j < GFC_DESCRIPTOR_RANK ( a ) - 1 ; j ++ )
6923+ for (j = 0 ; j < rank - 1 ; ++ j )
69286924 {
6929- array_offset_sr += ((i / (extent * stride ))
6930- % (a -> dim [j ]._ubound
6931- - a -> dim [j ].lower_bound + 1 ))
6932- * a -> dim [j ]._stride ;
69336925 extent = (a -> dim [j ]._ubound - a -> dim [j ].lower_bound + 1 );
6934- stride = a -> dim [j ]._stride ;
6926+ array_offset_sr += ((i / tot_ext ) % extent ) * a -> dim [j ]._stride ;
6927+ tot_ext *= extent ;
69356928 }
6936- array_offset_sr += (i / ( extent * stride ) ) * a -> dim [rank - 1 ]._stride ;
6929+ array_offset_sr += (i / tot_ext ) * a -> dim [rank - 1 ]._stride ;
69376930 void * sr = (void * )((char * ) a -> base_addr
69386931 + array_offset_sr * GFC_DESCRIPTOR_SIZE (a ));
69396932
0 commit comments