首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >细分Scalapack网格

细分Scalapack网格
EN

Stack Overflow用户
提问于 2017-11-02 09:22:07
回答 2查看 307关注 0票数 2

我试图使用Scalapack计算许多大型矩阵的特征谱,而不是在所有32个过程中分配每个矩阵。我宁愿将每个矩阵分布在4个过程中,并行计算8个矩阵。我知道如何使用MPI_Comm_split细分MPI网格,但我似乎没有使用定制的通信器。相反,它似乎使用了植根于PVM的BLACS网格。

如何在Scalapack中实现这个细分?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-11-02 10:04:38

这是由BLACS和网格设置完成的。

参考函数是

  • GRIDINIT( ICONTXT,ORDER,NPROW,NPCOL )
  • GRIDMAP( ICONTXT、USERMAP、LDUMAP、NPROW、NPCOL )

这些例程的文档声明:

这些例程接受可用的进程,并将它们分配或映射到BLACS进程网格中。 每个BLACS网格包含在上下文中(它自己的消息传递空间),因此它不会干扰在其他网格/上下文中发生的分布式操作。 可以重复调用这些网格创建例程,以便定义其他上下文/网格。

这意味着您可以创建8个不同的网格,并将每个ICONTXT传递给每个矩阵的scalapack例程。

他们两个都得到了一个输入/输出参数

科恩特 (输入/输出)整数 在输入时,表示用于创建BLACS上下文的系统上下文的整数句柄。用户可以通过对BLACS_GET的调用获得默认系统上下文。在输出时,创建的BLACS上下文的整数句柄。

您可以以相同的方式递归地使用这些上下文。

票数 1
EN

Stack Overflow用户

发布于 2017-11-02 15:59:52

我实现了@ztik建议,这就是我想出的结果。它似乎奏效了:

代码语言:javascript
复制
program main
    use mpi
    implicit none
    integer              :: ierr, me, nProcs, color, i,j,k, my_comm, dims(2), global_contxt
    integer              :: cnt, n_colors, map(2,2)
    integer, allocatable :: contxts(:)
    integer, parameter   :: group_size = 4

    call MPI_Init(ierr)

    call MPI_Comm_size(MPI_COMM_WORLD, nProcs, ierr)
    call MPI_Comm_rank(MPI_COMM_WORLD, me, ierr)

    color = get_color(group_size)
    n_colors =  nProcs / group_size
    allocate(contxts(n_colors))

    dims = calc_2d_dim(group_size)

    call BLACS_GET(0, 0, global_contxt)
    if(me == 0) write (*,*) global_contxt
    contxts = global_contxt

    do k = 1,n_colors 
        ! shift for each context
        cnt = group_size * (k-1)
        if(me==0) write (*,*) "##############", cnt

        ! create map
        do i=1,2
            do j=1,2
                map(i,j) = cnt
                cnt = cnt + 1
            enddo
        enddo

        call BLACS_GRIDMAP(contxts(k), map, 2, 2, 2)
        do i = 0,nProcs
            if(i == me) then
                write (*,*) me, contxts(k)
            endif
            call MPI_Barrier(MPI_COMM_WORLD, ierr)
        enddo
    enddo

    call MPI_Finalize(ierr)
contains
    function get_color(group_size) result(color)
        implicit none
        integer, intent(in)     :: group_size
        integer                 :: me, nProcs, color, ierr, i, cnt

        call MPI_Comm_size(MPI_COMM_WORLD, nProcs, ierr)
        call MPI_Comm_rank(MPI_COMM_WORLD, me, ierr)

        if(mod(nProcs, group_size) /= 0) then
            write (*,*) "Nprocs not divisable by group_size", mod(nProcs, group_size)
            call MPI_Abort(MPI_COMM_WORLD, 0, ierr)
        endif

        color = 0
        do i = 1,me
            if(mod(i, group_size) == 0) then
                color = color + 1
            endif
        enddo
    end function get_color

    function calc_2d_dim(sz) result(dim)
        implicit none
        integer, intent(in)    :: sz
        integer                :: dim(2), cand

        cand = nint(sqrt(real(sz)))

        do while(mod(sz, cand) /= 0)
            cand = cand - 1
        enddo
        dim(1) = sz/cand
        dim(2) = cand
    end function calc_2d_dim

end program main
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47071622

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档