# MPI undefined error when installing CCTM using gcc and gfortran

**URL:** <https://forum.cmascenter.org/t/mpi-undefined-error-when-installing-cctm-using-gcc-and-gfortran/4858>\
**Category:** Compiling\
**Tags:** cmaq\
**Created:** [April 11, 2024, 7:23pm UTC](https://forum.cmascenter.org/t/mpi-undefined-error-when-installing-cctm-using-gcc-and-gfortran/4858 "2024-04-11T19:23:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lr111](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lr111](https://forum.cmascenter.org/u/lr111)\
**Post date:** [April 11, 2024, 7:23pm UTC](https://forum.cmascenter.org/t/mpi-undefined-error-when-installing-cctm-using-gcc-and-gfortran/4858/1 "2024-04-11T19:23:52Z")

</div>

Hi everyone,  
I successfully compiled MCIP BCON and ICON when configuring CMAQv5.3.3 using mpich4.0 ioapi-3.2-large. However, I encountered an error in the mpi library link during the installation of CCTM. I would like to know the reason for this. Below is the log file when I make CCTM  
/usr/bin/ld: cmaq\_main.o: in function `MAIN__': cmaq_main.F:(.text+0x2ea): undefined reference to `mpi\_wtime\_’  
/usr/bin/ld: cmaq\_main.F:(.text+0x3dd): undefined reference to `mpi_finalize_' /usr/bin/ld: se_data_send_module.o: in function `\__se\_data\_send\_module\_MOD\_se\_5d\_data\_send’:  
se\_data\_send\_module.f:(.text+0x5a9): undefined reference to `mpi_send_' /usr/bin/ld: se_data_send_module.f:(.text+0x62d): undefined reference to `mpi\_send_’  
/usr/bin/ld: se\_data\_send\_module.f:(.text+0x953): undefined reference to `mpi_send_' /usr/bin/ld: se_data_send_module.o: in function `\_\_se\_data\_send\_module\_MOD\_se\_4de\_data\_send’:se\_data\_send\_module.f:(.text+0xb3a): undefined reference to `mpi_send_' /usr/bin/ld: se_data_send_module.o: in function `_se\_data\_send\_module\_MOD\_se\_4d\_data\_send’:  
se\_data\_send\_module.f:(.text+0x15f3): undefined reference to `mpi_send_' /usr/bin/ld: se_data_send_module.o:se_data_send_module.f:(.text+0x1674): more undefined references to `mpi\_send’ follow  
/usr/bin/ld: se\_internal\_util\_module.o: in function `__se_internal_util_module_MOD_se_generate_map': se_internal_util_module.f:(.text+0xa81): undefined reference to `mpi\_gather_’  
/usr/bin/ld: se\_internal\_util\_module.f:(.text+0xaab): undefined reference to `mpi_bcast_' /usr/bin/ld: se_data_recv_module.o: in function `\__se\_data\_recv\_module\_MOD\_se\_5d\_data\_recv’:  
se\_data\_recv\_module.f:(.text+0x1c4): undefined reference to `mpi_recv_' /usr/bin/ld: se_data_recv_module.o: in function `se\_data\_recv\_module\_MOD\_se\_4de\_data\_recv’:se\_data\_recv\_module.f:(.text+0xb3c): undefined reference to `mpi_recv_' /usr/bin/ld: se_data_recv_module.f:(.text+0x11ee): undefined reference to `mpi\_recv’  
/usr/bin/ld: se\_data\_recv\_module.o: in function `__se_data_recv_module_MOD_se_4d_data_recv': se_data_recv_module.f:(.text+0x13c1): undefined reference to `mpi\_recv’  
/usr/bin/ld: se\_data\_recv\_module.o: in function `__se_data_recv_module_MOD_se_3de_data_recv':se_data_recv_module.f:(.text+0x1b77): undefined reference to `mpi\_recv_’  
/usr/bin/ld: se\_data\_recv\_module.o:se\_data\_recv\_module.f:(.text+0x2153): more undefined references to `mpi_recv_' follow /usr/bin/ld: se_global_sum_module.o: in function `\__se\_global\_sum\_module\_MOD\_se\_global\_rasum’:  
se\_global\_sum\_module.f:(.text+0xc8): undefined reference to `mpi_reduce_' /usr/bin/ld: se_global_sum_module.f:(.text+0x119): undefined reference to `mpi\_bcast_’  
/usr/bin/ld: se\_global\_sum\_module.f:(.text+0x187): undefined reference to `mpi_reduce_' /usr/bin/ld: se_global_sum_module.o: in function `\__se\_global\_sum\_module\_MOD\_se\_global\_iasum’:  
se\_global\_sum\_module.f:(.text+0x678): undefined reference to `mpi_reduce_' /usr/bin/ld: se_global_sum_module.f:(.text+0x6c9): undefined reference to `mpi\_bcast_’  
/usr/bin/ld: se\_global\_sum\_module.f:(.text+0x737): undefined reference to `mpi_reduce_' /usr/bin/ld: se_global_sum_module.o: in function `\__se\_global\_sum\_module\_MOD\_se\_global\_rsum’:se\_global\_sum\_module.f:(.text+0xafe): undefined reference to `mpi_reduce_' /usr/bin/ld: se_global_sum_module.f:(.text+0xb37): undefined reference to `mpi\_bcast_’  
/usr/bin/ld: se\_global\_sum\_module.o: in function `\_\_se\_global\_sum\_module\_MOD\_se\_global\_isum’:  
﻿  
————————————————————————  
I set the gcc section in my config\_cmaq.csh file as follows：  
#\> set the compiler flag -fopt-info-missed to generate a missed optimization report in the bldit logfile  
setenv myFC gfortran  
setenv myCC gcc  
setenv myFSTD “-O3 -funroll-loops -finit-character=32 -Wtabs -Wsurprising -march=native -ftree-vectorize -ftree-loop-if-convert -finline-limit=512”  
setenv myDBG “-Wall -O0 -g -fcheck=all -ffpe-trap=invalid,zero,overflow -fbacktrace” setenv myFFLAGS “-ffixed-form -ffixed-line-length-132 -funroll-loops -finit-character=32”  
setenv myFRFLAGS “-ffree-form -ffree-line-length-none -funroll-loops -finit-character=32”  
setenv myCFLAGS “-O2”  
setenv myLINK\_FLAG “-fopenmp” # “-fopenmp” # openMP may be required if I/O API was built using this link flag.  
setenv extra\_lib “”  
setenv mpi\_lib “-lmpich”

* * *

My Makefile as follows:  
EXEC = CCTM\_v533.exe  
﻿  
FC = gfortran  
CC = gcc  
﻿  
LIB = /home/mapuni/WRF/CMAQ-5.3.3/lib/x86\_64/gcc  
include\_path = -I (LIB)/ioapi/lib \ -I (LIB)/ioapi/include\_files   
-I (LIB)/mpi/lib -I. ﻿ WARN = FSTD = -O3 -funroll-loops -finit-character=32 -Wtabs -Wsurprising -march=native -ftree-vectorize -ftree-loop-if-convert -finline-limit=512 DBG = -Wall -O0 -g -fcheck=all -ffpe-trap=invalid,zero,overflow -fbacktrace ﻿ ifneq (,(filter (debug), TRUE true True T )) DEBUG = TRUE endif ﻿ ifneq (,(filter (DEBUG), TRUE true )) f\_FLAGS = -ffixed-form -ffixed-line-length-132 -funroll-loops -finit-character=32 (DBG) (include\_path) f90\_FLAGS = -ffree-form -ffree-line-length-none -funroll-loops -finit-character=32 (DBG) (include\_path) else f\_FLAGS = -ffixed-form -ffixed-line-length-132 -funroll-loops -finit-character=32 (FSTD) (include\_path) f90\_FLAGS = -ffree-form -ffree-line-length-none -funroll-loops -finit-character=32 (FSTD) (include\_path) endif ﻿ F\_FLAGS = (f\_FLAGS) -fallow-argument-mismatch  
F90\_FLAGS = (f90\_FLAGS) -fallow-argument-mismatch C\_FLAGS = -O2 -DFLDMN -I(LIB)/mpi/include -I.  
﻿  
LINKER = $(FC)  
LINK\_FLAGS = -fopenmp  
﻿  
REPOROOT = /home/mapuni/WRF/CMAQ-5.3.3/CCTM/src

* * *

Thank you very much for your help. I have been stuck for many days and even after changing to the mpich version, I still cannot generate CCTMv533.exe properly

---

<div class="post-metadata">

**Author:** ![lizadams](https://avatars.discourse-cdn.com/v4/letter/l/49beb7/32.png) [@lizadams](https://forum.cmascenter.org/u/lizadams)\
**Post date:** [April 12, 2024, 5:29pm UTC](https://forum.cmascenter.org/t/mpi-undefined-error-when-installing-cctm-using-gcc-and-gfortran/4858/2 "2024-04-12T17:29:05Z")

</div>

If you change MPI versions, then you need to carefully recreate the hard coded links to the MPI libraries.  
The links are created when you source the config\_cmaq.csh

These are the environment variables that you likely modified in the config\_cmaq.csh

```auto
        setenv MPI_INCL_DIR /<your_path>/include #> MPI Include directory pat
        setenv MPI_LIB_DIR /<your_path>/lib #> MPI Lib directory path

```

Later in the config\_cmaq.csh the links to these paths are created:

```auto
#> Create Symbolic Links to Libraries
 if ( ! -d $CMAQ_LIB ) mkdir -p $CMAQ_LIB
 if ( -e $MPI_DIR ) rm -rf $MPI_DIR
     mkdir $MPI_DIR
     ln -s $MPI_LIB_DIR $MPI_DIR/lib
     ln -s $MPI_INCL_DIR $MPI_DIR/include

```

I recommend that you verify the linked path has been updated.

Look in the following directory if you are using the gcc compiler:

```auto
ls -lrt CMAQ/lib/x86_64/gcc/mpi

```

Output example:

```auto
lrwxrwxrwx 1 lizadams rc_cep-emc_psx 58 Dec 22 00:40 lib -> /nas/longleaf/apps-dogwood/mpi/gcc_9.1.0/openmpi_4.0.1/lib
lrwxrwxrwx 1 lizadams rc_cep-emc_psx 62 Dec 22 00:40 include -> /nas/longleaf/apps-dogwood/mpi/gcc_9.1.0/openmpi_4.0.1/include

```

If these links are not updated then change to the directory and remove the links and then resource the config\_cmaq.csh

---

<div class="post-metadata">

**Author:** ![lr111](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lr111](https://forum.cmascenter.org/u/lr111)\
**Post date:** [April 15, 2024, 9:38am UTC](https://forum.cmascenter.org/t/mpi-undefined-error-when-installing-cctm-using-gcc-and-gfortran/4858/3 "2024-04-15T09:38:19Z")

</div>

Thank you for your reply, dear lizadams

I have ensured that there are no issues with my mpich and the lib link path of CMAQ when raising the questions you mentioned.

In the end, I modified the Makefile of CCTM by changing FC=gfortran to FC=mpifort, which solved my compilation problem.

```auto
EXEC = CCTM_v533.exe

FC = mpifort
CC = gcc

LIB = /home/mapuni/WRF/CMAQ-5.3.3/lib/x86_64/gcc
include_path = -I $(LIB)/ioapi/lib \
               -I $(LIB)/ioapi/include_files \
               -I $(LIB)/mpi/lib -I.

```

I am not sure what the reason is.  
Thank you again for your patient reply and answer!
