# How to call parallel fortran code from Julia correctly?

**URL:** <https://discourse.julialang.org/t/how-to-call-parallel-fortran-code-from-julia-correctly/57583>\
**Category:** New to Julia\
**Tags:** question, ccall, fortran, mpi\
**Created:** [March 20, 2021, 2:08am UTC](https://discourse.julialang.org/t/how-to-call-parallel-fortran-code-from-julia-correctly/57583 "2021-03-20T02:08:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DerongXu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/derongxu/32/23102_2.png) [@DerongXu](https://discourse.julialang.org/u/DerongXu)\
**Post date:** [March 20, 2021, 2:08am UTC](https://discourse.julialang.org/t/how-to-call-parallel-fortran-code-from-julia-correctly/57583/1 "2021-03-20T02:08:38Z")

</div>

Hi All,

I am new to Julia. I would like to call the MPI FORTRAN code in Julia. However, when the Fortran code involve MPI\_Init, I cannot run my code correctly. A minimum demo is shown below.

-------------Fortran code: main.f90--------------------  
function rank()  
implicit none  
include ‘mpif.h’  
integer::ierr,rank  
rank=-1  
!call MPI\_INIT(ierr)  
!call MPI\_Comm\_rank(MPI\_COMM\_WORLD,rank,ierr)  
print\*, “hello world”,rank  
!call MPI\_FINALIZE(ierr)  
end function rank

-------------Julia script: test.jl--------------------  
ccall((:rank\_,“main.so”),Int64,())

I compile my fortran code with  
“mpif90 -shared -fPIC -o main.so main.f90”  
and run Julia script with  
“mpirun -np 1 julia test.jl”.

As you can see in the Fortran code, when I comment the **MPI\_Init** functions, I can get correct output. However, when these sentences  
When these sentences take effect, something wrong happens.

* * *

## The error information is shown here. [username:04407] mca\_base\_component\_repository\_open: unable to open mca\_patcher\_overwrite: /usr/lib/x86\_64-linux-gnu/openmpi/lib/openmpi/mca\_patcher\_overwrite.so: undefined symbol: mca\_patcher\_base\_patch\_t\_class (ignored) [username:04407] mca\_base\_component\_repository\_open: unable to open mca\_shmem\_sysv: /usr/lib/x86\_64-linux-gnu/openmpi/lib/openmpi/mca\_shmem\_sysv.so: undefined symbol: opal\_show\_help (ignored) [username:04407] mca\_base\_component\_repository\_open: unable to open mca\_shmem\_posix: /usr/lib/x86\_64-linux-gnu/openmpi/lib/openmpi/mca\_shmem\_posix.so: undefined symbol: opal\_shmem\_base\_framework (ignored) [username:04407] mca\_base\_component\_repository\_open: unable to open mca\_shmem\_mmap: /usr/lib/x86\_64-linux-gnu/openmpi/lib/openmpi/mca\_shmem\_mmap.so: undefined symbol: opal\_show\_help (ignored)

It looks like opal\_init failed for some reason; your parallel process is  
likely to abort. There are many reasons that a parallel process can  
fail during opal\_init; some of which are due to configuration or  
environment problems. This failure appears to be an internal failure;  
here’s some additional information (which may only be relevant to an  
Open MPI developer):

opal\_shmem\_base\_select failed  
 → Returned value -1 instead of OPAL\_SUCCESS
