1

Hi can any one provide me an example Makefile for calling ScaLAPACK from C++, I am having difficulties.

I have the newest version compiled correctly with all the tests passed. I have it compiled with GCC and OpenMPI on Fedora, and I have also tried using the pre-built binaries from the repository with no luck.

Matthias Beaupère
  • 1,731
  • 2
  • 17
  • 44
pyCthon
  • 11,746
  • 20
  • 73
  • 135

1 Answers1

3

I used the following declarations for ScaLAPACK procedures:

extern "C" void pdgesvd_(char *jobu, char *jobvt, int *M, int *N, double *A, int *ia, int *ja, int *desca, double *s, double *u, int *iu, int *ju,
            int *descu, double *vt, int *ivt, int *jvt, int *descvt, double *work, int *lwork, int *info);

extern "C" void pdgemv_(char *t, int *M, int *N, double *alpha, double *A, int *ia, int *ja, int *desca, double *X, int *ix, int *jx,int *descx,
            int *incx, double *beta, double *Y, int *iy, int *jy, int *descy, int *incy);


extern "C" void pdgemm_(char *transa, char *transb, int *M, int *N, int *K, double *alpha, double *A, int *ia, int *ja, int *desca, double *B,
            int *ib, int *jb, int *descb, double *beta, double *C, int *ic, int *jc, int *descc);

BLACS procedures are declared in the same way:

extern "C" void blacs_get_(/*in*/int *icontxt, /*in*/int *what, /*out*/int *val); 

I append the "_" character to procedure names, because BLAS and ScaLAPACK were built with -DAdd_ compiler option. This may be different for your system. If so, try objdump -t on libscalapack.a and other static library files to determine actual procedure names.

Your program with ScaLAPACK calls may be compiled with something like this:

mpicxx -o your_binary_name -O2 your_source.cpp -lscalapack -lblacs -lcblacs -lblacs -llapack -lblas -lgfortran

Note that the order of static libraries in g++ invocation line (-lblacs -lcblacs -lblacs -llapack -lblas -lgfortran) is important! Also check the existance of all these static library files (libblas.a, libcblacs.a and so on) in the library directories. Don't forget about Fortran package (for -lgfortran).

Sergey
  • 7,985
  • 4
  • 48
  • 80
  • i posted how i compiled a C example, and I already have the extern stuff in there for the .cpp files, i tried many examples from the web – pyCthon Sep 26 '12 at 18:55
  • 1) Do you use a package manager? I use OpenSUSE, and in its repositories there are two packages: openmpi and openmpi-devel. The first package contains binaries, such as mpirun, mpicxx, and the second contains static libraries. IMO, it's rather strange division for such thing as MPI. 2) More probable assumption: you get errors like `undefined reference to mpi_bcast_`, but if I compile any MPI code with bare g++, I get undefined references to functions like MPI_Bcast. Logically, that your linker can't find lowercase symbols in libmpi.a. – Sergey Sep 26 '12 at 19:42
  • Possible solution for the second assumption from my previous comment: remove repository-provided ScaLAPACK, download sources from netlib.org and compile your own version with proper compiler flags. In older ScaLAPACK versions setting proper flags could be tricky, but modern ScaLAPACK from netlib has an automated compilation system (with cmake or smth like that), which can be appropriate for you. – Sergey Sep 26 '12 at 19:45
  • Pay attention at such Fortran flags as -lowercase or -fcase-lower when compiling scalapack and underlying libraries. These flags may be responsible for that undefined references. – Sergey Sep 26 '12 at 19:51