首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从FORTRAN调用METIS时出现分段错误

从FORTRAN调用METIS时出现分段错误
EN

Stack Overflow用户
提问于 2018-08-20 00:49:21
回答 1查看 284关注 0票数 0

我正在开发一个Fortran 90程序,并将其与METIS库链接起来。我使用的是GNU Fortran 4.8.5和METIS 5.1.0。我用以下命令编译Fortran程序:

代码语言:javascript
复制
-fdefault-real-8 -fdefault-integer-8

选项,在构建METIS时,我指定了:

代码语言:javascript
复制
#define IDXTYPEWIDTH 64 

代码语言:javascript
复制
#define REALTYPEWIDTH 64 

因此,整数和实数的长度都应该匹配。当我编译并运行以下程序时:

代码语言:javascript
复制
program Test_Metis
implicit none
integer              :: nvtxs,          &  ! number of vertices
                        ncons,          &  ! number of connections          
                        nparts = 2         ! requested number of partitions
integer, pointer     :: vwgt  =>null(), &  ! weights of the vertices
                        vsize =>null(), &  ! size of the vertices
                        adjwgt=>null(), &  ! weights of the edges
                        mopts =>null(), &  ! array of options
                        objval=>null()     ! stores edgecut or comm. volume
real, pointer        :: tpwgts=>null(), &  ! desired weight for each partition
                        ubvec =>null()     ! 
integer, allocatable :: xadj  (:),      &  ! variabes for ...
                        adjncy(:),      &  ! ... compressed row storage
                        part  (:)          ! partition of the grid

nvtxs = 15
ncons = 22
allocate(xadj  (nvtxs+1))
allocate(adjncy(ncons*2))
allocate(part  (nvtxs))

xadj = (/ 0,  2,  5,  8, 11, 13, 16, 20,  &
         24, 28, 31, 33, 36, 39, 42, 44/)

adjncy=(/ 1,  5,  0,  2,  6,  1,  3,  7,  2,  4,  8,  &
          3,  9,  0,  6, 10,  1,  5,  7, 11,  2,  6,  &
          8, 12,  3,  7,  9, 13,  4,  8, 14,  5, 11,  &
          6, 10, 12,  7, 11, 13,  8, 12, 14,  9, 13/)

call METIS_PartGraphRecursive(nvtxs,     &  ! (in), int
                              ncons,     &  ! (in), int
                              xadj,      &  ! (in), int(:)
                              adjncy,    &  ! (in), int(:)
                              vwgt,      &  ! (in), int(:)
                              vsize,     &  ! (in), int(:)
                              adjwgt,    &  ! (in), int(:)
                              nparts,    &  ! (in), int(:)
                              tpwgts,    &  ! (in), real(:)
                              ubvec,     &  ! (in), real(:)
                              mopts,     &  ! (in), int(:)
                              objval,    &  ! (out) int(:)
                              part)         ! (out) int(:)
end program

我得到了一个分段错误。(我从METIS手册中获取了邻接关系,这应该是非常基础的。)

有人能帮我解决这个问题吗?

EN

回答 1

Stack Overflow用户

发布于 2018-08-22 00:09:01

这是从Fortran调用METIS所需的最低要求:

代码语言:javascript
复制
program Test_Metis                                                              
use iso_c_binding                                                               
implicit none                                                                   
integer              :: nvtxs  = 15,       &  ! number of vertices              
                        nedgs  = 22,       &  ! number of edges                 
                        ncons  =  1,       &  ! number of constraints           
                        nparts =  2,       &  ! requested number of partitions  
                        objval,            &  ! return value from METIS call    
                        mopts(41)             ! array of options                
type(c_ptr)          :: vwgt  =c_null_ptr, &  ! weights of the vertices         
                        vsize =c_null_ptr, &  ! size of the vertices            
                        adjwgt=c_null_ptr     ! weights of the edges            
real                 :: ubvec                 !                                 
integer, allocatable :: xadj  (:),         &  ! variabes for ...                
                        adjncy(:),         &  ! ... compressed row storage         
                        part  (:)             ! partition of the grid           
real, allocatable    :: tpwgts(:)             ! desired weight for each partition

allocate(xadj  (nvtxs+1))                                                       
allocate(adjncy(nedgs*2))                                                       
allocate(part  (nvtxs))                                                         
allocate(tpwgts(nparts))                                                        

xadj = (/ 0,  2,  5,  8, 11, 13, 16, 20,  &                                     
         24, 28, 31, 33, 36, 39, 42, 44/)                                       
adjncy=(/ 1,  5,  0,  2,  6,  1,  3,  7,  2,  4,  8,  &                         
          3,  9,  0,  6, 10,  1,  5,  7, 11,  2,  6,  &                         
          8, 12,  3,  7,  9, 13,  4,  8, 14,  5, 11,  &                         
          6, 10, 12,  7, 11, 13,  8, 12, 14,  9, 13/)                           

tpwgts(:) =  1.0 / real(nparts)  ! all parts weigh the same                     
ubvec     =  1.001               ! this would be default by METIS anyway        
mopts(:)  = -1                   ! -1 is default value for all options          

call METIS_PartGraphRecursive(nvtxs,     &  ! (in), int                         
                              ncons,     &  ! (in), int                         
                              xadj,      &  ! (in), int(:)                      
                              adjncy,    &  ! (in), int(:)                      
                              vwgt,      &  ! (in), int(:)                      
                              vsize,     &  ! (in), int(:)                      
                              adjwgt,    &  ! (in), int(:)                      
                              nparts,    &  ! (in), int(:)                      
                              tpwgts,    &  ! (in), real(:)                     
                              ubvec,     &  ! (in), real(:)                     
                              mopts,     &  ! (in), int(:)                      
                              objval,    &  ! (out) int(:)                      
                              part)         ! (out) int(:)                      
end program                                                                     
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51919850

复制
相关文章

相似问题

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