How to initialize two distinct blacs contexts?

♀尐吖头ヾ 提交于 2019-12-22 10:01:37

问题


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:


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.



来源:https://stackoverflow.com/questions/30735995/how-to-initialize-two-distinct-blacs-contexts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!