How do I initialize two different blacs contexts?

I have a computer with processors nproc

and I would like to initialize two blacs, one of the sizes p x q = nprocs

and one of the sizes 1 x 1

.

Suppose MPI is allready initialized and routine search for good block sizes, the first grid is initialized with

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 one? Do I have to enter another mpi communicator first?

+3


source to share


1 answer


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 contexts, no need to initialize another MPI communicator and composes 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 to blacs_gridinit is an I / O argument that needs the global blacs context of all processes as input. It is returned to a new variable by calling blacs_get, the third argument.

In this case, I found a completely opposite intuitive fact: the context value seems to follow some kind of sum rule, so after initializing the 1x1 grid and again the 4x4 grid, the 4x4 grid values ​​for all processes do not match.

0


source







All Articles