fortranfortran-coarrays

Fortran Coarray cant compile


Im trying to compile an example of Coarray Fortran file. https://github.com/ljdursi/coarray-examples The command for compile is:

mpifort diffusion/diffusion-coarray.f90 -fcoarray=lib -o diffusion/diffusion-coarray -L ${PATH_TO_OPENCOARRAY_LIB} -lcaf_mpi

I've already installed the OpenCoarrays, using spack But there is an error:

/usr/bin/ld: cannot find -lcaf_mpi
collect2: error: ld returned 1 exit status

Without -lcaf_mpi the error is:

/tmp/ccOdrmfc.o: In function `MAIN__':
diffusion-coarray.f90:(.text+0x32): undefined reference to `_gfortran_caf_num_images'
diffusion-coarray.f90:(.text+0x4c): undefined reference to `_gfortran_caf_this_image'
diffusion-coarray.f90:(.text+0x66): undefined reference to `_gfortran_caf_this_image'
diffusion-coarray.f90:(.text+0x77): undefined reference to `_gfortran_caf_num_images'
diffusion-coarray.f90:(.text+0x8a): undefined reference to `_gfortran_caf_num_images'
diffusion-coarray.f90:(.text+0xaa): undefined reference to `_gfortran_caf_this_image'
diffusion-coarray.f90:(.text+0xbd): undefined reference to `_gfortran_caf_this_image'
diffusion-coarray.f90:(.text+0xf4): undefined reference to `_gfortran_caf_num_images'

End etc. Where is the problem?


Solution

  • Thanks for help. I've solved the problem. If anyone will be interested, here is my solution: 1. Install Linuxbrew following their instructions:

    sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
    
    test -d ~/.linuxbrew && PATH="$HOME/.linuxbrew/bin:$HOME/.linuxbrew/sbin:$PATH"
    test -d /home/linuxbrew/.linuxbrew && PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:$PATH"
    test -r ~/.bash_profile && echo "export PATH='$(brew --prefix)/bin:$(brew --prefix)/sbin'":'"$PATH"' >>~/.bash_profile
    echo "export PATH='$(brew --prefix)/bin:$(brew --prefix)/sbin'":'"$PATH"' >>~/.profile
    
    1. Install OpenCoarrays library brew install opencoarrays Now we can compile files with caf and cafrun
    2. Compile .exe-file caf fname.f90 -o test.exe
    3. Run the program cafrun -np (numimages) test.exe

    Hope it will be helpful for someone! P.S. My OS is Ubuntu 16.04.4 LTS, gfortran: GNU Fortran 5.4.0 20160609 so the rest of necessary tools (for example, compiler caf and launcher cafrun are the part of OpenCoarrays package) will be installed by following the instruction.