Compiling ElmerFEM using LFortran

Hello!

I am trying to compile ElmerFEM (GitHub - ElmerCSC/elmerfem: Official git repository of Elmer FEM software) using LFortran.

I am having some issues (as expected from an alpha stage compiler), but I do not want to spam the issue boards straight away because the blame might be on me. And there can be many issues between here and the successful compilation, so I’ll use this thread for asking around and for deciding if the issue should be reported to LFortran issue tracker (or that of ElmerFEM).

ElmerFEM is mainly a fortran code (F90), at least the part that I am interested in now (the ElmerSolver) and allows several 3rd party libraries to be linked in for various tasks (linear system solution, meshing, partitioning, mpi, …). Build automation is handled using cmake (trying to incorporate fpm is one other project that should be tried).

However, let’s start simple and use as little external libraries as possible:

export FC="/home/eelis/git/lfortran/src/bin/lfortran"
cmake .. -DWITH_MPI=FALSE

MPI is TRUE by default

First relevant error is here:

Run Build Command(s):/usr/bin/make -f Makefile cmTC_f0449/fast && /usr/bin/make  -f CMakeFiles/cmTC_f0449.dir/build.make CMakeFiles/cmTC_f0449.dir/build
make[1]: Entering directory '/home/eelis/git/elmerfem/build/CMakeFiles/CMakeScratch/TryCompile-E47nlM'
Building Fortran object CMakeFiles/cmTC_f0449.dir/testFortranCompiler.f.o
/home/eelis/bin/lfortran    -c /home/eelis/git/elmerfem/build/CMakeFiles/CMakeScratch/TryCompile-E47nlM/testFortranCompiler.f -o CMakeFiles/cmTC_f0449.dir/testFortranCompiler.f.o
e[0;31;1msemantic errore[0;0me[0;1m: function interface must be specified explicitly; you can enable implicit interfaces with `--implicit-interface`e[0;0m
 e[0;34;1m-->e[0;0m /home/eelis/git/elmerfem/build/CMakeFiles/CMakeScratch/TryCompile-E47nlM/testFortranCompiler.f:3:16
  e[0;34;1m|e[0;0m
e[0;34;1m3 |e[0;0m       external sgemm
  e[0;34;1m|e[0;0m                e[0;31;1m^^^^^ e[0;0m


e[0;1mNotee[0;0m: Please report unclear or confusing messages as bugs at
https://github.com/lfortran/lfortran/issues.
make[1]: *** [CMakeFiles/cmTC_f0449.dir/build.make:78: CMakeFiles/cmTC_f0449.dir/testFortranCompiler.f.o] Error 1
make[1]: Leaving directory '/home/eelis/git/elmerfem/build/CMakeFiles/CMakeScratch/TryCompile-E47nlM'
make: *** [Makefile:127: cmTC_f0449/fast] Error 2

Even if --implicit-interface is used, it just ends to an error where sgemm symbol is not found. So the issue is that libblas is not found. Gfortran compiles the whole project without problems.

I am wondering why in the case of LFortran, libblas is not found (should I compile that first btw.)? Is omitting the --implicit-interface functionality a “standard behaviour” among compilers?

Thanks!

edit. This may be a cmake configuration issue with lfortran

Hmm… the actual problem is find_package(BLAS REQUIRED)
Here is a small example:
CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
enable_language(Fortran)
project(Hello)
add_executable(Hello hello.f90)
set_target_properties(Hello PROPERTIES LINKER_LANGUAGE Fortran)
find_package(BLAS REQUIRED)

hello.f90:

print *, "hello!"; end

Put in the same folder and run
mkdir build; cd build; FC="/home/eelis/git/lfortran/src/bin/lfortran" cmake ..

with gfortran I have no issue.

FYI @certik

I wrote a related issue: Unhandled exception with external libblas subroutine · Issue #2924 · lfortran/lfortran · GitHub

This isn’t a problem with Lfortran. The blas library isn’t part of Fortran. It’s a third party library (TPL), of which there a many available implementations. Your system happens to include one that was compiled with gfortran which is why the find_package(BLAS) is successful when using gfortran. Code compiled with one Fortran compiler are not generally compatible with code compiled by another. You’re going to need to compile a version of the blas using Lfortran (and then arrange for cmake to find that one). Same for any other Fortran library that ElmerFEM uses. And when you get to turning MPI back on, you’ll need to build a version of the MPI library using Lfortran for the Fortran compiler (assuming ElmerFEM uses the Fortran MPI interface). Things get compilicated when you’re building a program that relies on TPL.

2 Likes

@eelis Thanks for trying LFortran! We are still in alpha, meaning it is expected you will hit issues like these when trying it on a new code. Go ahead and report them all into our issue tracker and we’ll fix them. Ideally if you can figure out a small reproducible example, those are the best bug reports that we can fix quickly.

Regarding print *, "hello!"; end, I tried it in LFortran, that works for me. So the issue is likely what @nncarlson said, you might be mixing several Fortran compilers in the same project. That never works in general.

1 Like