首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Metis API通过Fortran

Metis API通过Fortran
EN

Stack Overflow用户
提问于 2013-06-17 19:21:38
回答 2查看 717关注 0票数 1

我试图通过Fortran使用METIS对一个网格进行分区,我使用VisualStudio10.0 X64在X64 Windows 7系统上构建了这个库文件,我的程序如下:

代码语言:javascript
复制
module metis_vars

     use iso_c_binding

    ! Variables
    integer                                        :: ia, ic
    integer(kind=c_int)                            :: ne, nn
    integer(kind=c_int)                            :: ncommon, objval
    integer(kind=c_int)                            :: nparts
    integer(kind=c_int), allocatable, dimension(:) :: eptr, eind
    integer(kind=c_int), allocatable, dimension(:) :: epart, npart
    type(c_ptr)                                    :: vwgt, vsize, tpwgts  
    integer                                        :: opts(0:40)

    interface

        subroutine METIS_PartMeshDual(ne,nn,eptr,eind,vwgt,vsize,ncommon,nparts,tpwgts,opts,objval,epart,npart) bind(C, name="METIS_PartMeshDual")

            ! use binding module
            use iso_c_binding
            ! declare variables with C++ types semantics
            integer(kind=c_int)               :: ne, nn, ncommon, objval
            integer(kind=c_int), dimension(*) :: eptr, eind
            integer(kind=c_int), dimension(*) :: epart, npart
            type(c_ptr), value                :: vwgt, vsize, tpwgts 
            integer(kind=c_int)               :: opts(0:40)

        end subroutine METIS_PartMeshDual

    end interface

end module

program METIS_PART_1

    use iso_c_binding
    use metis_vars

    implicit none

    open(unit=1, file='metis_test.mesh')

    read(1,*), ne

    nn = ne * 8

    allocate( eptr(ne), eind(8*ne) )
    allocate( epart(ne), npart(nn) )

    do ic=1,ne

        ia = (ic-1) * 8 + 1

        read(1,*), eind(ia:ia+7)

        eptr(ic) = ia

    enddo

    nparts = 4
    ncommon = 2

    vwgt   = c_null_ptr
    vsize  = c_null_ptr
    tpwgts = c_null_ptr
    opts(0)   = 1
    opts(7)   = 1

    call METIS_PartMeshDual(ne,nn,eptr,eind,vwgt,vsize,ncommon,nparts,tpwgts,opts,objval,epart,npart)

end program METIS_PART_1

我修改了所有输入数组,它们都是正确的(我已经成功地使用EXE划分了这个网格),但是,当我使用API时,我得到了以下错误:

使用的当前内存:祖字节使用的最大内存: zu字节*内存分配失败的CreateGraphDual: nind。请求的大小: zu字节

我不知道出了什么问题,也不知道如何调试

EN

回答 2

Stack Overflow用户

发布于 2013-07-11 15:41:27

最后,我发现eptr的分配大小是(nc),但它应该是(nc+1),也就是elements+1的数量。

票数 1
EN

Stack Overflow用户

发布于 2018-05-07 11:23:19

通过Metis的源文件(5.1.0版)快速查看grep就会发现这个问题:

代码语言:javascript
复制
    void CreateGraphDual(idx_t ne, idx_t nn, idx_t *eptr, idx_t *eind, idx_t ncommon, 
              idx_t **r_xadj, idx_t **r_adjncy)
    {
      ...
      idx_t *nptr, *nind;
      ...

      /* construct the node-element list first */
      nptr = ismalloc(nn+1, 0, "CreateGraphDual: nptr");
      nind = imalloc(eptr[ne], "CreateGraphDual: nind");
      ...

暗示eptr数组可能有问题(正如您已经知道的那样)。

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

https://stackoverflow.com/questions/17155169

复制
相关文章

相似问题

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