I am just learning to use ScaLapack. I wrote a test routine for calculating the eigenvalues and -vectors for a 20x20 matrix. However, even before
being able to test it, I ran into a problem of not being able to initialize the arrays required by the 'pdszevr_' routine. My code looks like this:
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#define TABSIZE 20
#define DLEN 9
int main (int argc, char *argv[]) {
int taskid,numtasks,myGrid;
int i,j;
double **dist;
Cblacs_pinfo(&taskid, &numtasks);
Cblacs_get(0, 0, &myGrid);
Cblacs_gridinit(&myGrid, "R", 1, numtasks);
printf ("MPI task %d has started...\n", taskid);
dist = (double **)malloc(TABSIZE*TABSIZE*sizeof(double)) ;
if (dist==NULL){ printf("error of memory allocation\n"); exit(0); }
for (i=0;i<TABSIZE;++i) {
dist[i]= (double *)malloc(TABSIZE*sizeof(double)) ;
if (dist==NULL){ printf("error of memory allocation\n"); exit(0); }
}//endfor
for (i=0;i<TABSIZE;++i) {
for (j=0;j<TABSIZE;++j) {
if (i==j) dist[i][j]=0;
else {
dist[i][j]=0.1*i+0.01*j;
}
}
}
if (taskid==0) {
for (i=0;i<TABSIZE;++i) {
printf("\n");
for (j=0;j<TABSIZE;++j) {
printf("%0.2f ",dist[i][j]);
}
}
printf("\n");
}
// PDSYEVR-variables, mostly disabled right now
char jobz='N';
char range='V';
char uplo='U';
int dist_length=TABSIZE;
double *result_eigval;
double **result_eigvec;
double vl=-10.0;
double vu=10.0;
int IL=1;
int IU=TABSIZE;
int N_eigval=TABSIZE;
int N_eigvec=TABSIZE;
int lwork=3;
int iwork=12*TABSIZE+2*N_eigvec;
double *work,*liwork;
int info;
int tag8=8,tag10=10;
int *desca;
int *descz;
int blocksize=TABSIZE/numtasks/2;
result_eigval = (double *)malloc(TABSIZE*sizeof(double)) ;
if (result_eigval==NULL){ printf("error of memory allocation\n"); exit(0); }
result_eigvec = (double **)malloc(TABSIZE*TABSIZE*sizeof(double)) ;
if (result_eigvec==NULL){ printf("error of memory allocation\n"); exit(0); }
for (i=0;i<TABSIZE;++i) {
result_eigvec[i]= (double *)malloc(TABSIZE*sizeof(double)) ;
if (result_eigvec==NULL){ printf("error of memory allocation\n"); exit(0); }
}
desca = (int*)malloc(DLEN*sizeof(int));
if (desca==NULL){ printf("error of memory allocation\n"); exit(0); }
descz = (int*)malloc(DLEN*sizeof(int));
if (descz==NULL){ printf("error of memory allocation\n"); exit(0); }
work = (double *)malloc((lwork)*sizeof(double)) ;
if (work ==NULL){ printf("error of memory allocation\n"); exit(0); }
liwork = (double *)malloc((iwork)*sizeof(double)) ;
if (liwork ==NULL){ printf("error of memory allocation\n"); exit(0); }
descinit_(desca,TABSIZE,TABSIZE,blocksize,blocksize,0,0,myGrid,2,info);
descinit_(descz,TABSIZE,TABSIZE,blocksize,blocksize,0,0,myGrid,2,info);
// the function pdsyevr_ is disabled right now
/*info = pdsyevr_(jobz,range,uplo,dist_length,dist,1, 1, desca,vl,vu,IL,IU,N_eigval,N_eigvec,result_eigval,result_eigvec,ONE,ONE,descz,work,
lwork,iwork,liwork,info);*/
for (i=0;i<TABSIZE;++i) {
free(dist[i]);
free(result_eigvec[i]);
}
free(liwork);
free(work);
free(result_eigval);
free(dist);
free(result_eigvec);
free(desca);
free(descz);
Cblacs_gridexit(myGrid);
Cblacs_exit(0);
}
The program compiles fine, but when running it with 'mpirun -np 4' I get a huge list of runtime errors:
MPI task 0 has started...
MyGrid:0
MPI task 1 has started...
MyGrid:0
MPI task 3 has started...
*** Process received signal ***
Signal: Segmentation fault (11)
Signal code: Address not mapped (1)
Failing at address: (nil)
[ 0] /lib/x86_64-linux-gnu/libpthread.so.0(+0x10340) [0x7f460b401340]
[ 1] pdstest() [0x402f60]
[ 2] pdstest() [0x40291e]
[ 3] pdstest() [0x401730]
[ 4] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f460b04dec
[ 5] pdstest() [0x401129]
*** End of error message ***
*** Process received signal ***
Signal: Segmentation fault (11)
Signal code: Address not mapped (1)
Failing at address: (nil)
[ 0] /lib/x86_64-linux-gnu/libpthread.so.0(+0x10340) [0x7f7804dbb340]
[ 1] pdstest() [0x402f60]
[ 2] pdstest() [0x40291e]
[ 3] pdstest() [0x401730]
[ 4] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f7804a07ec
[ 5] pdstest() [0x401129]
*** End of error message ***
*** Process received signal ***
Signal: Segmentation fault (11)
Signal code: Address not mapped (1)
Failing at address: (nil)
0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19
0.10 0.00 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.20 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29
0.20 0.21 0.00 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.30 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39
...
so the matrix prints out fine, but that's about it. By disabling even the descinit_ -command, I get an error free run,
but then again, the program isn't really doing anything in that case. So my (first) question is: How to correctly
initialize the arrays desca and descz?

