1

I am getting a segfault in C = C + matmul(A(:, 1 + (l - 1) * n / p: l * n / p), B(:,:)[l]) using gfortran + mpich, with n = 4000, p = 2. Is it not allowed to pass slices of distributed arrays into functions? When copying out B(:,:)[l], it is super slow, and I get a "unexpected tag-receive descriptor 0x561965b27900 was not matched"-error (though after the program finishes).

program main
    implicit none

    integer :: n, p, l
    real(KIND=8), allocatable :: A(:,:)[:], B(:,:)[:], C(:,:)[:]
    character(len=12), dimension(:), allocatable :: args
    integer :: cpu_count, cpu_count2, count_rate, count_max

    allocate(args(1))
    call get_command_argument(1, args(1))
    read (unit=args(1),fmt=*) n

    p = num_images()

    if (modulo(n, p) /= 0) then
        write (*, *) 'Please make sure n divides p'
    end if

    allocate(A(n / p, n)[*])
    allocate(B(n / p, n)[*])
    allocate(C(n / p, n)[*])

    A = 1
    B = 1
    C = 0

    sync all
    call system_clock(cpu_count, count_rate, count_max)

    do l = 1, num_images()
        C = C + matmul(A(:, 1 + (l - 1) * n / p: l * n / p), B(:,:)[l])
    end do

    sync all
    call system_clock(cpu_count2, count_rate, count_max)

    if (this_image() .eq. 1) then
        write (*, *) 2.0 * n * n * n / (real(cpu_count2 - cpu_count) / &
                    count_rate) / 1000000000.0
    end if
end program main
  • 1
    There certainly restrictions on a actual argument like `B[1]` that don't apply to those like `B`. Are you interested in the general case as "Is it not allowed to pass slices of distributed arrays into functions?" strictly asks, or the specific case of this code? – francescalus Jun 26 '23 at 15:37
  • 1
    What versions of (presumably) OpenCoarrays, GCC, MPICH, ... are you using, and how are you compiling/running? – francescalus Jun 26 '23 at 15:38
  • @francescalus GCC 12.2.0, mpich 2.10.1. I think OpenCoarrays is part of GCC now, I didn't install anything special. Compiled with ```gfortran matrix.f90 -fcoarray=lib -lcaf_mpich``` I am interested in both the general case, and why it goes wrong in this specific example. – asdfldsfdfjjfddjf Jun 26 '23 at 17:17
  • @asdfldsfdfjjfddjf OpenCoarrays have to be compiled against some particular MPI library so cannot just be in the GCC, at least cannot be compiled before an MPI library is compiled. Do you use some distribution packages? Which ones exactly? – Vladimir F Героям слава Jun 27 '23 at 12:41
  • It's compiled against mpich. Except for the standard gcc and mpich packages (I think they came with my distribution), I only installed libcaf-mpich-3 from apt – asdfldsfdfjjfddjf Jun 27 '23 at 12:43
  • So which distribution? Is it Linux? Which one, Ubuntu? – Vladimir F Героям слава Jun 27 '23 at 12:45
  • @VladimirFГероямслава Ubuntu 23.04 – asdfldsfdfjjfddjf Jun 27 '23 at 12:46

0 Answers0