Linking with LAPACK using gfortran on Fedora Linux - fortran

I need some help regarding installation of LAPACK ( for Fortran 95) on a Fedora machine.
I am writing this post after having tried all answers posted to pertinent queries in this forum.
I tried two different options:
METHOD 1
I directly downloaded the lapack95.a library from here (http://www.netlib.org/lapack95/, file named lapack95_linux_redhat.tgz. After unzipping, I could get file lapack95.a
After looking for some answers on how to link and use libraries, I wrote a trial code and saved in file try.f90 and then did the following
gfortran -c try.f90
gfortran -o try try.o -L/(name of directory where lapack95.a
was present. I put it in the same directory
as try.f90)/ -llapack95
( The fortran file try.f90 and lapack95.a were in the same directory)
I got the following error:
/usr/bin/ld: cannot find -llapack95
collect2: error: ld returned 1 exit status
I searched on internet and found here (https://forums.fedoraforum.org/archive/index.php/t-248227.html) that we need to install lapack-devel.
I did that and had the same outcome.
Method 2
I also tried running the above command (in Method 1) but without space between / and -llapack95 , i.e. as :
gfortran -o try try.o -L/(name of directory where lapack95.a
was present I put it in the same directory
as try.f90)/-llapack95
and received the following error:
try.o: In function `MAIN__':
try.f90:(.text+0xdb): undefined reference to `sgesv_'
collect2: error: ld returned 1 exit status
Method 3
After having no success, I thought may it's not good idea to use the lapack95.a downloaded directly. I should build it from the original files.
I realized that may be I need to install lapack95 through proper means following which from the same link
http://www.netlib.org/lapack95
I downloaded the file lapack95.tgz and followed the instructions in readme file.( which said just to run make file in SRC)
I made some changes as :
FC1 = f95 -fixed to
FC1 = f95
and
OPTS0 = -u -V -dcfuns -dusty -ieee=full
to
OPTS0 = -u -V
( as suggested on https://www.reddit.com/r/linux4noobs/comments/7tgmb9/fortran_library_netlib_lapack95_installation_error/)
I expected that the library will be created in /usr/lib/ or usr/local/lib as LAPACK3 but couldn't find it.
Infact there was an error ( and thus could not have any .a file )
f95 -free -c -u -V - -I./../lapack95_modules f77_lapack_double.f90 f95: error: -E or -x required when input is from standard input make: *** [../make.inc:45: f77_lapack_double.o] Error 1
I am not sure if any of my method is fine.
I expected Method 1 to work as I am linking the library locally but failure in all 3 cases.
Kindly suggest.
Thanks

Lapack library is a very useful tool to conduct matrix operations in a fast way. On the linux machine, it is very simple to install lapack with the build-in tools: dnf/yum or apt-get [2]. On my Fedora desktop, installation is like this:
sudo dnf install lapack64-devel.x86_64
Here is a small example on how to use lapack lib. The source code is to solve linear equations as linear_eqs.f [3].
Program LinearEquations
c solving the matrix equation A*x=b using LAPACK
Implicit none
c declarations, notice single precision
Real*4 A(3,3), b(3)
integer i, j, pivot(3), ok
c define matrix A
A(1,1)=3.1
A(1,2)=1.3
A(1,3)=-5.7
A(2,1)=1.0
A(2,2)=-6.9
A(2,3)=5.8
A(3,1)=3.4
A(3,2)=7.2
A(3,3)=-8.8
c define vector b, make b a matrix and you can solve multiple
c equations with the same A but different b
b(1)=-1.3
b(2)=-0.1
b(3)=1.8
c find the solution using the LAPACK routine SGESV
call SGESV(3, 1, A, 3, pivot, b, 3, ok)
c
c parameters in the order as they appear in the function call
c order of matrix A, number of right hand sides (b), matrix A,
c leading dimension of A, array that records pivoting,
c result vector b on entry, x on exit, leading dimension of b
c return value
c
c print the vector x
do i=1, 3
write(*,*) b(i)
end do
end
In this code, one lapack function 'sgesv()' is used. To execute this file, run the below command:
gfortran linear_eqs.f -llapack -o lineqs.out
./lineqs.out
The outputs will be:
1.00000024
1.00000036
1.00000036
Reference
[1] https://github.com/fxcoudert/gfortran-for-macOS/releases
[2] BLAS, ATLAS, LAPACK Shared library minimal example
[3] http://physics.oregonstate.edu/~landaur/nacphy/lapack/codes/linear-f.html

Related

link against a legacy library: -lgfortranbegin from a premade makefile

I got some trouble trying to compile a programm developed by some researcher supposed to compute in a very precise way fourier transform and some other useful operation scientific paper here, whereas all the files needed and the makefile are provided.
I use gcc and a version of ubuntu available on windows10 (18.04), so, I linked all the librabries needed by the program and called in the pre-made makefile (fftw, lapack, gfortran..) everything is ok untill here, but once I tried to compile I got the error message:
/usr/bin/ld: cannot find -lgfortranbegin
collect2: error: ld returned 1 exit status
Makefile:38: recipe for target 'furian_main' failed
make: *** [furian_main] Error 1
After a few research it appears that libfortranbegin is a legacy code and no more available(source: here ) ..
So my question is: is it possible for me to compile my program without this legacy library (somme people say that we could get rid off this library, but I didn't understand what they do .. here)
Or should I do some update or use another library ?
Thank you for your time and consideration :)
The usual way of solving this is the following one:
remove the -lgfortranbegin
check the new link errors and look at what source file from the original source code implemented this feature
add this source file to your repository and your build and go back to step 2.
Be aware that it may still not work in the end, but hopefully you will be able to have the missing symbols.

Installing Fortran library Expokit (Windows/Ubuntu)

I am looking to perform matrix exponentials, which apparently the Expokit library is suitable for. Sadly unlike Lapack or OpenMP this is not easily installed from Cygwin or Mingw for Windows. Therefore I have downloaded the library from here, however once unpacked it consists purely of .f files with little guidance on how to use them. The only site I've found online isn't much use (Fortran Wiki), as it doesn't give any indication of how the Expokit library is linked.
I would greatly appreciate any guidance on how to install Expokit on Windows, or alternatively on Ubuntu if Windows is not suitable.
Making the change suggested by ripero and running 'make sample_d' on Ubuntu I get the log shown below. I assume this means the sample has been compiled successfully, but I have no idea how this enables me to use Expokit as a library in my Fortran programs. Could someone please provide guidance on this?
XX:~/programs/expokit/expokit/fortran$ make sample_d
f77 -O3 -c blas.f
blas.f:404:72:
10 assign 30 to next
1
Warning: Deleted feature: ASSIGN statement at (1)
blas.f:409:19:
20 go to next,(30, 50, 70, 110)
1
Warning: Deleted feature: Assigned GOTO statement at (1)
blas.f:411:72:
assign 50 to next
1
Warning: Deleted feature: ASSIGN statement at (1)
blas.f:420:72:
assign 70 to next
1
Warning: Deleted feature: ASSIGN statement at (1)
blas.f:427:72:
assign 110 to next
1
Warning: Deleted feature: ASSIGN statement at (1)
blas.f:1621:72:
10 assign 30 to next
1
Warning: Deleted feature: ASSIGN statement at (1)
blas.f:1628:19:
go to next,(30, 50, 70, 90, 110)
1
Warning: Deleted feature: Assigned GOTO statement at (1)
blas.f:1630:72:
assign 50 to next
1
Warning: Deleted feature: ASSIGN statement at (1)
blas.f:1639:72:
assign 70 to next
1
Warning: Deleted feature: ASSIGN statement at (1)
blas.f:1644:72:
100 assign 110 to next
1
Warning: Deleted feature: ASSIGN statement at (1)
blas.f:1671:72:
85 assign 90 to next
1
Warning: Deleted feature: ASSIGN statement at (1)
blas.f:1689:16:
go to next,( 50, 70, 90, 110 )
1
Warning: Deleted feature: Assigned GOTO statement at (1)
f77 -O3 -c lapack.f
f77 -o sample_d sample_d.o clock.o expokit.o mataid.o blas.o lapack.o
Your Fortran compiler fails to compile file sample_d.f due to a non-standard format statement. The source code of the same file provides instructions for how to fix it if this happens:
9001 format( <mprint>(1X,D11.4) )
*--- Some compliers (e.g., g77) generate 'Unsupported FORMAT specifier'
* with the specification above. In this case, simply use this form:
* 9001 format( 5(1X,D11.4) )
If you comment the first line above (add a * as the first character of the line) and uncomment the last line (remove the leading *), the error should disappear.
I don't think there is a particular significance to running make sample_d other than ensuring that the object files are created and that a sample program can be compiled and linked against them in order to create a working binary.
First, you should be aware that you have compiled Expokit and one of the sample programs using what their Makefile calls case 3, where the required BLAS and LAPACK subroutines are provided by files blas.o and lapack.o, respectively, compiled from their .f counterparts provided by Expokit.
# Among the 3 possibilities below, uncomment the appropriate
# case for your environment and comment the others.
# case 1: works when LAPACK and BLAS are installed.
OBJLIBS =
LIBS = -llapack -lblas
# case 2: works when LAPACK is not installed but BLAS is.
#LIBS = -lblas
#OBJLIBS = lapack.o
# case 3: works when neither LAPACK nor BLAS are installed.
#OBJLIBS = blas.o lapack.o
#LIBS =
If your system already has BLAS and LAPACK libraries, they very likely are more optimized than the ones in blas.o and lapack.o, and you probably will want to change the case in the Makefile (add/remove leading # to comment/uncomment the appropriate definitions of OBJLIBS and LIBS) so that you can use the system BLAS and LAPACK.
In order to use Expokit in your Fortran programs, you need to call from your source code the relevant subroutines (see the Expokit paper and the source code of expokit.f and mataid.f in order to read about the provided subroutines) and then the simplest is to add to your linking line the following
object files: expokit.o mataid.o followed by all the object files listed in the active OBJLIBS variable in the Expokit Makefile, if any; and
libraries: all the ones listed in the active LIBS variable in the Expokit Makefile, if any.

How to use Boost Wave Lib on Linux

Heading
I am trying to use Boost Wave, but I fail to compile it with those samples in boost_1_55_0/lib/wave/samples. The system I am using is Ubuntu 12.04 64-bit
For examples, when I try to compile the quick_start.cpp I use the commend:
c++ -I ~/Documents/boost_1_55_0 quick_start.cpp -o parser \
~/Documents/boost_1_55_0/stage/lib/libboost_wave.a
The libboost_wave.a is what I get from the ./b2 build commend of boost. The compile output is a super long result ending with:
collect2: ld returned 1 exit status
Part of the rest of output looks like(they are so long):
/tmp/ccpBhjhs.o: In function `boost::filesystem::operator!=(boost::filesystem::path
const&, boost::filesystem::path const&)':
quick_start.cpp: (.text._ZN5boost10filesystemneERKNS0_4pathES3_[boost::filesystem::operator!=(boost::filesystem::path const&, boost::filesystem::path const&)]+0x1f): undefined reference to `boost::filesystem::path::compare(boost::filesystem::path const&) const'
/tmp/ccpBhjhs.o: In function `boost::thread_exception::thread_exception(int, char const*)':
I have no clue what happened! Thanks for reading! If you can help me, Please!
p.s. I have built the wave library following the steps on Boost Website. I managed to use the regex library to build the sample e-mail extract program. So I think my wave library is built correctly.
Try the suggestions in this link:
Linking boost::filesystem on Ubuntu 13.04
1) Check that your boost library contains required symbols, you can use something like this: nm -D /usr/lib64/libboost_filesystem.so.1.52.0 | grep detail | c++filt | grep your names
2) Try to change order of linking library, for example put -lboost_bla-bla-bla to the end of command line, and run this command with g++ again, not use make or something, just copy paste command and make experiments with it.
3) And, of course, make sure you have a "libboost_filesystem.XXX" (either a static .a or shared .so library), and make sure it's in your "ld" (link) command.

Compile c++ code in R does not work anymore

I start saying that i am a newbie in programming and then i am not sure i will be able to explain well my problem.
I had some c++ code i wrote, this code are loaded and used by some R functions.
To compile the code i used the following:
R CMD SHLIB MyCode.cpp
and i loaded the library in R with
dyn.load("MyCOde.so")
Sometimes i built also an R package and i was able to load it into R.
If i do all these stuff on a Mac with mountain lion everything work fine, but now that i switched to mavericks, i have some problems. The R CMD SHLIB MyCode.cpp command works but when i used dyn.load("MyCOde.so") i get the following text:
Errore in dyn.load(paste(dir_function, "MyCOde.so", sep = "")) :
unable to load shared object 'MyCOde.so':
dlopen(MyCOde.so, 6): Symbol not found: __ZNSt8ios_base4InitC1Ev
Referenced from: MyCOde.so
Expected in: flat namespace
in MyCOde.so
Moreover if i try to load the package in R, i get the following
ld: warning: directory not found for option '-L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2'
ld: library not found for -lquadmath
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [MyCode.so] Error 1
Can someone helps me?
Based on the helpful website of:
thecoatlessprofessor
Type this into your terminal shell:
curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2
sudo tar fvxz gfortran-4.8.2-darwin13.tar.bz2 -C /
This will create what you need to resume compiling as before.
Since it starts to work I can publish the answer for such a cases.
When you change the compiler and standard libraries - please note that different libraries have different implementation and different standard support. Changing the basement of your system might require total rebuild of your system with the new C++ standard library.
Your libraries are not the exception. So if have the errors in your linker like this:
warning: directory not found for option
'-L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2'
apply next algorithm:
Check whether the directory /usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2 still exists. I bet it is not.
Check if you still have the libstdc++ from the missed compiler? Usually if you upgrade the same compiler and the C++ standard library ABI does not change everything should continue to work. If the ABI changed or you switch standard C++ library and compiler - you face the massive system rebuild.
Recompile your library and apps with the new C++ standard library and compiler.

Compiling DISLIN gfortran

I am having trouble compiling Fortran code with references to DISLIN. I have downloaded DISLIN from the website, unzipped the file and ran the setup. I have added an environment variable called DISLIN (C:\dislin) and added C:\dislin\win to the PATH section of my system variables.
I am trying to compile some example code of the DISLIN website which includes line
USE DISLIN
I am using a MinGW shell to compile with command gfortran -o progrname -ldislin EX11_1.f90 and am getting the following error:
Fatal Error: Cant open module file 'dislin.mod' for reading at (1): No such file or directory.
I have tried changing the variable path and even moving the dislin.mod file (which is there) but still get the same message.
Ok I fixed this problem so thought I come back and post what worked for me incase any one else needs it...
Install both DISLIN and MinGW on the c drive
Copy disgf.a from /c/dislin and dislin.f90 from /c/dislin/gf into the directory containing your fortran files
(for me this is /c/MinGW/pnote)
Using the MinGW shell navigate to you files: cd /c/MinGW/pnote
compile dislin.f90 and your fortran program: gfortran -c dislin.f90 progName.f90 (dislin.f90 obviously only needs to be done once)
link libraries etc and compile: gfortran progName.o disgf.a -luser32 -lgdi32 -lopengl32 -o exeName
'run' exeName
You probably need to specify the path to the DISLIN module files:
gfortran EX11_1.f90 -o progrname -ldislin -I/path/to/DISLIN/modules
and, if not already configured like described here, also the path to the library itself:
gfortran EX11_1.f90 -o progrname -ldislin -I/path/to/DISLIN/modules \
-L/path/to/DISLIN/library
They provide a batch file (windows) to do the compiling and linking for you.
f90link -c My_Program
This is located in c:\dislin\Win
Also, if you are having trouble with the dislin.mod file which resides in c:\dislin\gf then recompile that with the -c compile option. I found all of this info in c:\dislin\readme.inf
near as I can tell (Jan 2018) dislin (64 bit) fails miserably with gfortran 7.2, period; and probably with many other newer compilers.
When trying to link, gfortran 7 says 'dislin.mod' is an unrecognizable format.
I think this program is highly dependent on exactly correct version synchronization - something that renders such software useless imho after many years in research.
and no, the correctness of various 'paths' seems not to help.
after all, gnuplot works, "at all". Not sure why I spent so much time on brand x.
jrc