---
title: 编译和安装
description: "1. 使用PuTTY工具，以root用户登录服务器。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpcindapp/prtg-osc/openmind_kunpengmitgcm_02_0010.html
sourcePath: /source/zh/kunpenghpcs/hpcindapp/prtg-osc/openmind_kunpengmitgcm_02_0010.html
indexId: 7178c841542e2f37d1c71779bb595abeface9e6f0aad3760aedbc93e247977f977
---
# 编译和安装

#### 操作步骤

1. 使用PuTTY工具，以root用户登录服务器。
2. 执行以下命令进入MITgcm安装包所在目录。

```
cd
/
path/to/
MITGCM
```


3. 执行以下命令解压安装包。

```
tar -xvf MITgcm_c67o.tar.gz
cd MITgcm
```


4. 执行以下命令配置相关文件。

  a. 进入“build_options”目录。

```
cd tools/build_options
```


  b. 创建并编辑“Linux_arm64_gfortran”文件。

```
vi linux_arm64_gfortran
```


  c. 按“i”进入编辑模式，添加如下内容。

```
#!/bin/bash
MPI='true'
CC=mpicc
FC=mpif77
F90C=mpif90
DEFINES='-DWORDLENGTH=4 -DNML_TERMINATOR -DALLOW_USE_MPI -DALWAYS_USE_MPI'
EXTENDED_SRC_FLAG='-ffixed-line-length-132'
F90FIXEDFORMAT='-ffixed-form'
GET_FC_VERSION="--version"
OMPFLAG='-fopenmp'
NOOPTFLAGS='-O0 -g'
NOOPTFILES=''
CFLAGS='-O3 '
FFLAGS="$FFLAGS -fconvert=big-endian -fimplicit-none"
CFLAGS="$CFLAGS -fPIC"
FFLAGS="$FFLAGS -fPIC"
#- with FC 19, need to use this without -fPIC (which cancels -mcmodel option):
# CFLAGS="$CFLAGS -mcmodel=medium"
# FFLAGS="$FFLAGS -mcmodel=medium"
#- might want to use '-fdefault-real-8' for fizhi pkg:
#FFLAGS="$FFLAGS -fdefault-real-8 -fdefault-double-8"
if test "x$IEEE" = x ; then #- with optimisation:
#- full optimisation
FOPTIM='-O3 -funroll-loops'
NOOPTFILES="$NOOPTFILES ini_masks_etc.F"
#- can use -O2 (safe optimisation) to avoid Pb with some gcc version of -O3:
#FOPTIM='-O2 -funroll-loops'
else
# these may also be useful, but require specific gfortran versions:
# -Wnonstd-intrinsics for gfortran <= 4.3
# -Wintrinsics-std for gfortran >= 4.4
# -Wno-tabs for gfortran >= 4.3
# -Wno-unused-dummy-argument for gfortran >= 4.6
#FFLAGS="$FFLAGS -Waliasing -Wampersand -Wsurprising -Wline-truncation"
#- or simply:
FFLAGS="$FFLAGS -Wall"
#- to get plenty of warnings: -Wall -Wextra (older form: -Wall -W) or:
#FFLAGS="$FFLAGS -Wconversion -Wimplicit-interface -Wunused-labels"
if test "x$DEVEL" = x ; then #- no optimisation + IEEE :
FOPTIM='-O0'
else #- development/check options:
FOPTIM='-O0 -g -fbounds-check'
FOPTIM="$FOPTIM -ffpe-trap=invalid,zero,overflow -finit-real=inf"
fi
fi
F90FLAGS=$FFLAGS
F90OPTIM=$FOPTIM
# --------------------------
# NETCDF DIRECTORIES
# --------------------------
HDF5_HOME=/path/to/HDF5
NETCDF_HOME=/path/to/NETCDF
INCLUDEDIRS=''
INCLUDES="-I$NETCDF_HOME/include -I$HDF5_HOME/include"
LIBS="-L$NETCDF_HOME/lib -lnetcdff -lnetcdf -L$HDF5_HOME/lib -lhdf5_hl -lhdf5"
# -----------------------
# INCLUDE MPI DIRECTORIES
# -----------------------
MPI_HOME=/path/to/OPENMPI-4.0.1
MPI_INC_DIR=$MPI_HOME/include
INCLUDES="$INCLUDES -I$MPI_HOME/include"
INCLUDEDIRS="$INCLUDEDIRS $MPI_HOME/include"
MPIINCLUDEDIR="$MPI_INC_DIR"
```


  d. 按“Esc”键，输入:wq!，按“Enter”保存并退出编辑。
5. 以“exp4”算例为例，进行编译安装。

  a. 执行以下命令进入相应目录。

```
cd
/path/to/MITGCM
/MITgcm/verification/exp4/code
```


  b. 执行以下命令将“SIZE.h_mpi”重命名为“SIZE.h”，覆盖原始的“SIZE.h”文件。

```
mv SIZE.h_mpi SIZE.h
```


  c. 执行以下命令进入相应目录。

```
cd
/path/to/MITGCM
/MITgcm/verification/exp4/build
```


  d. 执行以下命令生成“makefile”文件。

```
../../../tools/genmake2 -mods=../code -mpi -of=../../../tools/build_options/
linux_arm64_gfortran
```


  e. 执行以下命令编译安装，若有“mitgcmuv”文件生成表示编译成功。

```
make depend
make
```
