The LAPACK forum has moved to https://github.com/Reference-LAPACK/lapack/discussions.

About Lapack C++

Open discussion regarding features, bugs, issues, vendors, etc.

About Lapack C++

Postby truelies » Fri Apr 11, 2008 12:55 pm

I am new to Lapack. I want to use Lapack under gnu c++, I found Lpp can do this. What I am wondering is:

Does the Lapack solution use Fortran routines from Lapack or all the routines have already been rewritten to C++? Thank you!
truelies
 
Posts: 27
Joined: Thu Apr 10, 2008 6:31 pm

Postby Danesh_D » Sat Apr 12, 2008 10:32 am

LAPACK is written in Fortran77 but you can easily call its function in C/C++ too. All you need is a wrapper which acts as an interface between you and LAPACK library. The wrapper should be written in C/C++ and contains just simple function signatures. You can also find ready-to-use wrappers on net. I'm sure if you google for it, you will find your right wrapper.

Danesh
Danesh_D
 
Posts: 31
Joined: Mon Jun 04, 2007 10:03 pm

Postby truelies » Thu May 29, 2008 5:46 pm

Thank you! Now my problem is how to connect the c/c++ with the wrappers and LAPACK? I couldn't find explanation on line.


Danesh_D wrote:LAPACK is written in Fortran77 but you can easily call its function in C/C++ too. All you need is a wrapper which acts as an interface between you and LAPACK library. The wrapper should be written in C/C++ and contains just simple function signatures. You can also find ready-to-use wrappers on net. I'm sure if you google for it, you will find your right wrapper.

Danesh
truelies
 
Posts: 27
Joined: Thu Apr 10, 2008 6:31 pm

Postby Julie » Thu May 29, 2008 6:09 pm

My first question is:
- Do you have a Fortran Compiler on your machine?

Julie
Julie
 
Posts: 299
Joined: Wed Feb 23, 2005 12:32 am
Location: ICL, Denver. Colorado

Postby truelies » Thu May 29, 2008 6:12 pm

Yes. Intel visual fortran 11, but my code was written on C/C++ based on Mingw.

Julie wrote:My first question is:
- Do you have a Fortran Compiler on your machine?

Julie
truelies
 
Posts: 27
Joined: Thu Apr 10, 2008 6:31 pm

Postby Julie » Fri May 30, 2008 10:40 am

ok, so you have different way to go:
- 1st solution:
Use the LAPACK build under Visual Studio or nmake to build LAPACK library and link your program with it in Mingw. This will need to add some Intel Fortran Compiler library at linking
The package is available at http://icl.cs.utk.edu/lapack-for-windows/

Here is how to call Fortran from C++

The extern "C" directive
First of all, the extern "C" linkage specification must be used to declare any modules that are not written in C++.
So you will have to define the Fortran routine in your C++code:
Code: Select all
extern "C" void dgeqrf_ (const int &m, const int &n, double da[], const int &lda, double dtau[], double dwork[], const int &ldwork, int &info)

Case sensitivity

C++ is a case sensitive language, Fortran is not. The name of the Fortran routine is mangled by the compiler. All references to Fortran symbols may be specified in lowercase or in uppercase (depends on the compiler) in C++ calls.

The underscore (_)
In many Fortran compilers, an underscore (_) is appended by default at the end of definitions and references to externally visible symbols (subroutines, functions, etc.). This happens for Solaris and Digital UNIX f77 compilers, for g77 compiler and for hepf77 compiler interface; on HP-UX the +ppu option must be added to the f77 compiler to activate this feature; on AIX -qextname must be added to the xlf compiler. The appended underscore is a standard for HEP Fortran libraries (e.g. CERNLIB). In a C++ call the Fortran subroutines or functions must be specified with an appended underscore.

Passing parameters
An important thing to remember is that C++ passes all parameters by value (except arrays and structures). Fortran passes them by reference. It is therefore necessary to specify in the C++ function prototypes that the Fortran subroutines and functions expect call-by-reference arguments using the address-of (&) operator.

Arrays
C++ stores arrays in row-major order, whereas Fortran stores arrays in column-major order. The lower bound for C++ is 0, for Fortran is 1. This mean that the Fortran array element myarray(1,1) corresponds to the C++ array element myarray[0][0]; whereas myarray(6,8) corresponds to myarray[7][5];
[color=darkred]

- 2nd Solution:
use the CLAPACK build (LAPACK tranlated to C) under Visual Studio to build LAPACK library and link your program with it in Mingw.
The package is available at http://icl.cs.utk.edu/lapack-for-windows/

Hope it helps
Julie
Julie
 
Posts: 299
Joined: Wed Feb 23, 2005 12:32 am
Location: ICL, Denver. Colorado

Postby truelies » Tue Jun 03, 2008 5:52 pm

Hi. Julia:

I tried your method. But looks like I can't build the LIB files.

First I downloaded the file LAPACK_3.1.1_for_Windows_VS.zip for the web site you gave. I unzipped it to a dictionary, then I opened the \lapack-3.1.1\Visual Studio Solution\lapack-3.1.1.sln under Intel Fortran 11.0 visual studio 2005. Selected "rebuild the solution". When linking to generate lapack.lib, will pop out a window"Microsoft visual studio has encountered a problem and needs to close". In the IDE: fatal error LNK1181: can't open "lapack.lib".

Do you know what's the problem? Thank you!




Julie wrote:ok, so you have different way to go:
- 1st solution:
Use the LAPACK build under Visual Studio or nmake to build LAPACK library and link your program with it in Mingw. This will need to add some Intel Fortran Compiler library at linking
The package is available at http://icl.cs.utk.edu/lapack-for-windows/

Here is how to call Fortran from C++

The extern "C" directive
First of all, the extern "C" linkage specification must be used to declare any modules that are not written in C++.
So you will have to define the Fortran routine in your C++code:
Code: Select all
extern "C" void dgeqrf_ (const int &m, const int &n, double da[], const int &lda, double dtau[], double dwork[], const int &ldwork, int &info)

Case sensitivity

C++ is a case sensitive language, Fortran is not. The name of the Fortran routine is mangled by the compiler. All references to Fortran symbols may be specified in lowercase or in uppercase (depends on the compiler) in C++ calls.

The underscore (_)
In many Fortran compilers, an underscore (_) is appended by default at the end of definitions and references to externally visible symbols (subroutines, functions, etc.). This happens for Solaris and Digital UNIX f77 compilers, for g77 compiler and for hepf77 compiler interface; on HP-UX the +ppu option must be added to the f77 compiler to activate this feature; on AIX -qextname must be added to the xlf compiler. The appended underscore is a standard for HEP Fortran libraries (e.g. CERNLIB). In a C++ call the Fortran subroutines or functions must be specified with an appended underscore.

Passing parameters
An important thing to remember is that C++ passes all parameters by value (except arrays and structures). Fortran passes them by reference. It is therefore necessary to specify in the C++ function prototypes that the Fortran subroutines and functions expect call-by-reference arguments using the address-of (&) operator.

Arrays
C++ stores arrays in row-major order, whereas Fortran stores arrays in column-major order. The lower bound for C++ is 0, for Fortran is 1. This mean that the Fortran array element myarray(1,1) corresponds to the C++ array element myarray[0][0]; whereas myarray(6,8) corresponds to myarray[7][5];
[color=darkred]

- 2nd Solution:
use the CLAPACK build (LAPACK tranlated to C) under Visual Studio to build LAPACK library and link your program with it in Mingw.
The package is available at http://icl.cs.utk.edu/lapack-for-windows/

Hope it helps
Julie
truelies
 
Posts: 27
Joined: Thu Apr 10, 2008 6:31 pm

Postby truelies » Tue Jun 03, 2008 5:53 pm

Also I built it under release/ win32.
truelies
 
Posts: 27
Joined: Thu Apr 10, 2008 6:31 pm

Postby Julie » Tue Jun 03, 2008 5:57 pm

Check the LAPACK project properties and more specifically the path to lapack.lib, you may have to adapt it to your path on your machine.
Julie
Julie
 
Posts: 299
Joined: Wed Feb 23, 2005 12:32 am
Location: ICL, Denver. Colorado

Postby truelies » Tue Jun 03, 2008 6:27 pm

Julie:

Where to input the path of lapack.lib? The rebuild can get the new blas.lib, matgen.lib and extras.lib, but stopped at trying build lapack.lib.



Julie wrote:Check the LAPACK project properties and more specifically
the path to lapack.lib, you may have to adapt it to your path on your machine.
Julie
truelies
 
Posts: 27
Joined: Thu Apr 10, 2008 6:31 pm

Postby Julie » Tue Jun 03, 2008 6:36 pm

Try to do a "build" instead of a "rebuild".

Here is how to check where the lib is created:
- >Right click on the LAPACK project
- > In the Configuration Properties / Librarian / General.
Check the first line: Output File. Make sure that directory exists.

Also, something that I do to avoid MS Visual crash is to set the options to build and run only one project at a time.
Menu : Tools / Options
-> Projects and Solution / Build and Run.
I put 1 in "maximum number of parallel project builds"

If that does not solve your problem, please send me the log file of the build.
I will take a look.
Hope it helps
Julie
Julie
 
Posts: 299
Joined: Wed Feb 23, 2005 12:32 am
Location: ICL, Denver. Colorado

Postby truelies » Wed Jun 04, 2008 10:25 am

Julie:

After I cleaned the solution and used the build solution. It can generate the .lib files, but got a lot of errors like "error LNK2001: unresolved external symbol _ZSCAL".

I only unzipped the LAPACK_3.1.1_for_Windows_VS.zip to a dictionary and build it under VS2005. Do I need to do some modification on this?

Thank you!

PS: I already emailed you the buildlog.htm


Julie wrote:Try to do a "build" instead of a "rebuild".

Here is how to check where the lib is created:
- >Right click on the LAPACK project
- > In the Configuration Properties / Librarian / General.
Check the first line: Output File. Make sure that directory exists.

Also, something that I do to avoid MS Visual crash is to set the options to build and run only one project at a time.
Menu : Tools / Options
-> Projects and Solution / Build and Run.
I put 1 in "maximum number of parallel project builds"

If that does not solve your problem, please send me the log file of the build.
I will take a look.
Hope it helps
Julie
truelies
 
Posts: 27
Joined: Thu Apr 10, 2008 6:31 pm

Postby Julie » Wed Jun 04, 2008 12:02 pm

You are missing the blas library in the linking sequence.
Julie
Julie
 
Posts: 299
Joined: Wed Feb 23, 2005 12:32 am
Location: ICL, Denver. Colorado

Postby truelies » Wed Jun 04, 2008 12:32 pm

Julie:

How to add blas library in the linking sequence? Thank you!

Julie wrote:You are missing the blas library in the linking sequence.
Julie
truelies
 
Posts: 27
Joined: Thu Apr 10, 2008 6:31 pm


Return to User Discussion

Who is online

Users browsing this forum: No registered users and 8 guests