G95

From OctopusWiki
Jump to navigation Jump to search

Problems with earlier versions of g95

g95 0.92 crashed with an internal error and segmentation fault compiling some files of octopus development version circa May 2014. g95 0.93 with gcc 4.1.2 had runtime errors on many tests in the testsuite, like the one below, in situations where a function argument (from a different module, and using global pointers) was passed to a subroutine. No problem, or real explanation of this message, could be found.

Using input file : ../../testsuite/components/04-hartree_3d_cg.01-cg_corrected.inp 

Starting test run ...
Executing: cd /tmp/octopus._PuX8M;  /home/pulpo/buildbot/lascar_x86_64_g95/build/_build/testsuite/../src/main/oct-test > out 
At line 2003 of file solvers_oct.f90
Traceback: (Innermost first)
   Called from line 353 of file poisson_cg_oct.f90
   Called from line 990 of file poisson_oct.f90
   Called from line 1274 of file poisson_oct.f90
   Called from line 224 of file test_oct.f90
   Called from line 191 of file test_oct.f90
Fortran runtime error: Actual assumed-shape array argument does not conform
	Elapsed time:     29.8 s

However, g95 0.94 with gcc 4.2.4 on Ubuntu worked. So did 0.93 with gcc 4.2.4 on MacOS (from MacPorts). Compiling with this version of gcc took a bit of work, so I give the instructions below.

Instructions for compiling g95 0.94 with gcc 4.2.4 on Ubuntu

Choose an installation directory in which to put the resulting g95 executables, which you will use as prefix below for the configure step in g95 and libf95, in place of $HOME/g95-install. A multi-threaded make -j should work for gcc, but probably won't for g95.

wget ftp://gcc.gnu.org/pub/gcc/releases/gcc-4.2.4/gcc-core-4.2.4.tar.gz
cd gcc-4.2.4
sed -i 's/prune_options (&argc, &argv);//' gcc/gcc.c
mkdir g95
cd g95
../configure --enable-languages=c
make
cd ../..
wget http://ftp.g95.org/g95_source.tgz
tar xzf g95_source.tgz
cd g95-0.94
./configure --prefix=$HOME/g95-install --with-gcc-dir=$PWD/../gcc-4.2.4
sed -i "s|g95_LDADD = |g95_LDADD = $PWD/../gcc-4.2.4/g95/gcc/driver-i386.o |"  Makefile
sed -i "s|f951_LDADD = |f951_LDADD = $PWD/../gcc-4.2.4/g95/libdecnumber/*.o |"  Makefile
sed -i 's/named_section/get_named_section/' trans-decl.c
echo -e "\n\nfopenmp\nF95 Var(flag_openmp)\nEnable OpenMP\n" >> lang.opt
make install
tar xzf libf95.a-0.94.tar.gz
cd libf95.a-0.94
./configure --prefix=$HOME/g95-install 
make install
cd ../..

Finally, you can create a symlink from the resulting executable:

ln -s x86_64-unknown-linux-gnu-g95 g95-install/bin/g95

Explanations of patches

  • Patch 1
sed -i "s|g95_LDADD = |g95_LDADD = $PWD/../gcc-4.2.4/g95/gcc/driver-i386.o |"  Makefile

fixes

gcc -DTARGET_NAME=\"x86_64-unknown-linux-gnu\" -DSTANDARD_EXEC_PREFIX=\"/home/dstrubbe/g95-0.94/../g95-install_src/lib/gcc-lib/x86_64-unknown-linux-gnu/4.2.4\"
-DTARGET_SYSTEM_ROOT=\"\" -DDEFAULT_TARGET_VERSION=\"\" -DDEFAULT_TARGET_MACHINE=\"\" -DTOOLDIR_BASE_PREFIX=\"\"
-DSTANDARD_STARTFILE_PREFIX=\"\" -DSTANDARD_STARTFILE_PREFIX_2=\"/usr/lib64\" -DSTANDARD_EXEC_PREFIX=\"/home/dstrubbe/g95-0.94/../g95-install_src/lib/gcc-lib/x86_64-unknown-linux-gnu/4.2.4\"
-DSTANDARD_BINDIR_PREFIX=\"/home/dstrubbe/g95-0.94/../g95-install_src/bin\" -DSTANDARD_LIBEXEC_PREFIX=\"/home/dstrubbe/g95-0.94/../g95-install_src/lib/gcc-lib/x86_64-unknown-linux-gnu/4.2.4\"
-DG95_SPEC=\"\"  -g -O2 -DIN_GCC -Wall -Wmissing-prototypes   -o g95 g95-g95spec.o /home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/gcc/prefix.o gcc.o version.o
/home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/gcc/intl.o /home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/libiberty/libiberty.a  
gcc.o:(.rodata+0x14d8): undefined reference to `host_detect_local_cpu'
  • Patch 2
sed -i 's/named_section/get_named_section/' trans-decl.c

fixes

gcc  -g -O2 -DIN_GCC -Wall -Wmissing-prototypes   -o f951 arith.o array.o bbt.o bigint.o bigreal.o check.o convert.o data.o decl.o dump.o entry.o error.o expr.o f95-lang.o forall.o
format.o imodule.o interface.o intrinsic.o io.o iresolve.o kinds.o lang-options.o match.o matchexp.o misc.o module.o parse.o primary.o resolve.o scanner.o scalarize.o select.o show.o
simplify.o st.o symbol.o trans-array.o trans-decl.o trans-intrinsic.o trans-stmt.o trans.o trans-common.o trans-const.o trans-expr.o trans-io.o trans-types.o options.o opts.o version.o
ggc-page.o /home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/gcc/main.o /home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/gcc/libbackend.a
/home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/libcpp/libcpp.a /home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/libiberty/libiberty.a  
trans-decl.o: In function `g95_dump_coarray':
/home/dstrubbe/g95-0.94/trans-decl.c:2882: undefined reference to `named_section'
  • Patch 3
echo -e "\n\nfopenmp\nF95 Var(flag_openmp)\nEnable OpenMP\n" >> lang.opt

fixes

gcc  -g -O2 -DIN_GCC -Wall -Wmissing-prototypes   -o f951 arith.o array.o bbt.o bigint.o bigreal.o check.o convert.o data.o decl.o dump.o entry.o error.o expr.o f95-lang.o forall.o
format.o imodule.o interface.o intrinsic.o io.o iresolve.o kinds.o lang-options.o match.o matchexp.o misc.o module.o parse.o primary.o resolve.o scanner.o scalarize.o select.o show.o
simplify.o st.o symbol.o trans-array.o trans-decl.o trans-intrinsic.o trans-stmt.o trans.o trans-common.o trans-const.o trans-expr.o trans-io.o trans-types.o options.o opts.o version.o
ggc-page.o /home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/gcc/main.o /home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/gcc/libbackend.a
/home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/libcpp/libcpp.a /home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/libiberty/libiberty.a  
/home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/gcc/libbackend.a(cgraph.o): In function `cgraph_varpool_finalize_decl':
/home/dstrubbe/gcc-4.2.4/g95/gcc/../../gcc/cgraph.c:1002: undefined reference to `flag_openmp'
/home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/gcc/libbackend.a(omp-low.o): In function `gate_expand_omp':
/home/dstrubbe/gcc-4.2.4/g95/gcc/../../gcc/omp-low.c:3565: undefined reference to `flag_openmp'
/home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/gcc/libbackend.a(omp-low.o): In function `gate_lower_omp':
/home/dstrubbe/gcc-4.2.4/g95/gcc/../../gcc/omp-low.c:4439: undefined reference to `flag_openmp'
  • Patch 4
sed -i "s|f951_LDADD = |f951_LDADD = $PWD/../gcc-4.2.4/g95/libdecnumber/*.o |"  Makefile

fixes

gcc  -g -O2 -DIN_GCC -Wall -Wmissing-prototypes   -o f951 arith.o array.o bbt.o bigint.o bigreal.o check.o convert.o data.o decl.o dump.o entry.o error.o expr.o f95-lang.o forall.o
format.o imodule.o interface.o intrinsic.o io.o iresolve.o kinds.o lang-options.o match.o matchexp.o misc.o module.o parse.o primary.o resolve.o scanner.o scalarize.o select.o show.o
simplify.o st.o symbol.o trans-array.o trans-decl.o trans-intrinsic.o trans-stmt.o trans.o trans-common.o trans-const.o trans-expr.o trans-io.o trans-types.o options.o opts.o version.o
ggc-page.o /home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/gcc/main.o /home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/gcc/libbackend.a
/home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/libcpp/libcpp.a /home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/libiberty/libiberty.a  
/home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/gcc/libbackend.a(dfp.o): In function `decimal_to_decnumber':
/home/dstrubbe/gcc-4.2.4/g95/gcc/../../gcc/dfp.c:112: undefined reference to `decContextDefault'
/home/dstrubbe/gcc-4.2.4/g95/gcc/../../gcc/dfp.c:121: undefined reference to `decNumberFromString'
/home/dstrubbe/gcc-4.2.4/g95/gcc/../../gcc/dfp.c:125: undefined reference to `decNumberFromString'
/home/dstrubbe/gcc-4.2.4/g95/gcc/../../gcc/dfp.c:131: undefined reference to `decimal128ToNumber'
/home/dstrubbe/gcc-4.2.4/g95/gcc/../../gcc/dfp.c:127: undefined reference to `decNumberFromString'
/home/dstrubbe/gcc-4.2.4/g95/gcc/../../gcc/dfp.c:118: undefined reference to `decNumberZero'
/home/dstrubbe/g95-0.94/../gcc-4.2.4/g95/gcc/libbackend.a(dfp.o): In function `encode_decimal128':
/home/dstrubbe/gcc-4.2.4/g95/gcc/../../gcc/dfp.c:252: undefined reference to `decContextDefault'
/home/dstrubbe/gcc-4.2.4/g95/gcc/../../gcc/dfp.c:256: undefined reference to `decimal128FromNumber'
...

References