...
Now run the fcm command to build the model with this change (make sure you have already compiled OpenIFS in the normal way in the oifs/make directory as this relies on the .o files being available):
| Code Block | ||
|---|---|---|
| ||
% fcm make -v -f change-fcflags.cfg [init] make [init] make config-parse [info] config-file=/openifs/inherit_tests/oifs/mymake/change-fcflags.cfg [info] config-file= - /openifs/inherit_tests/oifs/make/fcmcfg/oifs.cfg [info] config-file= - - /openifs/inherit_tests/oifs/make/fcmcfg/x86_64-gnu-opt.cfg [info] use=/openifs/inherit_tests/oifs/make [info] sources: total=2192, analysed=0, elapsed-time=0.6s, total-time=0.0s [info] target-tree-analysis: elapsed-time=13.3s [info] compile 0.2 M uvclr.o <- ifs/phys_radi/uvclr.F90 [info] link 1.7 M master.exe <- programs/master.F90 [info] compile targets: modified=1, unchanged=2070, total-time=0.2s [info] compile+ targets: modified=0, unchanged=626, total-time=0.0s [info] ext-iface targets: modified=0, unchanged=1247, total-time=0.0s [info] install targets: modified=0, unchanged=120, total-time=0.0s [info] link targets: modified=1, unchanged=0, total-time=1.7s [info] TOTAL targets: modified=2, unchanged=4063, elapsed-time=25.3s [done] make build # 26.3s [done] make # 26.6s |
...
If you now check the contents of this directory, you'll see:
| Code Block |
|---|
:% ls -R
build change-fcflags.cfg
./build:
bin o
./build/bin:
master.exe
./build/o:
uvclr.o |
...
| Info |
|---|
Experiment with this example by adding additional lines in the To verify the new compiler options are being used add the |
Example 2: Editing existing code
In this example, we'll build on the previous example and edit an existing source file. First make a new directory to hold the modified source code and copy a source file:
| Code Block | ||
|---|---|---|
| ||
% mkdir -p mysrc/ifs/control
% cp src/ifs/control/cnt0.F90 mysrc/ifs/control/cnt0.F90
Edit mysrc/ifs/control/cnt0.F90 using your favourite editor to add some print statements. |
| Note | ||
|---|---|---|
| ||
The path to any copies of OpenIFS code must be the same as they are laid out under the 'src' directory. Otherwise, the build command 'fcm' will not be able to match the sources. |
Then create the configuration file for FCM that looks like this:
| Code Block | ||
|---|---|---|
| ||
use = ../make
build.source = $HERE/../mysrc
build.prop{fc.flags}[ifs/control/cnt0.F90] = -g -O1 -fcheck=bounds |
As in example 1, the 'use' statement tells the build command FCM where to find the pre-compiled OpenIFS and all that's needed here are the changes. In this case, we now need to tell FCM where our new source code is using the 'build.source' statement - the special fcm $HERE variable means "the directory which contains this configuration file". As above, we'll also change the compiler options for this file. Note we don't need to include the oifs.cfg file as in the previous example, as this file doesn't contain any references to the OIFS_FFLAGS variable.
| Code Block | ||
|---|---|---|
| ||
% fcm make -v -f change-src1.cfg [init] make [init] make config-parse [info] config-file=/openifs/inherit_tests/oifs/mymake/change-src1.cfg [info] use=/openifs/inherit_tests/oifs/make [done] make dest-init # 0.0s [init] make build [info] sources: total=2192, analysed=0, elapsed-time=0.4s, total-time=0.0s [info] target-tree-analysis: elapsed-time=13.9s [info] compile 0.1 M cnt0.o <- ifs/control/cnt0.F90 [info] link 1.7 M master.exe <- programs/master.F90 [info] compile targets: modified=1, unchanged=2070, total-time=0.1s [info] compile+ targets: modified=0, unchanged=626, total-time=0.0s [info] ext-iface targets: modified=0, unchanged=1247, total-time=0.0s [info] install targets: modified=0, unchanged=120, total-time=0.0s [info] link targets: modified=1, unchanged=0, total-time=1.7s [info] TOTAL targets: modified=2, unchanged=4063, elapsed-time=25.6s [done] make build # 26.2s [done] make # 26.4s |
Note that FCM has: seen the new version of cnt0.F90, recompiled it and relinked it to the pre-compiled object code in oifs/make. The new executable can be found in the build/bin sub-directory.
A more advanced example with modules
We'll now add to this and change a fortran file with a MODULE. In this case, FCM will notice that the module interface has changed and recompile all source files (that we have not changed) that 'USE' this module:
| Code Block |
|---|
% mkdir mysrc/ifs/module
% cp src/ifs/module/yemct0.F90 mysrc/ifs/module
Edit yemct0.F90 - add a new logical variable |
The module YEMCT0 is only USE'd in the file ifs/control/cnt3.F90. We have not made any changes to cnt3.F90 but adding a new variable to the source file yemct0.F90 will change its interface and cnt3.F90 will need to be recompiled.
We do not need to make any changes to the configuration file:
| Code Block | ||
|---|---|---|
| ||
% fcm make -v -f change-src.cfg
[init] make
[init] make config-parse
[info] config-file=/openifs/inherit_tests/oifs/mymake/change-src2.cfg
[info] use=/openifs/inherit_tests/oifs/make
[done] make dest-init
[init] make build
[info] analyse 0.0 ifs/module/yemct0.F90
[info] analyse 0.0 ifs/control/cnt0.F90
[info] sources: total=2192, analysed=2, elapsed-time=0.5s, total-time=0.0s
[info] target-tree-analysis: elapsed-time=13.3s
[info] compile 0.0 M yemct0.o <- ifs/module/yemct0.F90
[info] compile+ 0.0 M yemct0.mod <- ifs/module/yemct0.F90
[info] ext-iface 0.0 U cnt3.intfb.h <- ifs/control/cnt3.F90
[info] compile 0.0 U cnt2.o <- ifs/control/cnt2.F90
[info] ext-iface 0.0 U cnt0.intfb.h <- ifs/control/cnt0.F90
[info] compile 0.1 U cnt3.o <- ifs/control/cnt3.F90
[info] compile 0.1 M cnt0.o <- ifs/control/cnt0.F90
[info] link 1.6 M master.exe <- programs/master.F90
[info] compile targets: modified=2, unchanged=2069, total-time=0.3s
[info] compile+ targets: modified=1, unchanged=625, total-time=0.0s
[info] ext-iface targets: modified=0, unchanged=1247, total-time=0.0s
[info] install targets: modified=0, unchanged=120, total-time=0.0s
[info] link targets: modified=1, unchanged=0, total-time=1.6s
[info] TOTAL targets: modified=4, unchanged=4061, elapsed-time=25.1s
[done] make build # 25.7s
[done] make # 25.9s
|
The lines:
| Code Block |
|---|
[info] analyse 0.0 ifs/module/yemct0.F90
[info] analyse 0.0 ifs/control/cnt0.F90 |
show that FCM has noticed we now have 2 modified source code files and has analysed them for changes.
...
The following lines:
| Code Block |
|---|
[info] compile 0.0 M yemct0.o <- ifs/module/yemct0.F90
[info] compile+ 0.0 M yemct0.mod <- ifs/module/yemct0.F90
[info] ext-iface 0.0 U cnt3.intfb.h <- ifs/control/cnt3.F90
[info] compile 0.0 U cnt2.o <- ifs/control/cnt2.F90
[info] ext-iface 0.0 U cnt0.intfb.h <- ifs/control/cnt0.F90
[info] compile 0.1 U cnt3.o <- ifs/control/cnt3.F90
[info] compile 0.1 M cnt0.o <- ifs/control/cnt0.F90
[info] link 1.6 M master.exe <- programs/master.F90 |
show that not only have the new versions of yemct0.F90 and cnt0.F90 been compiled, but also the unchanged, original, source for cnt3.F90 has been recompiled because it has a USE statement for yemct0. Also, because cnt3 is called by cnt2, which again we haven't altered, then this has is also recompiled.
The directory build/o now contains .o files for cnt0, cnt2, cnt3 and yemct0 and the new executable in build/bin/master.exe.
The directory mysrc we used here can contain as many source files from the main src directory as you like; either changed or unchanged.
Example 3: Adding new code
In this last example, we'll extend example 2 but this time add some new code and modify OpenIFS to call it.
| Code Block | ||
|---|---|---|
| ||
% mkdir mysrc/new
% cd mysrc/new
% cat > newsub.F90 << EOF
subroutine newsub
print *,'hello openifs'
end subroutine
EOF
% cd ../ifs/control
% vi cnt0.F90
Edit cnt0.F90 and add 'call newsub' to the start of the executable code. |
Having added a new subroutine and a call to it from our modified cnt0.F90 file, we need to make an additional change to the configuration file:
| Code Block |
|---|
use = ../make
build.source = $HERE/../mysrc
build.ns-incl = new algor ifsaux ifs surf trans openifs programs/master.F90
build.prop{fc.flags}[ifs/control/cnt0.F90] = -g -O1 -fcheck=bounds |
| HTML |
|---|
<script type="text/javascript" src="https://software.ecmwf.int/issues/s/en_UKet2vtj/787/12/1.2.5/_/download/batch/com.atlassian.jira.collector.plugin.jira-issue-collector-plugin:issuecollector/com.atlassian.jira.collector.plugin.jira-issue-collector-plugin:issuecollector.js?collectorId=5fd84ec6"></script> |
...