0

Befor finding an answer for the quesion I asked before, I wrote very simple code for very sime mesh(there are just two triangles) as below to call C function in fortran. For the simplicity of code. Neither interface module here nor iso_c_binding(as possible as) isn't used here. It is very similar to this post, There is another error.

program METIS_NoInterface

  implicit none

  integer :: ne, nn
  integer, dimension(:), allocatable      :: eptr, eind
  integer, pointer                        :: vwgt=>null(), vsize=>null()
  integer                                 :: nparts
  real, pointer                           :: tpwgts=>null()
  integer, dimension(0:39)                :: opts
  integer                                 :: objval
  integer, dimension(:), allocatable      :: epart, npart

  ! Input  => 2 tri: too small mesh
  !ne = 2
  !nn = 4
  !nparts = 2
  !allocate(eptr(0:2), eind(0:5))
  !eptr=[0,    3,     4]
  !eind=[0,1,3,1,2,3]

  ! Output
  !allocate(epart(0:1), npart(0:4))

  ! Input  => 4 quad : reasonable result
  ne = 4  
  nn = 9
  nparts = 2
  allocate(eptr(0:ne), eind(0:15))
  eptr=[0,4,8,12,16]
  eind=[0,1,8,7,1,2,3,8,3,4,5,8,5,6,7,8]

  ! Output
  allocate(epart(0:ne-1), npart(0:nn-1))

  ! METIS function call
  call METIS_SetDefaultOptions(opts)
  !call METIS_PartMeshNodal(ne,ne,eptr,eind,vwgt,vsize,nparts,tpwgts,&  !<=syntax error
   call METIS_PartMeshNodal(ne,nn,eptr,eind,vwgt,vsize,nparts,tpwgts,&
                                opts,objval,epart,npart) 

  ! Result print
  write(*,*) epart
  write(*,*) ''
  write(*,*) npart
  write(*,*) ''
end program

It gives access violation error because of eind. It runs anyway if c_null_ptr are passed instead of eind. The size of array eind and number of elements are coincident. How can it be fixed? => resolved. Thank you!

The problem I had was systax error on calling METIS_PartMeshNodal, the 2nd argument was ne which is the same the 1st argument ne. It should have been nn.
Solution was to replace the 2nd argument to nn. Above code can be compiled and executed.

NOTE: Too small mesh may not have reasonable solution due to METIS' scheme.
Please refer another post in order to use interface module.

Community
  • 1
  • 1
dave
  • 33
  • 1
  • 7
  • Should the second argument to METIS_PartMeshNodal be nn rather than ne? Also WHY have you missed out the iso_c_binding stuff which is there specifically to help with this kind of thing? "Simpler" is NOT the same as "easier"! – Ian Bush Feb 07 '13 at 09:20
  • Are you sure, you are using the correct values for `ne` and `nn`? Especially, the arrays `eptr` and `eind` have the size **3** and **6** but none of your scalar variables you pass to the function contains such values. – Bálint Aradi Feb 07 '13 at 11:43
  • I am unable to reproduce your access violation with METIS 5.0.2 and gfortran 4.7, neither with this code nor with the interface block from your other question. I get `epart` = `[0, 0]` and `npart` = `[0, 0, 1, 1, 0]` (that is, with `nn` passed as the second argument). – sigma Feb 07 '13 at 12:32
  • Thank you all for kind replies. After fixing syntax error, I got epart=[0,0], npart=[0,0,1,1,-1163005939](by ivf 2011 with vs2008). The last element is weired but I received a responce from the Univ. of Minnesota that too small mesh may yield wrong result. Acceess violation seems to be caused by syntax error. I got reasonable result for a 2x2 quad mesh. And before this post I've failed to run the code with iso_c_binding but I'll post the result as soon as possible. – dave Feb 07 '13 at 13:29
  • Thank for commenters, I completed the program which calls METIS_PartMeshNodal function from fortran using interface module, iso_c_binding. If someone need an example, please mail me(dokeun98@gmail.com) – dave Feb 07 '13 at 15:17
  • Why not edit one of your questions to show the exact problems you had, and answer it yourself with the steps that resolved them? That way it should be abundantly clear to any future readers of your question. – sigma Feb 07 '13 at 16:56
  • @sigma Thank you for your adivce and I edited it. Would you please run the code with option(7)=1 for Fortran-style numbering? I got the same result regardless of the option. I wonder if my code is faultless. – dave Feb 07 '13 at 18:13
  • I actually meant to leave the non-working case in the question, and the steps towards the solution in an answer below. You can then accept your own answer, so that the question will not remain marked as open. Or remove the question if you don't think it would be helpful to keep it. P.S.: I also get the same output with or without `opts(7)=1`. I would still advise the use of an interface block, which should warn you that the default real `tpwgts` does not match `c_double`. – sigma Feb 11 '13 at 13:52

0 Answers0