Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28456 Discussions

Is Array slicing allowed in Fortran 2018 collectives?

N_Netto
Beginner
319 Views

I've come across a situation that I need to perform a equivalent of mpi_allreduce (mpi_allgather would suffice) in Coarray application. 

At first, i trying co_sum() collective, but I was suspecting that it was very slow (VTune pointed out that MPI_REDUCE was very heavy on my application and the co_sum()  has other bug that Intel already took notice), so I was trying to make my on allreduce function. 

I was trying to broadcast slices of an array to every process. However, I find the results odd. The following code:

    program ColectiveFunctionSlice

    implicit none
    
    integer(4), dimension(8)    :: array
    
    array = this_image()
    
    call co_broadcast( array(5:6), 3 ) ! At this point, [3 3] should be passed to everyone at positions 5 and 6
    
    critical
        write( *, '(A,I0,A,8(I0,X),A)' ) 'I am #', this_image(), ' and this is my array [', array, "]"
    end critical
    sync all
    if( this_image() == 1 ) write(*,*) " " 
    
    if( this_image() == 4 ) then
        array(7:8) = 0
        array(1:2) = 8
    endif
    
    call co_broadcast( array(7:8), 4 ) ! At this point, [0 0] should be passed to everyone at positions 7 and 8, but will pass [8 8] 
    critical
        write( *, '(A,I0,A,8(I0,X),A)' ) 'I am #', this_image(), ' and this is my array [', array, "]"
    end critical
    
    end program ColectiveFunctionSlice

Gives the following result:

 

I am #1 and this is my array [3 3 1 1 1 1 1 1 ]
I am #2 and this is my array [3 3 2 2 2 2 2 2 ]
I am #4 and this is my array [3 3 4 4 4 4 4 4 ]
I am #3 and this is my array [3 3 3 3 3 3 3 3 ]

I am #1 and this is my array [8 8 1 1 1 1 1 1 ]
I am #3 and this is my array [8 8 3 3 3 3 3 3 ]
I am #4 and this is my array [8 8 4 4 4 4 0 0 ]
I am #2 and this is my array [8 8 2 2 2 2 2 2 ]

In the first group of write, I was expecting to pass the [3 3] slice into postions 5 and 6, however, the slice array(1:2) was passed.

This situation is clearer in the second group. There, I was trying to broadcast [0 0], however, the [8 8] was broadcast.

Is this a bug of the collective functions, or can it be something else related to how Fortran manipulate the data?

Thanks,

0 Kudos
0 Replies
Reply