ROMS OpenMP with gfortran?

Discussion on computers, ROMS installation and compiling

Moderators: arango, robertson

Post Reply
Message
Author
User avatar
m.hadfield
Posts: 517
Joined: Tue Jul 01, 2003 4:12 am
Location: NIWA

ROMS OpenMP with gfortran?

#1 Post by m.hadfield » Thu Aug 24, 2006 10:24 pm

Has anyone managed to build ROMS in OpenMP mode with Gnu Fortran 95 (gfortran)? When I try on Linux with a recent version of gfortran I get undefined reference errors:

libUTIL.a(mp_routines.o): In function `my_threadnum__':
mp_routines.f90:(.text+0x1d): undefined reference to `omp_get_thread_num__'
libUTIL.a(mp_routines.o): In function `my_numthreads__':
mp_routines.f90:(.text+0x29): undefined reference to `omp_get_max_threads__'

I *think* the problem might me that I am using both the -fopenmp and -ff2c compiler flags (the former to support OpenMP and the latter to allow linking with NetCDF).

User avatar
m.hadfield
Posts: 517
Joined: Tue Jul 01, 2003 4:12 am
Location: NIWA

#2 Post by m.hadfield » Wed Sep 06, 2006 12:28 am

OK, I've sorted it out. The solution is to build netCDF in a way that doesn't require the Gfortran -ff2c flag.

I'll spare the gory details, but if anyone wants more info, please contact me.

By the way, Gfortran is the Gnu Fortran 95 compiler. It is included with GCC versions 4.1 or so and later (and so should be bundled with recent Linux distributions). It is also available separately, see http://gcc.gnu.org/wiki/GFortran. G95 is a separate Fortran 95 compiler , see http://www.g95.org/. They are are both free/open source.

G95 has been able to build ROMS for a year or two, Gfortran has only managed it more recently. G95 is a little friendlier and more adaptable and I generally prefer it, but Gfortran now supports OpenMP, hence my renewed interest.

User avatar
arango
Site Admin
Posts: 1081
Joined: Wed Feb 26, 2003 4:41 pm
Location: IMCS, Rutgers University
Contact:

#3 Post by arango » Wed Sep 06, 2006 1:06 am

Good job Mark :!: Did you used the same configuration file as with G95? If not, please send me the Gfortran configuration file so I can add it our increasing list of make include files.

User avatar
m.hadfield
Posts: 517
Joined: Tue Jul 01, 2003 4:12 am
Location: NIWA

#4 Post by m.hadfield » Wed Sep 06, 2006 6:01 am

Hi Hernan

As you know, I just sent you an email about this stuff, but I'll mention the info here in case it's of wider interest.

Good old g77 adds two underscores to its global symbols. G95 is binary-compatible with g77 and also uses two underscores. Gfortran is not binary-compatible and uses a single underscore. However the gfortran -ff2c switch causes it to use two. See

http://gcc.gnu.org/onlinedocs/gcc-4.1.1 ... en-Options
http://www.g95.org/docs.html

Until today, I had a single version of the netCDF library, built with g95 or g77. To link gfortran-compiled ROMS with that I used the -ff2c switch.

Conversely, in the master copy of the ROMS source (and by "master" I mean "Hernan"), Makefile.g95 has had -fno-second-underscore in its FFLAGS. From this I conjecture that you are linking g95-compiled ROMS with a library built with gfortran.

The cleanest solution for the ROMS source is, I think, to avoid either of these flags. If you're using g95 you should link with a netCDF library built with g95, ditto with gfortran. If you want to be able to use both compilers, you'll need two versions of the netCDF library. But you might disagree...

kfennel
Posts: 33
Joined: Thu Jun 12, 2003 6:55 pm
Location: Dalhousie University

#5 Post by kfennel » Wed Dec 13, 2006 6:08 pm

Hi,

we're trying to build ROMS with OpenMP on a Linux (centOS 4.4 X86_64) system for testing purposes, and are having problems with OpenMP in particular

Initial build attempts without OpenMP were successful using either gfortran or g95 fortran compiler. Most recent attempts now with openMP enabled are failing with errors (shown below) - regardless of building and linking to different NetCDF builds appropriate for the compiler.

the errors shown are,

(a) for g95 build:

Bin/cpp_clean propagator.f90
g95 -c -ftrace=full -O3 -ffast-math propagator.f90
g95 -c -ftrace=full -O3 -ffast-math ocean_control.f90
g95 -c -ftrace=full -O3 -ffast-math master.f90
g95 -ftrace=full -O3 -ffast-math master.o ocean_control.o propagator.o -o oceanO libNLM.a libUTIL.a libMODS.a -L/opt/netcdf/lib -lnetcdf
libUTIL.a(mp_routines.o)(.text+0x105): In function `my_numthreads__':
: undefined reference to `omp_get_max_threads__'
libUTIL.a(mp_routines.o)(.text+0x165): In function `my_threadnum__':
: undefined reference to `omp_get_thread_num__'
make: *** [oceanO] Error 1
rm mod_kinds.f90

(b) for gfortran build:

...
: undefined reference to `nf_inq_varndims_'
libUTIL.a(get_varcoords.o)(.text+0x226): In function `get_varcoords_':
: undefined reference to `nf_get_vara_double_'
libUTIL.a(get_varcoords.o)(.text+0x2e7): In function `get_varcoords_':
: undefined reference to `nf_inq_varid_'
libUTIL.a(get_varcoords.o)(.text+0x321): In function `get_varcoords_':
: undefined reference to `nf_inq_varndims_'
libUTIL.a(get_varcoords.o)(.text+0x394): In function `get_varcoords_':
: undefined reference to `nf_get_vara_double_'
libUTIL.a(get_varcoords.o)(.text+0x508): In function `get_varcoords_':
: undefined reference to `nf_inq_varname_'
libUTIL.a(nf_fwrite2d.o)(.text+0x17c): In function `nf_fwrite2d_':
: undefined reference to `nf_put_vara_double_'
libUTIL.a(nf_fwrite3d.o)(.text+0x2d7): In function `nf_fwrite3d_':
: undefined reference to `nf_put_vara_double_'
collect2: ld returned 1 exit status
make: *** [oceanO] Error 1
rm mod_kinds.f90
[root@localhost roms]#


Does anyone have any hints or comments on steps to be taken to successfully build OpenMP ROMS on this sort of platform?

Many thanks,

Katja Fennel (& Tim Chipman)

User avatar
m.hadfield
Posts: 517
Joined: Tue Jul 01, 2003 4:12 am
Location: NIWA

#6 Post by m.hadfield » Wed Dec 13, 2006 9:52 pm

G95 doesn't support OpenMP, so it's not surprising that didn't work.

You Gfortran problems look like they're related to name mangling, the subject of my previous post on this thread. I suggest you make sure you are *not* using the "-ff2c" switch with Gfortran (your error messages suggest you aren't) and that you link with a netCDF library that has been built with Gfortran, or with G95 or G77 using the -fno-second-underscore switch. You might find this helpful:

http://www.unidata.ucar.edu/support/hel ... 01040.html

It *is* possible to build and run ROMS in OpenMP mode with Gfortran on Linux. Once you get past the linking issues, you might have a problem with your kernel version: it has to be reasonably recent to support thread-local storage or some such thing; if not, an error is issued at run time.

Post Reply