4

I have a computer with nproc processors and I'd like to initialize two blacs grids, one of the dimension p x q = nprocs and one of the dimension 1 x 1.

Assume MPI allready initialized and a routine finding good block sizes, the first grid is initialized via

call blacs_get(   -1, 0, self%context  )
call blacs_gridinit( self%context, 'R', self%nprows, self%npcols )
call blacs_gridinfo( self%context, self%nprows, self%npcols, self%myrow, self%mycol )

But how do I set up the second? Do I have to introduce another mpi communicator first?

1 Answer 1

0

As an answer and example, I share this implementation:

    call blacs_get(   -1, 0, self%context  )
    call blacs_gridinit( self%context, 'R', self%nprows, self%npcols )
    call blacs_gridinfo( self%context, self%nprows, self%npcols, self%myrow, self%mycol )

    print*, "A ", self%context, self%nprows, self%npcols, self%myrow, self%mycol

    call sleep(1)

    call blacs_get(   -1, 0, val  )
    call blacs_gridinit( val, 'R', 1, 1 )
    call blacs_gridinfo( val, self%nprows, self%npcols, self%myrow, self%mycol )

    call sleep(1)

    print*, "B ", val, self%nprows, self%npcols, self%myrow, self%mycol

    call sleep(1)

    call blacs_get(   -1, 0, val2  )
    call blacs_gridinit( val2, 'R', 2, 2 )
    call blacs_gridinfo( val2, self%nprows, self%npcols, self%myrow, self%mycol )

    call sleep(1)
    print*, "C ", val2, self%nprows, self%npcols, self%myrow, self%mycol

Which adds three blacs context, no need to initialize another MPI communicator, and amounts to the following output on four cores:

 A            0           2           2           1           1
 A            0           2           2           0           0
 A            0           2           2           1           0
 A            0           2           2           0           1




 B           -1          -1          -1          -1          -1
 B           -1          -1          -1          -1          -1
 B           -1          -1          -1          -1          -1
 B            1           1           1           0           0




 C            1           2           2           1           0
 C            1           2           2           1           1
 C            1           2           2           0           1
 C            2           2           2           0           0

So, the crucial point is that the first argument of blacs_gridinit is an input/output argument, needing the globale blacs context of all processes as an input. It is recived in a new variable by the call to blacs_get, third argument.

What I found quite counter intuitive in this case is the fact, that the value of the context seems to follow some kind of sum rule, so after initializing the 1x1 grid and then again a 4x4 grid, the values of the 4x4 grid handle are not the same on all processes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.