Topic: Simply lapack

I am new here so Hi to all.
Let me first thank Jeff for Simply Fortran
and then ask a simple question:
How to simply install lapack?
Carlos

Re: Simply lapack

The LAPACK site seems to contain quite good instructions on what to do.
You probably need to find the section for the MinGW version.
There appear to be libraries you need to put somewhere on your PC.
I've learned that library files can just be ADDed to a project, just as if they were source files, and Simply Fortran recognises what they are and only links the code it needs from them.

Do you need a banded symmetrical linear equation solver using SKYLINE storage?  I don't think LAPACK has this.
I have a really good subroutine for it, written by Prof RL Taylor in Ziekiewicz on FE analysis, which I have slightly adapted and annotated with comments.  Say if you'd like the source code - it's not very long and I could post it here if Jeff doesn't mind.
---
John

Re: Simply lapack

@John
Thank you for your offer, however at the moment  I need only lapack and blas.
Yes, probably I can compile lapack in a MinGWish way,
but the reason I am using Simply Fortran is to act "automagically", if possible.
Anyway, I have solved the problem, but the solution is not very elegant:
1. I created SF project (with static library option) and added
manually all ~1650 files  from lapack SRC folder. Build went
nicely. I did the same with blas files.
2. I copied liblapack.a and  libblas.a  to ..\Simply Fortran\mingw\lib\ folder.
3. I compiled my program with linker options -llapack -lblas and it turned
out that the file dlamch.f was missing. I found in it INSTALL folder of lapack directory (?).
After adding the missing file to the SF project and recompilation everything went
as expected. Will see with other programs...
The question is, how to add the contents of an entire folder to the project?
There is something like "Add folder" in project options, but I have not figured out
how it works.
Carlos

Re: Simply lapack

Carlos,

I'm glad you got LAPACK and BLAS compiled.  There currently isn't a good way to add a file-system folder to a project.  However, when you select "Add Files..." you may select multiple files if you wish. 

I've been working on a way to easily add packages to Simply Fortran.  It's a ways off yet, but hopefully we'll have a solution soon.

Jeff Armstrong
Approximatrix, LLC

Re: Simply lapack

I was able to compile the Lapack 3.4.0
with SF 1.32 by means of the method hinted by Carlos.
However, the files can be added to the project in groups
and not all at once. It is not common to
add the project thousands of files at once.

The announced possibility to add on the fly
fundamental packages is VERY important.
Ettore

Re: Simply lapack

@ Carlos Herrera, JohnWasilewski, Ettore, Jeff Armstrong
Gentlemen,

Could you, please, post detailed step-by-step instructions for COMPLETE NOVICE how to use LAPACK and BLAS wit SF 2.17 or above? By this I mean instructions on similar level to the Tutorial in the SF's Help menu.


Here are several examples of (for you) very simple questions that novices need to learn:
Carlos wrote "2. I copied liblapack.a and  libblas.a  to " - where do you get these two files from? He also wrote "3. I compiled my program with linker options -llapack -lblas..." - where  do you actually enter these options in SF? Where is the linker in the SF's menu? The Windows LAPACK site (http://icl.cs.utk.edu/lapack-for-windows/lapack/)  is filled with info. What do we exactly need there? Where is actually LAPACK file to download there?

Fortran and SF is useless without LAPACK. Everyone needs these info. Providing details would not only help me but the rest of the community that are novices.

Thank you all very much.

Re: Simply lapack

Compiling LAPACK can be straightforward if you're familiar with the process.  However, it is time-consuming, and you'll need to place the resultant libraries in the proper directories.  For these reasons, we provide pre-built LAPACK and BLAS packages for subscribers to the SF Package Manager service.  Saying Fortran is useless without LAPACK is a bit of an exaggeration, though. Much of the world gets by with Fortran's intrinsic procedures for their linear algebra needs.

The first step is to compile LAPACK with Simply Fortran.  While you could do so using the instructions on the LAPACK for Windows site you linked to, I wouldn't suggest doing so.  They've made things unnecessarily complex by using CMAKE to control the build process.

To get started, you can download LAPACK from the LAPACK home page.  You'll need software that can deal with a file ending in ".tgz" to extract the archive.  Next, you'll need to create a project for compiling LAPACK in Simply Fortran.  You can download a working project from http://download.approximatrix.com/sfort … -3.5.0.prj.  Place this project in the folder lapack-3.5.0 that was created when the LAPACK archive was extracted, and load the project in Simply Fortran.

Because LAPACK is so large, you'll need to wait a bit (minutes) for Simply Fortran to finish scanning files for dependency reasons (even though there are no dependencies).  Once Simply Fortran's status bar no longer says "Indexing: Dependencies," you can start building LAPACK by clicking "Build Now!" in the Build menu.  Depending on your system, LAPACK should compile in a few minutes.

Once LAPACK is built, you can now use it with your own Fortran code.  To do so, you'll first need to add the library to your Linker flags in Project Options under the Compiler Flags tab.  To do so, enter:

-llapack

Next, you need to tell your new project where it can find the LAPACK library, liblapack.a, that was built in the previous step.  In the Project Options window, you can proceed to the "File Locations" tab and click the button marked "Search Directories."  In the Directories window, click the "Library Directories" tab and click "Add..."  Navigate to the directory where LAPACK lives and select it.  Click Ok to leave the Directories window and Ok again to leave the Project Options window.  Save you project, and you should be able to call LAPACK functions.

Most of these steps are, of course, unnecessary if the Package Manager is used instead.

I hope the above instructions help!  They are complicated because the steps to build LAPACK are themselves complicated.  LAPACK, thankfully, is a straightforward library to compile.  Its size is the only thing that makes compiling it complex.

Jeff Armstrong
Approximatrix, LLC

Re: Simply lapack

@ Jeff
Thanks very much Jeff. Let me try it and will get back with a post how it went.

Re: Simply lapack

Boris, I hope Jeff's advice helps you make it all work as you require.

You wrote:

Fortran and SF is useless without LAPACK. Everyone needs these.

I must say, I did not realise that LAPACK was as valuable as that!

I write programs which do a lot of linear algebra, particularly with banded symmetrical arrays for my equation coefficients.
Naturally, I don't waste memory by storing large numbers of off-diagonal zeros, outside the non-zero symmetrical band.

I use two storage strategies:

(1) storing only the half-bandwidth, either in a rectangular array, of size NEQ x HBW, where these integers are the number of equations and the half bandwidth, respectively, or in a 1-D vector.  I write a simple function to retrieve element (i,j) for the full-size matrix from this compacted array of the half bandwidth. 

(2) for problems in which the half bandwidth also contains a lot of zeros, I use 'Skyline' array storage, with a 1-D vector of pointers to  retrieve element (i,j) for the full-size uncompacted matrix.

I can see from the LAPACK website that it will solve Ax + B = C, where A is a full-size square matrix, but can you point me to where in LAPACK docs I can find how to use it to solve these same equations when A is a banded symmetrical matrix stored in the above two compacted forms, without the off-diagonal zeros?

I had thought it was not so good that it could do all this, and was only useful for use coding without a care in the world about efficient storage.   

That is, I thought,

LAPACK is useless with efficiently-stored arrrays.  Everyone needs Fortran and SF for these.

I'd love you to prove me wrong.
---
John

Re: Simply lapack

LAPACK is indeed terribly inefficient for most specialized, banded, or sparse arrays.  It works wonderfully as a general-purpose linear algebra library (if you don't mind the Fortran-77-style calls), but it should generally not be used for large, spare matrices, especially if there is a known, specific, and efficient technique for solving a system.

That said, LAPACK forms the basis for an enormous amount of numerical software.   It is easily the most downloaded package on the SF Package Manager (along with its BLAS dependency).

Jeff Armstrong
Approximatrix, LLC

Re: Simply lapack

@Jef
Thanks once again. Everything went well till the end of compiling. There were 1789 Fortran (in SRC folders of LAPACK and BLAS) compiled, but got the following error message at the end:

======================================
Generating Makefile... Okay
======================================
Compiling .\BLAS\SRC\caxpy.f
Compiling .\SRC\cbbcsd.f
...
... (total 1789 files compiled)
...
Compiling .\SRC\zupgtr.f
Compiling .\SRC\zupmtr.f
Generating liblapack.a
The parameter is incorrect.

Error(E42): Last command making (liblapack.a) returned a bad status
Error(E02): Make execution terminated

* Failed *

Could you please advise, what might be wrong?
Thanks!

Re: Simply lapack

@ John

In my case, I have to find eigenvalues/eigenvectors of large Hermitian matrices (size of about 20k) and have to do it for a large number of those matrices. I was recommended to use Fortran+LAPACK+MPI on a supercomputer.

Re: Simply lapack

Generating liblapack.a
The parameter is incorrect.

Error(E42): Last command making (liblapack.a) returned a bad status
Error(E02): Make execution terminated

Could you please email me your Makefile to support@approximatrix.com?  It will have been created in the lapack-3.5.0 directory.  It would appear that something might be wrong with the final step in generating the library.

Jeff Armstrong
Approximatrix, LLC

Re: Simply lapack

The problem in the original project file was actually that the final command line for creating the library exceeded 32,768 characters, the maximum length supported by Windows.  I've uploaded a revised version of the project that has a renamed build folder (bld instead of build) that gets the command line length below the Windows limit.

The revised project can be downloaded from the same location:

http://download.approximatrix.com/sfort … -3.5.0.prj

And it seems to be building fine now.

Jeff Armstrong
Approximatrix, LLC

15 (edited by JohnWasilewski 2014-12-19 23:09:44)

Re: Simply lapack

Boris_MV wrote:

@ John

..I have to find eigenvalues/eigenvectors of large Hermitian matrices (size of about 20k) and have to do it for a large number of those matrices.

We are not the same.  Your effort appears to be directed more to advanced mathematics, in which you are content to throw computer resources at your work without any great regard for or distraction by clever ways of optimising the way those resources are used.

In my view, this is far more laudable, and cerebral, than what I do.  I take pleasure from solving a problem that israther elementary compared with yours, but is handled with computer resources so minimal that it's hard to imagine it being possible.  Or rather, that was how I started (with an Apple ][) and 8-bit M$Fortran.  On such a system, with 48k of available memory, 128k of disk storage, no swapfile and an overlay linker, my finest hour was probably when I built a plane strain/[laine stress finite element plate-bending analysis program using 8-noded isoparametric rectangles with parabolic sides and shape functions, and 9 gauss points, which could analyse, solve and then post-process and print graphics output, for a problem with more than 80 elements.  A run like the above would take 2 hours. 

My contribution was a certain amount of skill and imagination in efficient coding, not the maths behind it - for which program authors Hinton and Owen were responsible, at Swansea.

The above is what I used once to do.  Now that system resources are no longer in short supply, it makes no sense to try spend time compacting my code and storage, but I still do it!

What you do is far more worthwhile, albeit not necessarily quite as satisfying, and its why you need LAPACK and I ought to need it, but don't!

OVER AND OUT.
---
John

Re: Simply lapack

@Jeff
Thanks so much for the detailed instructions. The build went well:
====================================
...
...
...
Compiling .\SRC\zupmtr.f
Generating liblapack.a

* Complete *
====================================
So happy! :-)

Re: Simply lapack

@ Jeff:

Upon the first use of LAPACK, it appeared that file "dlamch.f" was missing - the same problem Carols had.

First, I created fresh folder with LAPACK source, copied "dlamch.f" from INSTALL to SRC folder and build the entire thing again.  Upon successful build, I've checked the "Makefile" and "dlamch.f" was not mentioned there. I tried to compile and run my program and got the same error message.

Second, I copied "dlamch.f" to my current project folder and added (right click "Add File(s)") it to my currently opened SF project tree. After that the compilation and launching went through without reported errors.

Jeff, is there a way to add "dlamch.f"  like the other LAPACK files, so it's there "forever" and I don't have to do this for each new program/project?
Thanks.

Re: Simply lapack

I've added dlamch.f and slamch.f to the LAPACK project at:

http://download.approximatrix.com/sfort … -3.5.0.prj

If you download and use the new project, it should fix the missing files.

Jeff Armstrong
Approximatrix, LLC

Re: Simply lapack

I have been trying to get LAPACK to work with SF 1.45 on my Windows 10 PC. I followed these steps:
1) Downloaded lapack version 3.5.0 as lapack-3.5.0.tgz from netlib.org site and unpacked/unzipped (using MacBook).
2) Copied resulting lapack-3.5.0 folder form MacBook to Windows 10 PC
3) Downloaded lapack-3.5.0.prz file using link in Jeff's post of 2014-12-20
4) Loaded lapack-3.5.0.prz project into SF, selected 64-bit compile option, then build now
Results:
- All of the many lapack and blas .f files compile as .o files and are placed into the build folder as expected
- The build process appears to complete, including the last step to build liblapack.a file, with no error messages or warnings
but... the liblapack.a file does not appear in the lapack-3.5.0 folder, or anywhere else on my PC.
Any ideas on what I'm doing wrong would be much appreciated. Thanks.

Re: Simply lapack

Update - LAPACK is working fine for me now with SF 1.45. I downloaded the latest lapack v. 3.7.0, copied all of the blas and lapack .f files into a folder on my desktop plus the two files dlamch.f and slamch.f, then compiled and linked from the dos command line as follows:
gfortran -O2 -c *.f
ar rcs liblapack.a *.o
This created the proper liblapack.a file

Re: Simply lapack

I'm glad to hear you have LAPACK working!  I'm not sure why the project file didn't work in your case.

Jeff Armstrong
Approximatrix, LLC

Re: Simply lapack

Good grief, so   m a n y   views of this topic!

Anyone know why?  I'm curious.
---
J.