Hi,
Julien Langou wrote a code at the following url: http://icl.cs.utk.edu/lapack-forum/viewtopic.php?t=136
I modified that code in order to test the Cblacs_pcoord() routine.
And it became:
###################################################################
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mpi.h"
#include <sys/time.h>
static int max( int a, int b ){
if (a>b) return(a); else return(b);
}
extern void Cblacs_pinfo( int* mypnum, int* nprocs);
extern void Cblacs_get( int context, int request, int* value);
extern void Cblacs_gridmap(int *ictxt,int *pmap,int ldpmap,int nprow,int npcol);
extern void Cblacs_pcoord(int ictxt,int pnum,int *prow,int *pcol);
extern void Cblacs_gridexit( int context);
extern void Cblacs_exit( int error_code);
int main(int argc, char **argv) {
int iam, nprocs;
int myrank_mpi, nprocs_mpi;
int ictxt1, nprow1, npcol1, myrow1, mycol1;
int ictxt2, nprow2, npcol2, myrow2, mycol2;
int np1, nq1, n1, nb1, nrhs1;
int np2, nq2, n2, nb2, nrhs2;
int i, j, k, info, itemp, seed;
int descA[9], descB[9];
double *A, *Acpy, *B, *X, *R, eps, *work;
double AnormF, XnormF, RnormF, BnormF, residF;
int *ippiv;
int izero=0,ione=1;
double mone=(-1.0e0),pone=(1.0e0);
int *usermap1, *usermap2, ldumap1, ldumap2;
/**/
double MPIt1, MPIt2, MPIelapsed;
/**/
MPI_Init( &argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank_mpi);
MPI_Comm_size(MPI_COMM_WORLD, &nprocs_mpi);
/**/
Cblacs_pinfo( &iam, &nprocs ) ;
Cblacs_get( -1, 0, &ictxt1 );
Cblacs_get( -1, 0, &ictxt2 );
/**/
n1 = 500; nrhs1 = 1; nprow1 = 1; npcol1 = 2; nb1 = 64; ldumap1 = nprow1;
n2 = 250; nrhs2 = 2; nprow2 = 2; npcol2 = 1; nb2 = 50; ldumap2 = nprow2;
/**/
usermap1 = (int *)calloc(ldumap1*npcol1,sizeof(int)) ;
usermap2 = (int *)calloc(ldumap2*npcol2,sizeof(int)) ;
/**/
usermap1[0] = 0; usermap1[1] = 2;
usermap2[0] = 1; usermap2[1] = 3;
/**/
if ((nprow1*npcol1)+(nprow2*npcol2)>nprocs_mpi){
if (myrank_mpi==0)
printf(" **** ERROR : I want to use %d processes and only have %d\n",(nprow1*npcol1)+(nprow2*npcol2),nprocs_mpi);
MPI_Finalize(); exit(1);
}
/**/
Cblacs_gridmap ( &ictxt1, usermap1, ldumap1, nprow1, npcol1 );
free(usermap1);
Cblacs_gridmap ( &ictxt2, usermap2, ldumap2, nprow2, npcol2 );
free(usermap2);
/**/
if(ictxt1>=0){
Cblacs_pcoord(ictxt1,iam,&myrow1,&mycol1);
printf("I am %d, my coordinates are (%d,%d) on grid_1\n\n",iam,myrow1,mycol1);
}
if(ictxt2>=0){
Cblacs_pcoord(ictxt2,iam,&myrow2,&mycol2);
printf("I am %d, my coordinates are (%d,%d) on grid_2\n\n",iam,myrow2,mycol2);
}
Cblacs_exit(0);
exit(0);
}
####################################################################
the compilation is successful using:
mpif77 -o pcoord pcoord.c blacsF77init_MPI-LINUX-0.a blacs_MPI-LINUX-0.a blacsF77init_MPI-LINUX-0.a
When I run the executable, I get the following:
##################################################################
[root@localhost /root]#mpirun -np 4 ./pcoord
I am 0, my coordinates are (0,0) on grid_1
I am 2, my coordinates are (-1,-1) on grid_1
I am 1, my coordinates are (1,0) on grid_2
I am 3, my coordinates are (-1,-1) on grid_2
[root@localhost /root]#
###################################################################
only the coordinates of process 0 seems to be correct.
for example, the coordinates of process 1 should be (0,0) on grid_2, no?
Why the Cblacs_pcoord() routine doesn't return the correct coordinates?
Have you any idea ?
Thanks in advance,
alex

