Page 1 of 1

Fortran wrapper for sys2blacs_handle

PostPosted: Fri Jun 06, 2008 10:20 am
by salvadorvt
Dear forum,
I am trying to make a translation between mpi communicators and blacs
contexts within a FORTRAN code. I wonder if there is a wrapper for performing this task or if it is available already, I would like
to know the needed syntax. This routine is written in c and reads an mpi comm returning an integer blacs context.

I know the error in the run comes because blacs is not getting a proper context. Your help will be greatly appreciated.

Thank you in advance
-Salvador Barraza-Lopez

PS: Sample code and output follows.


! http://www.linux-mag.com/id/1359
! http://www.linux-mag.com/id/1412
! June 2008. Salvador Barraza-Lopez

include 'mpif.h'

integer iam, nprocs, nprow, npcol, ncontexts

integer MPI_WORLD_COMM, work_comm, ierr
integer work_iam, work_nprocs, color
integer context

nprow=2
npcol=nprow


!call mpi_init(ierr)

!
call blacs_pinfo(iam,nprocs)

!call mpi_comm_rank(MPI_COMM_WORLD, iam,ierr)
!call mpi_comm_size(MPI_COMM_WORLD,nprocs,ierr)

write(*,*) 'Fine here, I am', iam, 'out of ', nprocs, 'total procs'

ncontexts=int(nprocs/(nprow*npcol))

!we defined colors so that consecutive processors belong to the same communicator:
color=floor(real((iam/(nprow*npcol))))+1


call MPI_Comm_split(MPI_COMM_WORLD, color, iam, work_comm,ierr)

write(*,*) 'Splitting has taken place'

call MPI_Comm_rank(work_comm, work_iam,ierr)
call MPI_Comm_size(work_comm, work_nprocs,ierr)
write(*,*) iam, ': I am', work_iam, 'of ', work_nprocs, 'in context ',color

! Now we are ready to set the different processor grids:
!HERE IS THE PROBLEM: HOW TO GET A PROPER CONTEXT FROM !SYS2BLACS_HANDLE IN A FORTRAN CALL!
context = sys2blacs_handle(work_comm,ierr)
call blacs_gridinit( context, "Row", npcol, nprow ,ierr)

call MPI_Comm_free(comm_work,ierr)

call blacs_exit(0)

! call mpi_finalize(ierr)

end


mpirun -np 4 ./a.out
Fine here, I am 3 out of 4 total procs
Fine here, I am 0 out of 4 total procs
Fine here, I am 1 out of 4 total procs
Fine here, I am 2 out of 4 total procs
Splitting has taken place
Splitting has taken place
Splitting has taken place
Splitting has taken place
0 : I am 0 of 4 in context 1
1 : I am 1 of 4 in context 1
2 : I am 2 of 4 in context 1
3 : I am 3 of 4 in context 1
MPI Error, rank:0, function:MPI_GROUP_INCL, Invalid argument
MPI Error, rank:1, function:MPI_GROUP_INCL, Invalid argument
MPI Error, rank:2, function:MPI_GROUP_INCL, Invalid argument
MPI Error, rank:3, function:MPI_GROUP_INCL, Invalid argument
Killed