Scheduled Downtime
On Tuesday 24 October 2023 @ 5pm MT the forums will be in read only mode in preparation for the downtime. On Wednesday 25 October 2023 @ 5am MT, this website will be down for maintenance and expected to return online later in the morning.
Normal Operations
The forums are back online with normal operations. If you notice any issues or errors related to the forums, please reach out to help@ucar.edu

Porting CAM 3.1.p2 to be compiled under g95

I am trying to make CAM 3.1.p2 'compilable' on g95, and would like some help of people who know internally how does it work.

As I am beginning with CAM (dropped from CCM3 while not yet being familiar with it too), I understand little things of its working mechanism, so I am changing only orthogonal things, things that already have on the other compilers (found on other working source files for example).

Well so far, I left ESMF from the package and built latest version directly from the developers' website (version 2.2.2p3). With some special commandline arguments passed to CAM3.1's configure, it compiled the outer ESMF successfully (some tests seems to work, but real test comes when CAM3.1 is done).

Btw, my g95 is 0.92 (for gcc 4.0.3), 64bit, binary distribution got from the developers' website also (www.g95.org). NetCDF is also installed with g95 (thanks to a guy who sent a post to netcdf's website with parameters that permitted g95 to compile it -- his guidances are also helping the compile of CAM3.1 with g95.

Back to the building, after ESMF is compiled by CAM3.1's configure script, tons of errors pop up. Missing libraries, fixed (without changing makefile) with


Code:
-fflags '-fno-second-underscore -I. -Iesmf/mod/modO/linux_pgi -Iesmf/mod/modO/Linux.g95.64.mpiuni.default -I/usr/include -Imodels/atm/cam/src/dynamics/eul -Imodels/atm/cam/src/physics/cam1 -Imodels/atm/cam/src/control -Imodels/atm/cam/src/ocnsice/dom -Imodels/atm/cam/src/advection/slt'

(missing libs regards to the -I's only -- the other is to make possible linking .c's and .f's objects together)

After that, I started to have problems with not found includes for 'netcdf.inc', which was already on the -I's. The workaround was to change every

Code:
include 'netcdf.inc'

to

Code:
#include <netcdf.inc>


As both do the same, but the first looks only on current directory, I assumed that on other compilers they also look for on all include directories and just g95 needed it this way, but the others would support this changed include as well, as there were occurrences of these on other source files already.

Now I am under a problem with kissvec(), where on file models/atm/cam/src/physics/cam1/icarus_scops.F90, line 651 (and maybe others), it passes a real(8 ) value to kissvec() which accepts a real(4 ). Would that be safer to turn these into real(4 ) before passing, or better make kissvec accept real(8 ) (more memory) and make other calls to it real(8 )?

Thanks in advance.
 
Well, as it seems there's not much activity around, I'm posting my progress for archiving purposes may one ever come to want this program running on G95. Anyway, it has not guarantee that it will run smoothly. I am still going to play a model with ccm3 and then compare results with cam31p2, or compile cam with pgf90 (yeck) and then compare correctness with g95 version.

So, what I've done to the sources:
Grepped every file for

Code:
include 'netcdf.inc'

and

Code:
include "netcdf.inc"
(one match)

And changed all them to

Code:
#include <netcdf.inc>


Another change needed on the code was to edit models/utils/esmf/build/common_O, and change

Code:
FOPTFLAGS = ${O_FOPTFLAGS}

to

Code:
FOPTFLAGS = -fno-second-underscore ${O_FOPTFLAGS}


The other change I am not going to document it here. Just compile it and expect make to drop on error, read it and edit on the file (there are several files trying to carry real(4) to real(8) parameters or vice-versa. I've changed everything to real(8). Maybe later I make a diff from the entire source (when everything is tested and certain or if someone wants it to help me develop the code working on g95).

To compile everything, I assure a make clean is made (and everything cleaned), and then, from main source directory, where you have the 'models' directory:

Code:
cp models/utils/timing/gptl.inc .
models/atm/cam/bld/configure -cam_exedir ./bin -nc_inc /usr/include -nc_lib /usr/lib -smp -cppdefs '-DpgiFortran' -cflags '-O -fPIC -m64' -fc g95 -cc cc -fopt '-O' -fflags '-fno-second-underscore -I. -Iesmf/mod/modO/linux_pgi -Iesmf/mod/modO/Linux.g95.64.mpiuni.default -I/usr/include -Imodels/atm/cam/src/dynamics/eul -Imodels/atm/cam/src/physics/cam1 -Imodels/atm/cam/src/control -Imodels/atm/cam/src/ocnsice/dom -Imodels/atm/cam/src/advection/slt'
ESMF_COMPILER=g95 ESMF_ARCH=linux_pgi make


This 'cp gptl.inc' is needed by a moron source that can't find it in the directory even if specified by '-I' argument. It is a lot messy, but I am just finding out what is not in place first, later something can be done to make it recognizable by makefile. Esmf is a pain too.

After that, I finally got everything to compile. CAM binary is a binary. It -seems- to execute. Now I am going to install and test a simple model. Hope anyone else interests on the subject.
 
Arght! I must be missing tons of thing for not understanding how a #define could possibly be set if theres no previous #define nor #include on the file..........

This sounds just weird to me, on models/csm_share/shr/shr_sys_mod.F90. How is it supposed to have LINUX #define'd? There's no previous #include nor #define, there's just no '#define LINUX' on any of the files in the code (even after configure). Weird. Is this #define LINUX implied by pgf90 compiled for linux (for example)?

Although I think no one is going to read and help here, my progress is documented and maybe one day this can be of some sort of help to the development team.
 
I'm working on the same thing. In your Makefile you need to have

CPPDEF += -DLINUX

in the ifeq ($(UNAMES),Linux) section. With that and

ifeq ($(FC),g95)

CPPDEF += -DG95 -DNO_R16 -DDISABLE_TIMERS -DNO_CRAY_POINTERS
FFLAGS := $(cpp_path) $(mod_path) $(CPPDEF) -fno-second-underscore -fstatic -fmultiple-save

FREEFLAGS :=
FIXEDFLAGS :=
LDFLAGS := -L$(LIB_NETCDF) -lnetcdf



I can get most of the way. The compiler gags on

/models/atm/cam/src/physics/cam1/convect_ke.F

which has somewhat old code. I'd prefer not to rewrite the entire thing so I'm fiddling with why, since it ends appropriately in .F, the compiler doesn't like the formatting.

e.g.

variables are defined as:

REAL(R8) T(ND),Q(ND),QS(ND),U(ND),V(ND),TRA(ND,NTRA),P(ND),PH(ND+1)


but...

Q(J)=RM
1
Error: Expected 'q' at (1) to be a VARIABLE


etc.
 
well, with all my steps described above, I got it to compile to the end. The file is on, I think I am just screwing up things at the time to choose the model. The cam binary just quits complaining that couldn't get a convergence after a number of iterations...

I didn't have the problem you are having tough.

EDIT:

Drat... lost my last edit... must have clicked somewhere else.... In short I may have forgotten to update this topic as everything was too dead around and some other things took me time. I have figured out that -DLINUX thing and made it to compile, it just does that problem with convergence, but I think it is because of some messup setting up the data general + T42 resolution I am trying. What I've done to work were documented on a small textfile that I am going to paste now:


Code:
CAM 3.1.p2:
!! Add: -fno-second-underscore to 'FOPTFLAG' on models/utils/esmf/build/common_O
cp models/utils/timing/gptl.inc .
models/atm/cam/bld/configure -cam_exedir ./bin -nc_inc /usr/include -nc_lib /usr/lib -smp -cppdefs '-DpgiFortran -DLINUX' -cflags '-O -fPIC -m64 -DLINUX' -fc g95 -cc cc -fopt '-O' -fflags '-DLINUX -DG95 -fno-second-underscore -I. -Iesmf/mod/modO/linux_pgi -Iesmf/mod/modO/Linux.g95.64.mpiuni.default -I/usr/include -Imodels/atm/cam/src/dynamics/eul -Imodels/atm/cam/src/physics/cam1 -Imodels/atm/cam/src/control -Imodels/atm/cam/src/ocnsice/dom -Imodels/atm/cam/src/advection/slt' -ldflags '-L/usr/g95/lib'
ESMF_COMPILER=g95 ESMF_ARCH=linux_pgi make
!! package decompressed to /usr/src/moresrc and directory renamed from cam1 to cam3.1p2. command ran from
!!  /usr/src/moresrc/cam3.1p2 directory.
!! weird include error where already included (include 'something' but not #include <something>)
!! unsupported 'external' definition must be dropped adding a G95 define and making
!!  'defined LINUX' into '(defined LINUX && !defined G95)' on models/csm_share/shr/shr_sys_mod.F90
!! TODO: fix tons of WARNING errors, restore sources to make #ifdefs G95 to reflect changes


And that's all. The binary is out. I am just not sure this is really working or not. Maybe this helps you get to my state and make it work to the bottom. Just let me know if you can play a simulation correctly with it! :)

Best regards,
Fabrício Murta
 
Top