如何初始化两个不同的blacs上下文? [英] How to initialize two distinct blacs contexts?

查看:202
本文介绍了如何初始化两个不同的blacs上下文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台带有 nproc 处理器的计算机,我想初始化两个blacs网格,其中一个维< pxq = nprocs 和其中一个维 1 x 1



假设MPI已经初始化,块大小,第一个网格通过

 调用blacs_get(-1,0,self%context)
调用来初始化blacs_gridinit(self%context,'R',self%nprows,self%npcols)
调用blacs_gridinfo(self%context,self%nprows,self%npcols,self%myrow,self%mycol)

但是如何设置第二个?我必须先介绍另一个mpi通信器吗?

解决方案

作为回答和示例,我分享了这个实现:

 调用blacs_get(-1,0,self%context)
调用blacs_gridinit(self%context,'R',self%nprows ,self%npcols)
调用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)
调用blacs_gridinit(val,'R',1,1)
调用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)

调用blacs_get(-1,0,val2)
调用blacs_gridinit(val2,'R',2,2)
调用blacs_gridinfo(val2,self%npro ws,self%npcols,self%myrow,self%mycol)

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

这增加了三个blacs上下文,不需要初始化另一个MPI通信器,到四个内核的以下输出:

  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

所以,关键的一点是blacs_gridinit的第一个参数是一个输入/输出参数,需要所有进程的globale blacs上下文作为输入。它通过调用blacs_get,第三个参数在一个新变量中被接收。



在这种情况下,我发现非常直观的事实是,上下文的值似乎遵循某种总和规则,所以在初始化1x1网格,然后再一个4x4网格之后,4x4网格句柄的值在所有进程中都不相同。


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?

解决方案

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.

这篇关于如何初始化两个不同的blacs上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆