Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error copying Fortran module "include/schism_glbl.mod" #111

Open
platipodium opened this issue Sep 15, 2023 · 29 comments
Open

Error copying Fortran module "include/schism_glbl.mod" #111

platipodium opened this issue Sep 15, 2023 · 29 comments
Labels
bug Something isn't working conda Issues that occur in conda environments

Comments

@platipodium
Copy link
Member

On Mac M1 in a conda environment (gfortran-clang) my build fails with

Error copying Fortran module "include/schism_glbl.mod".  Tried "include/SCHISM_GLBL.mod" and "include/schism_glbl.mod".
make[2]: *** [Core/CMakeFiles/core.dir/depend.make:26: Core/CMakeFiles/core.dir/schism_glbl.mod.stamp] Error 1
make[1]: *** [CMakeFiles/Makefile2:1522: Core/CMakeFiles/core.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

Any ideas?

@platipodium
Copy link
Member Author

make  -f Core/CMakeFiles/core.dir/build.make Core/CMakeFiles/core.dir/build
make[3]: Entering directory '/Users/Lemmen/devel/schism/schism/build'
/opt/conda/envs/schism/bin/cmake -E cmake_copy_f90_mod include/schism_glbl.mod Core/CMakeFiles/core.dir/schism_glbl.mod.stamp GNU
Error copying Fortran module "include/schism_glbl.mod".  Tried "include/SCHISM_GLBL.mod" and "include/schism_glbl.mod".
m

@jreniel
Copy link
Member

jreniel commented Sep 15, 2023

Hi @platipodium,
I'm willing to take a shot at this problem.
This may sound like a silly question (you may have a reason) but this is so I can understand better your context.
Is there any reason why you are invoking
make -f Core/CMakeFiles/core.dir/build.make Core/CMakeFiles/core.dir/build
Instead of invoking something like this:

mkdir build
cd build
cmake ../src  # any other cmake opts here
make

@platipodium
Copy link
Member Author

Thanks @jreniel. I did exactly that. The VERBOSE option of make then isolates the culprit line (within the regular make schism), which is

cmake -E cmake_copy_f90_mod include/schism_glbl.mod Core/CMakeFiles/core.dir/schism_glbl.mod.stamp GNU

Googling that, I saw a lot of reports on this with older cmake versions, but I am at 3.27 where this issue should be fixed.

Another idea was that it might be related to erroneous preprocessing options (which is poorly handled by cmake in mixed gfortran-clang environments, but following up some stack overflow ideas on PREPROCESS_OPTIONS didn't help. I also tried the -J and -M options to place mod files, but to no avail.

@platipodium
Copy link
Member Author

To reproduce, this is my conda configuration

conda install gfortran clang mpi netcdf-fortran parmetis

@platipodium platipodium added bug Something isn't working conda Issues that occur in conda environments labels Sep 15, 2023
@jreniel
Copy link
Member

jreniel commented Sep 15, 2023

Thanks for the clarification, I'll try to reproduce the problem and let you know what I find soon.

@jreniel
Copy link
Member

jreniel commented Sep 16, 2023

Could you please share the cmake flags you are using to configure cmake?
After installing the dependencies you specified (by adding -c conda-forge), and running cmake ../src without any configuration flags, I noticed that cmake is able to pick up by default the clang compiler. Then CMake tries to build the parmetis on the SCHISM directory (rather than using the one installed through conda) using clang. However it tries to add some flags that clang compiler does not recognize and fails. So knowing which configuration flags you were applying to cmake would be helpful.

Additionally, I have a 2016 Mac, but it doesn't have an M1 processor, so I might not be able to replicate the error. However, I would argue that given the correct configuration and environment it should compile. Then again, if I'm not mistaken, the M1 processors are ARM processors and I have never seen SCHISM being compiled on ARM architechture.

Compiler problems are always fun to debug, but more importantly, I'd like to see this compiled on ARM architechture, that would be cool.

@platipodium
Copy link
Member Author

Oh.. it's been working on Mac M1 for at least a year. On my local laptop through macports. But I have now switched to a conda toolchain.

Here's my CMAKE command:

cmake -S ../src  -DCMAKE_Fortran_COMPILER=${CONDA_PREFIX}/bin/mpifort -DCMAKE_C_COMPILER=${CONDA_PREFIX}/bin/mpicc -DPARMETIS_HOME=${CONDA_PREFIX}

Can you reproduce the error (on linux/conda or Mac/conda)?

@platipodium
Copy link
Member Author

Just a side note, M1/arm64/gfortran toolchain via macports continues to work:

$> cat ../cmake/SCHISM.local.macports

set(CMAKE_Fortran_COMPILER /opt/local/bin/gfortran CACHE PATH "Path to serial Fortran compiler")
set(CMAKE_C_COMPILER /opt/local/bin/gcc CACHE PATH "Path to serial C compiler")
set(NetCDF_FORTRAN_DIR /opt/local  CACHE PATH "Path to NetCDF Fortran library")
set(NetCDF_C_DIR /opt/local CACHE PATH "Path to NetCDF C library")

@platipodium
Copy link
Member Author

The major difference is that there is gfortran/gcc (macports) versus gfortran/clang (conda). And the mix of fortran/c with cmake has been having issues with PREPROCESS_FLAGS (--preprocess versus -cpp) ... but how to connect this to the above error I am not sure. Neither how to fix :=)

@jreniel
Copy link
Member

jreniel commented Sep 16, 2023

Thanks for adding more context to the problem statement, that does help rule out some possibilities and hone in on potential solutions.

@brey
Copy link
Contributor

brey commented Jan 8, 2024

Hi All. Just to say that I have the same problem on my (old) Mac trying to compile the latest version of SCHISM. I am also using conda.

@platipodium
Copy link
Member Author

Error persists. An update to my previous command for reproducing this is the STANDALONE cmake flag that is now necessary

conda install gfortran clang mpi netcdf-fortran parmetis
cmake -S ../src  -DCMAKE_Fortran_COMPILER=${CONDA_PREFIX}/bin/mpifort -DCMAKE_C_COMPILER=${CONDA_PREFIX}/bin/mpicc -DPARMETIS_HOME=${CONDA_PREFIX} -DBLD_STANDALONE=ON
make schism

@fred116
Copy link

fred116 commented Mar 4, 2024

Hi, I am novice here, but have a fairly clean M2 system and am actively working on this (since I need to use it :)), so I can test configs as long as I get reasonable instructions.

I am running macOS 14, but no Conda. I installed the pre-reqs via home-brew, fortran, mai, NetCDF-fortran. I was using gcc/clang from apple as default, and went through the make options in the documentation. I was about to install a home-brew gcc (12) and switch to trying the older make.

any suggestions?

@platipodium
Copy link
Member Author

Hi, I am novice here, but have a fairly clean M2 system and am actively working on this (since I need to use it :)),

Help is greatly appreciated. Most important advise: keep your system clean and document / be able to retrace your steps. Both homebrew and conda install mixed gfortran/clang environments that seem to create difficulties; macports has both gfortran/gcc and gfortran/clang available. Please report how you fare ...

@fred116
Copy link

fred116 commented Mar 4, 2024

I think I further along, but not sure. I have switched to attempting the make build instead of cmake.

I got past the include/schism_glbl.mod error, but now get a series of these:

Core/schism_msgp.F90:1669:19:

1669 | call mpi_irecv(iegsend_2t(1,i),nesend_2t(i),itype,nbrrank_2t(i),16,comm,rrqst(i),ierr)
| 1
......
4095 | call mpi_irecv(e3d_2t_data,1,e3d_2t_tr_recv_type(i),nbrrank_2t(i),18,comm,e3d_2t_tr_recv_rqst(i),ierr)
| 2
Error: Type mismatch between actual argument at (1) and actual argument at (2) (INTEGER(4)/REAL(8)).

If these are no longer related to this thread I will search somewhere else, or post to the mailing list. Thanks!

@platipodium
Copy link
Member Author

platipodium commented Mar 4, 2024

@fred116 this has been discussed elsewhere and is a consequence of your direct use of make instead of cmake and mpich upstream problems. You need to provide -fallow-argument-mismatch to proceed.

See #18

@fred116
Copy link

fred116 commented Mar 4, 2024

Just $0.02 here -- I finally got what I think is a successful build on Sonoma/M2.

I installed:
gfortran
gcc-13
netcdf/netcdf-fortran/netcdf-cxx
open-mai

via homebrew. In my SCHISM.local.myown I included gcc-13

I then followed the cmake instructions; then 'make pschism'

resulting binary gave me:

epictetus:bin gbsmith$ sudo ./pschism_mac_epictetus_TVD-VL -v

schism v5.11.1
git hash e2bf5bd
epictetus:bin gbsmith$

@platipodium
Copy link
Member Author

platipodium commented Mar 5, 2024

@fred116 How did you achieve mpich to use gcc? For me brew continues to use clang:

❯ which mpicc && mpicc --version
/opt/homebrew/bin/mpicc
clang version 16.0.6

... and then run into the mixed gfortran/clang trap. Please check which mpich you're using, and post your SCHISM.local.myown

@platipodium
Copy link
Member Author

epictetus:bin gbsmith$ sudo ./pschism_mac_epictetus_TVD-VL -v

@fred116 you should not have to run pschism with sudo. On the other hand, you show how much you trust us :=)

@platipodium
Copy link
Member Author

platipodium commented Mar 5, 2024

OK, I got it.

❯ brew install -cc=gcc open-mpi
❯ cmake -S ../src  -DCMAKE_Fortran_COMPILER=/opt/homebrew/bin/mpifort -DBLD_STANDALONE=ON -DCMAKE_C_COMPILER=/opt/homebrew/bin/mpicc -DCMAKE_CXX_COMPILER=/opt/homebrew/bin/mpicxx
❯ make pschism

So we do have it working on gcc/gfortran toolchain, but still not clang/gfortran :=(

@fred116
Copy link

fred116 commented Mar 6, 2024 via email

@fred116
Copy link

fred116 commented Mar 6, 2024 via email

@platipodium
Copy link
Member Author

platipodium commented Mar 6, 2024

Post your SCHISM.local.myown

I added the homebrew cmake recipe as ./cmake/SCHISM.homebrew.gcc-openmpi with commit fefb7aa, use with

cmake ../src -C ../cmake/SCHISM.homebrew.gcc-openmpi

@brey
Copy link
Contributor

brey commented Jul 22, 2024

Hi All. I finally had some time to work on this and it turns out it's the preprocessing. Removing it from the CMakeLists files did the trick. I was able to compile and build a conda package as expected.

@platipodium see if it works for you as well.

I have encoded the change into the build.sh file of the recipe as

#Fix OSX issue with preprocessing
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i -e "s|add_compile_options(\${C_PREPROCESS_FLAG})|#add_compile_options(\${C_PREPROCESS_FLAG})|g" src/CMakeLists.txt
sed -i -e "s|add_definitions(\${C_PREPROCESS_FLAG})|#add_definitions(\${C_PREPROCESS_FLAG})|g" src/Utility/Combining_Scripts/CMakeLists.txt
sed -i -e "s|add_definitions(\${C_PREPROCESS_FLAG})|#add_definitions(\${C_PREPROCESS_FLAG})|g" src/Utility/Post-Processing-Fortran/CMakeLists.txt
fi

There might also be a way to fix that by passing the right argument. In ccmake the way it is now, the flag takes the value --preprocessing which brakes the flow. It should be -E -P -ccp or something similar. I don't know cmake well enough to test that.

@brey
Copy link
Contributor

brey commented Jul 22, 2024

I have tried with several options to change the option in schism/cmake/SCHISMCompile.cmake file but nothing was accepted. It seems that clang does its own preprocessing automatically and all these flags fail.

So another way to achieve the same as above (thanks @pmav99) is the following:

❯ git diff ../cmake/SCHISMCompile.cmake 
diff --git a/cmake/SCHISMCompile.cmake b/cmake/SCHISMCompile.cmake
index 72c558a6..e388d1fd 100644
--- a/cmake/SCHISMCompile.cmake
+++ b/cmake/SCHISMCompile.cmake
@@ -16,7 +16,7 @@ if("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "Intel")
          set( CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -debug inline_debug_info ${SCHISM_INTEL_OPTIONS}")
          set( C_PREPROCESS_FLAG CACHE STRING "C Preprocessor Flag")
     endif()
-    
+
 endif()
 
 if("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "IntelLLVM")
@@ -39,9 +39,9 @@ if("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "GNU")
     set( CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "-O2 -g ${SCHISM_GFORTRAN_OPTIONS}")
     unset( C_PREPROCESS_FLAG CACHE)
     if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
-      set( C_PREPROCESS_FLAG "--preprocess" CACHE STRING "C Preprocessor Flag")
+      set( C_PREPROCESS_FLAG "" CACHE STRING "C Preprocessor Flag")
     elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
-      set( C_PREPROCESS_FLAG "--preprocess" CACHE STRING "C Preprocessor Flag")
+      set( C_PREPROCESS_FLAG "" CACHE STRING "C Preprocessor Flag")
     else()
       set( C_PREPROCESS_FLAG "-cpp" CACHE STRING "C Preprocessor Flag")
     endif()

@platipodium
Copy link
Member Author

Thanks @brey for suggesting this. I have not tried yet, but this approach does not seem to resolve the issue within the CMake strutter unmixed gfortran/clang, or depends on build.sh (which I would like not not use). But I'll investigate your suggestions more and report

@brey
Copy link
Contributor

brey commented Jul 23, 2024

Just to clarify, there is no homebrew involved. Just changing the /cmake/SCHISMCompile.cmake file above you can build locally with cmake and conda. The build.sh referenced above is the one in the conda.recipe used to build the package.

My conda env is:

name: schism-openmpi-dev

channels:
  - conda-forge

dependencies:
  - python=3
  - gfortran_osx-64
  - openmpi-mpicxx
  - openmpi-mpifort
  - netcdf-fortran=4.5.3=mpi_openmpi_*
  - cmake
  - parmetis
  - metis

@platipodium
Copy link
Member Author

My conda env is:

dependencies:

  • openmpi-mpicxx
  • openmpi-mpifort

Great! can you tell me the outcome of your mpicc --version and mpifort --version ? I only had the problem when they pointed to different compilers (gfortran and clang).

@brey
Copy link
Contributor

brey commented Jul 23, 2024

❯ mpicc --version
clang version 16.0.6
Target: x86_64-apple-darwin13.4.0
Thread model: posix
InstalledDir: /Users/brey/mambaforge/envs/schism-openmpi-dev/bin
❯ mpifort --version
GNU Fortran (GCC) 12.3.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
❯ which mpifort
/Users/brey/mambaforge/envs/schism-openmpi-dev/bin/mpifort

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working conda Issues that occur in conda environments
Projects
None yet
Development

No branches or pull requests

4 participants