I'm trying to set up a very simple 1 * 2 grid using the following code:
int nprow, npcol, myrow, mycol, myid;
char rowcol[1] = "R";
nprow = 1;
npcol = size / nprow;
if(npcol * nprow != size){
printf("Error");
MPI_Finalize();
exit(1);
}
Cblacs_pinfo(&myid, &size);
Cblacs_get(0, 0, &ictxt);
Cblacs_gridinit(&ictxt, rowcol, nprow, npcol);
Cblacs_pcoord(ictxt, myid, &myrow, &mycol);
printf("rank = %d, nprow = %d, npcol = %d, myrow = %d, mycol = %d\n", rank, nprow, npcol, myrow, mycol); }
The problem is that the Cblacs_pcoord
function seems to be changing nprow to 0 no matter what it is initailly set to and this, in turn, gives 0 for every myrow while the npcol and mycol variables are always correct for any number of processors used. I am very confused since this function shouldn't touch nprow but I've printed nprow after every line of code and it is the correct value until after that function is called.
If I'm missing any information that would help you answer my question please let me know and I will update accordingly.
Short answer: Use
Cblacs_gridinfo
instead ofCblacs_pcoord
.Long answer: Please give a complete, minimum example. I filled in a bunch of details to compile something.
Use
const char* rowcol = "R";
instead ofchar rowcol[1] = "R";
, which generates a compile error:Declaring rowcol as a 1-character array could cause stack corruption, since "R" is 2 characters, including the terminating null char.
I'm not sure what output you got that was wrong. Your code seems to work for me. But I still recommend using gridinfo instead of pcoord, because that's what ScaLAPACK does everywhere, and I think pcoord is broken for col-major grids.
Here's complete code.
Compile and run: