Compiling Programs Containing LAPACK Routines

At the moment we have access to two different kinds of machines which have LAPACK installed, DEC alpha running OSF and IBM RS 6000 running AIX.


DEC alpha running OSF
LAPACK is implemented as part of DEC's extended math library (type man dxml to find out what else is there) which makes it easy to use.
Compiling a Fortran program
All you have to do is link in the extended math library when you compile your program. This should be in your path, so

f77 my_program.f -ldxml

(plus any other compiler options you might need) should do the job.

Compiling a C program
In addition to linking in the extended math library you have to make two changes in your program.
Due to difference in how arrays are stored in memory, you have to transform a matrix before you pass it to a LAPACK routine.
for (i=0; i<size; i++)
{
for(j=0; j<size; j++) NEW[j+size*i]=OLD[j][i];
}

Notice that if the result of your computation is a matrix, then you have transform this result again.

Because of a difference in how names of subroutines are handled internally, you have to add an underscore (_) to all the routine names. Instead of,

sgesv(&c1, &c2, NEW, &c1, pivot, b, &c1, &ok);

it has to be,

sgesv_(&c1, &c2, NEW, &c1, pivot, b, &c1, &ok);

After that you can just say,

cc my_program.c -ldxml

(plus any other compiler options you might need) to compile your program.


IBM RS 6000 running AIX

The AIX operating system contains a library of basic linear algebra routines (blas) which LAPACK is based on but you have install LAPACK yourself (or find a nice system administrator to do it for you).

Compiling a Fortran program
All you have to do is link in the LAPACK and the blas library when you compile your program. If these libraries reside in the standard directory /usr/lib/ and not e.g. in you home directory, then

f77 my_program.f -llapack -lblas

(plus any other compiler options you might need) should do the job.

Compiling a C program
Due to difference in how arrays are stored in memory, you have to transform a matrix before you pass it to a LAPACK routine.
for (i=0; i<size; i++)
{
for(j=0; j<size; j++) NEW[j+size*i]=OLD[j][i];
}

Notice that if the result of your computation is a matrix, then you have transform this result again.

After that you can just say,

cc my_program.c -llapack -lblas -lm -lxlf

(plus any other compiler options you might need) to compile your program.


Back to the Fortran programs
Back to the C programs