Feeds:
Posts
Comments

Archive for the ‘Fortran’ Category

MinGW stands for Minimalist GNU for Windows.

MinGW is a native software port of the GNU Compiler Collection (GCC) and GNU Binutils for use in the development of native Microsoft Windows applications.

MinGW can be downloaded with Code::Blocks.

Or it can be downloaded via  soureforge.

* * *

Next add:     C:\MinGW\bin

to the PATH environment variable by opening the System control panel, going to the Advanced tab, and clicking the Environment Variables button.

* * *

C/C++ programs can then be compiled in command line as:

c:\(your folder)>g++ -o filename filename.cpp

This will generate an executable file called:  filename.exe

* * *

Fortran progams can be compiled as:

c:\(your folder)>gfortran -o filename filename.f

This will generate an executable file called:  filename.exe

* * *

MinGW also provides a Unix-like shell.

* * *

Tom Irvine

Read Full Post »

Here is a program that uses dgemm to multiply two matrices:  matrix_mult.cpp

The dgemm function is implemented using gsl blas.

It can be compiled under Cygwin as:

gcc -o matrix_mult_alt matrix_mult_alt.cpp -lgsl -lstdc++

And under Ubuntu as:

gcc -o matrix_mult_alt matrix_mult_alt.cpp -lgsl -lgslcblas -lstdc++

* * *

For benchmark comparison, here is a matrix multiplication program which uses pure pointer access without BLAS.    matrix_11.cpp

* * *

A Fortran program which uses the intrinsic function MATMUL is given at:  MATRIX_MULT.F

A Fortran program which uses DGEMM is:  MATRIX_MULT_D.F

The program was compiled using:

gfortran -o MATRIX_MULT_D MATRIX_MULT_D.F -lblas -llapack

As an aside, the following was used to determine memory leaks during the debugging process:

gfortran -g -o MATRIX_MULT_D MATRIX_MULT_D.F -lblas -llapack -Wall -fbounds-check -fmax-errors=1 -Werror

* * *

Here is a program  matrix_mult_cblas.cpp  which uses cblas_dgemm.

It is compiled in Cygwin via:

gcc -o matrix_mult_cblas matrix_mult_cblas.cpp c:/cygwin/lib/libblas.a c:/cygwin/lib/libcygwin.a c:/cygwin/home/tirvine/CBLAS/lib/cblas_LINUX.a -lstdc++

The paths should be modified according to your library installation.

Note that CBLAS can be installed in Cygwin using the instructions at:

https://vibrationdata.wordpress.com/2011/11/07/install-cblas-in-ubuntu/

* * *

Tom Irvine

Read Full Post »

The goal of this project is to solve a “very large” generalized eigenvalue problem in a “reasonable” amount of time using library functions. The mass and stiffness matrices may be either dense or sparse. Optimum routines are desired for each case.

Here is description of the libraries and packages

gcc - GNU Compiler Collection for C/C++

BLAS – Basic Linear Algebra Subprograms

CBLAS – C interface to the BLAS

LAPACK – Linear Algebra PACKage. LAPACK is a software library for numerical linear algebra including the generalized eigenvalue problem. It uses BLAS.

PETSc – Portable, Extensible Toolkit for Scientific Computation. PETSc is a suite of data structures and routines for the scalable (parallel) solution of scientific applications modeled by partial differential equations. It includes a large suite of parallel linear and nonlinear equation solvers that are easily used in application codes written in C, C++, Fortran and now Python.

SLEPc - a software library for the parallel computation of eigenvalues and eigenvectors of large, sparse matrices. It can be seen as a module of PETSc that provides solvers for different types of eigenproblems, including linear (standard and generalized) and quadratic, as well as the SVD.

Note that PETSc/SLEPc requires BLAS/LAPACK.

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

Installation Steps:

I have a PC with Ubuntu 11.10 running with the gnome-classic shell.

I have installed the following:

Code::Blocks with the gcc compiler from the Ubuntu Software Center

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

BLAS

Step 1: download

$ wget http://www.netlib.org/blas/blas.tgz

Step 2: extraction

$ tar zxf blas.tgz    this will create a directory BLAS

Step 3: compilation

$ cd BLAS

$ make all

If everything was correct in the previous step, your library is in the BLAS directory, called blas_LINUX.a

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

CBLAS

Installation instructions:

BLAS must be installed first.

Next,

wget http://www.netlib.org/blas/blast-forum/cblas.tgz

tar zxf cblas.tgz

Go to CBLAS folder.

Open Makefiles.in in a text editor.

Modify this line in Makefiles.in

BLLIB = (specify path)/BLAS/blas_LINUX.a

make all

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

LAPACK

Step 1: download

$ wget http://www.netlib.org/lapack/lapack.tgz

Step 2: extraction

$ tar zxf lapack.tgz        this will create a directory lapack.

Step 3: compilation

$ cd lapack-3.3.1

The configuration can be done in the make.inc.example file:

modify:  BLASLIB      = /directory/where/to/find/BLAS/blas$(PLAT).a

The LaPack library uses the BLAS library, so you need to tell where to find it. The result is a library lapack_LINUX.a: this can be copied in a place of your choice.

Save file as:  make.inc

$ sudo apt-get install cmake      (if not installed already)

$ cmake

$ make

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

BLAS/LAPACK

The following step may also be needed:
$ sudo apt-get install libblas-dev liblapack-dev

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

The C++ source code for the generalized eigenvalue program is given at:
gen_eigen.cpp    (right mouse click & save target or link)

The header files are:   dsygv.h     dsyev.h     cblas.h

The source code uses BLAS, CBLAS & LAPACK.

The following linker options are required:

-lgfortran
-lblas
-llapack

* * * * * * * * *

Here is another C++ version: gen_eig.cpp

The program can be compiled via:

gcc -o gen_eig gen_eig.cpp -lblas -llapack -lstdc++

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

Here is a pure Fortran program for the generalized eigenvalue problem:  geigen.f

The program can be compiled via:

$ gfortran -o geigen geigen.f -lblas -llapack

* * *

Matlab scripts are given at:

Matlab Linear Algebra Page

* * *

A future generalized eigenvalue problem code will use PETSC & SLEPc.  These packages can be downloaded via:

PETSc
sudo apt-get install petsc-dev

SLEPc
sudo apt-get install slepc3.1-dev

* * *

Python is well-suited for the generalized eigenvalue problem.  It has functions derived from LAPACK.  It also has functions for sparse systems using ARPACK.  Sample scripts are posted at:

Vibrationdata Python Wiki Generalized Eigenvalue

* * *

Tom Irvine

Read Full Post »

« Newer Posts

Follow

Get every new post delivered to your Inbox.

Join 172 other followers

%d bloggers like this: