OpenCoarrays using homebrew – I guess you have to be lucky to get it working :(

Yet another way of using OpenCoarrays is to work with homebrew. However, there is one, small, issue. Note that OpenCoarrays may not work with OpenMPI. You can find description of the issue here: https://github.com/sourceryinstitute/OpenCoarrays/issues/625, and here is the original post on StackOverflowWhy does coarray with allocatable component creates segmentation faults when accessed from different image?.

If you want to have it run via homebrew, you have to follow these steps:

> cd ~/opt
> mkdir homebrew
> curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
> cd homebrew
> ./bin/brew cleanup
> ./bin/brew install gcc
> ./bin/brew install opencoarrays

once you have it, you can try with sample code (make sure to put it inside ~/tmp/hello.f90).

program hello_world
implicit none
  write(*,*) 'Hello world from ', &
   this_image() , 'of', num_images()
end program hello_world

and … it doesn’t work as expected :(

> cd ~/tmp
> ~/opt/homebrew/bin/caf -o hello hello.f90
ld: warning: directory not found for option '-L/Users/.../opt/homebrew/Cellar/open-mpi/4.0.1_2/lib'

The issue here is that for some reason (I don’t know what, yet), caf wrapper tries to use incorrect location for MPI libraries.

lib
|-- cmake
|   `-- opencoarrays -> ../../Cellar/opencoarrays/2.8.0/lib/cmake/opencoarrays
|-- gcc -> ../Cellar/gcc/9.2.0_3/lib/gcc
|-- openmpi -> ../Cellar/open-mpi/4.0.2/lib/openmpi
|-- pkgconfig
`-- pmix -> ../Cellar/open-mpi/4.0.2/lib/pmix

if you play a little bit, you can get it working. Just make sure to make caf happy when it comes to location of libraries provided by OpenMPI.

> cd ~/opt/homebrew/Cellar/open-mpi/
> ln -s 4.0.1_2

And now, let’s try it again

> ~/opt/homebrew/bin/caf -o hello hello.f90
> ~/opt/homebrew/bin/cafrun -np 2 ./hello
 Hello world from            1 of           2
 Hello world from            2 of           2

Success! But hey! Not so fast! Let’s try initial sample code from the issue submitted on StackOverflow.

program Main
    implicit none

    type :: Array_Type
        double precision, dimension(:), allocatable :: values
    end type
    type(Array_Type), codimension[*] :: array

    allocate(array%values(2))
    sync all

    print *, this_image(), array[1]%values(:)
    sync all
end program

Save it inside ~/tmp/coarrays_error.f90.

> ~/opt/homebrew/bin/caf -o coarrays_error coarrays_error.f90
> ~/opt/homebrew/bin/cafrun -np 2 ./coarrays_error
           1  -1.4916681462400413E-154  -1.4916681462400413E-154
           2  -1.4916681462400413E-154  -1.4916681462400413E-154
[pi:54179] *** An error occurred in MPI_Win_detach
[pi:54179] *** reported by process [2740256769,1]
[pi:54179] *** on win rdma window 5
[pi:54179] *** MPI_ERR_OTHER: known error not in list
[pi:54179] *** MPI_ERRORS_ARE_FATAL (processes in this win will now abort,
[pi:54179] ***    and potentially your MPI job)
Error: Command:
   `~/opt/homebrew/bin/mpiexec -n 2 ./coarrays_error`
failed to run.

Ups! Note that this error doesn’t exist in case you use MPICH.

I tried to apply approach presented here: https://github.com/sourceryinstitute/OpenCoarrays/issues/625, but I failed :( At some point I am getting compilation error

./bin/brew install --build-from-source --cc=gcc-9 opencoarrays
Warning: You passed `--cc=gcc-9`.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience while you are running this unsupported configuration.
...
...
...
                 from /Applications/Xcode.app/.../Headers/OSServices.h:29,
                 from /Applications/Xcode.app/.../Headers/IconsCore.h:23,
                 from /Applications/Xcode.app/.../Headers/LaunchServices.h:23,
                 from /Applications/Xcode.app/.../Headers/CoreServices.h:39,
                 from gutils.c:127:
/Applications/Xcode.app/.../Headers/Authorization.h:193:7: error: variably modified 'bytes' at file scope
  193 |  char bytes[kAuthorizationExternalFormLength];
      |       ^~~~~
make[6]: *** [libglib_2_0_la-gutils.lo] Error 1
make[5]: *** [all-recursive] Error 1
make[4]: *** [all] Error 2
make[3]: *** [all-recursive] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

Do not report this issue to Homebrew/brew or Homebrew/core!

I guess the reason here is, I am trying to use incorrect version of gcc.

> ./bin/gcc-9 --version
gcc-9 (Homebrew GCC 9.2.0_3) 9.2.0

Unfortunately, it’s not possible to install mpich with gcc@8 because it requires gcc@9 and the loop goes on :(

> ./bin/brew install gcc@8
> ./bin/brew install mpich
==> Installing dependencies for mpich: gcc
==> Installing mpich dependency: gcc
==> Downloading https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.xz
...
...

Please note that I am not quite a fan of homebrew. When it comes to me, I still prefer to build things by myself: Building OpenCoarrays on macOS – everything from the sources. However, I really appreciate the existence of that tool. It provides a huge help for all those people who don’t like to play with sources.

[fblike]