CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

using METIS functions in fortran

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 27, 2013, 06:50
Default using METIS functions in fortran
  #1
Member
 
Dokeun, Hwang
Join Date: Apr 2010
Location: Korea, Republic of
Posts: 98
Rep Power: 16
dokeun is on a distinguished road
Hello
I'm trying to use METIS in a fortran code with intel fortran. but there's not enough materials to refer. A file I got from building the original file with cmake was metis.lib.
Including this file made some error like below
Linking...
1>MSVCRT.lib(MSVCR90.dll) : error LNK2005: _printf already defined in LIBCMTD.lib(printf.obj)
From the METIS manual, calling METIS API in fortran is possible but I have no idea with it. It's a frustrating moment..
Would someone please give me an instruction or sample?
Thank you in advance.
dokeun is offline   Reply With Quote

Old   January 28, 2013, 00:15
Default
  #2
Senior Member
 
cdegroot's Avatar
 
Chris DeGroot
Join Date: Nov 2011
Location: Canada
Posts: 414
Rep Power: 17
cdegroot is on a distinguished road
I use METIS with Fortran and the file that I need to include is libmetis.a. Did this file build for you?
cdegroot is offline   Reply With Quote

Old   January 28, 2013, 21:00
Default
  #3
Member
 
Dokeun, Hwang
Join Date: Apr 2010
Location: Korea, Republic of
Posts: 98
Rep Power: 16
dokeun is on a distinguished road
dear cdegroot
I'm afraid but there was no such a file.

What I did.
After down loading the metis-5.0.2.tar.gz file from http://glaros.dtc.umn.edu/gkhome/metis/metis/download
I followed the window install instructoin of BUILD-Windows.txt as below

1. generated visual studio project files from METIS source using cmake gui.

2. opened METIS.sln and built this to make a library file.and the file yield was metis.lib in the directory the BUILD-Windows.txt described.

I guess libmetis.a is the type of library compiled in linux. -maybe metis.lib for windows- Did I guess correctly?
dokeun is offline   Reply With Quote

Old   January 28, 2013, 21:03
Default
  #4
Senior Member
 
cdegroot's Avatar
 
Chris DeGroot
Join Date: Nov 2011
Location: Canada
Posts: 414
Rep Power: 17
cdegroot is on a distinguished road
Yes you have guessed correctly. I've compiled and used on Linux and Mac OS, but never Windows. Sorry I won't be able to help with that.
cdegroot is offline   Reply With Quote

Old   January 28, 2013, 21:12
Default
  #5
Member
 
Dokeun, Hwang
Join Date: Apr 2010
Location: Korea, Republic of
Posts: 98
Rep Power: 16
dokeun is on a distinguished road
Not at all~
It's my fault with wrong title.
Anyway, have you ever got a link error during linking those files?
I think it not differenct so much.

Just in case, here is my simple test code to call. It's just a fortran code no special. There are some other talks about usint iso_c_binding, interface but, I thought those are not necessary becuase it just needs to link the metis library.
-----------------------------------
program METIS_call
implicit none

!input variables
integer :: ne, nn
integer, dimension(: ), allocatable :: eptr, eind
integer, pointer :: vwgt(: )=>null(), vsize=>null()
integer :: nparts
real(kind=8), pointer :: tpwgt(: )=>null()
integer, pointer :: opts(: )=>null()
integer :: objval
!output variables
integer, dimension(: ), allocatable :: epart, npart

!local variables
integer :: iC, iV

! read grid
! TODO Below will be modified to read a grid and initialize variables for real cases
ne = 4
nn = 9
allocate(eptr(ne+1), eind(4*ne), opts(17))
allocate(epart(ne), npart(nn))

! TODO It is necessary to write algorithm for eptr and eind after grid reading
do iC=1,ne+1
eptr(iC) = 1+4*(iC-1) !4 for quard, 3 for tri
end do
eind(: ) = (/1,2,4,5,2,3,5,6,4,5,7,8,5,6,8,9/)

! TODO Set option before calling METIS function
npart = 2
opts = 0
opts(1) = 1
opts(7) = 1

call METIS_PartMeshNodal(ne, nn, eptr, eind, vwgt, vsize, nparts, tpwgt, opts, objval, epart, npart)

end program

Last edited by dokeun; January 28, 2013 at 21:45.
dokeun is offline   Reply With Quote

Old   January 28, 2013, 21:33
Default
  #6
Senior Member
 
cdegroot's Avatar
 
Chris DeGroot
Join Date: Nov 2011
Location: Canada
Posts: 414
Rep Power: 17
cdegroot is on a distinguished road
Never had any problems linking in the METIS libraries. Are you sure about the argument list there? Doesn't seem to match what I see in the manual. Make sure you are looking at the docs for version 5.x as there were major changes from 4.x.
cdegroot is offline   Reply With Quote

Old   January 28, 2013, 21:50
Default
  #7
Member
 
Dokeun, Hwang
Join Date: Apr 2010
Location: Korea, Republic of
Posts: 98
Rep Power: 16
dokeun is on a distinguished road
It was METIS_PartMeshNodal, sorry to confuss.

For another try, I disabled MSVCRT.lib during linking but it cause warnings and errors as below.

Anyway if I fix this problem, I'll post what I've done
________________________________________________
1>Linking...
1>ipo: warning #11073: metis.lib(pmetis.obj): locally defined symbol __imp__printf imported
1>ipo: warning #11073: metis.lib(mesh.obj): locally defined symbol __imp__free imported
1>ipo: warning #11073: metis.lib(mesh.obj): locally defined symbol __imp__malloc imported
1>ipo: warning #11073: metis.lib(meshpart.obj): locally defined symbol __imp__raise imported
1>ipo: warning #11073: metis.lib(gklib.obj): locally defined symbol __imp__memmove imported
1>ipo: warning #11073: metis.lib(memory.obj): locally defined symbol __imp__fprintf imported
1>ipo: warning #11073: metis.lib(memory.obj): locally defined symbol __imp____iob_func imported
1>ipo: warning #11073: metis.lib(memory.obj): locally defined symbol __imp__realloc imported
1>ipo: warning #11073: metis.lib(error.obj): locally defined symbol __imp__exit imported
1>ipo: warning #11073: metis.lib(error.obj): locally defined symbol __imp__fflush imported
1>ipo: warning #11073: metis.lib(error.obj): locally defined symbol __imp__vfprintf imported
1>ipo: warning #11073: metis.lib(error.obj): locally defined symbol __imp__signal imported
1>ipo: warning #11073: metis.lib(error.obj): locally defined symbol __imp__strerror imported
1>ipo: warning #11073: metis.lib(util.c.obj): locally defined symbol __imp__rand imported
1>ipo: warning #11073: metis.lib(random.obj): locally defined symbol __imp__srand imported
1>metis.lib(kwayfm.obj) : warning LNK4049: locally defined symbol _printf imported
1>metis.lib(minconn.obj) : warning LNK4217: locally defined symbol _printf imported in function _libmetis__MoveGroupMinConnForVol
1>metis.lib(mincover.obj) : warning LNK4049: locally defined symbol _printf imported
1>metis.lib(debug.obj) : warning LNK4049: locally defined symbol _printf imported
1>metis.lib(fm.obj) : warning LNK4049: locally defined symbol _printf imported
1>metis.lib(balance.obj) : warning LNK4049: locally defined symbol _printf imported
1>metis.lib(sfm.obj) : warning LNK4217: locally defined symbol _printf imported in function _libmetis__FM_2WayNodeRefine1Sided
1>metis.lib(separator.obj) : warning LNK4049: locally defined symbol _printf imported
1>metis.lib(timing.obj) : warning LNK4217: locally defined symbol _printf imported in function _libmetis__PrintTimers
1>metis.lib(contig.obj) : warning LNK4217: locally defined symbol _printf imported in function _libmetis__IsConnected
1>metis.lib(compress.obj) : warning LNK4049: locally defined symbol _printf imported
1>metis.lib(mcore.obj) : warning LNK4217: locally defined symbol _printf imported in function _gk_gkmcoreDestroy
1>metis.lib(wspace.obj) : warning LNK4049: locally defined symbol _printf imported
1>metis.lib(initpart.obj) : warning LNK4217: locally defined symbol _printf imported in function _libmetis__GrowBisectionNode
1>metis.lib(coarsen.obj) : warning LNK4217: locally defined symbol _printf imported in function _libmetis__SetupCoarseGraph
1>metis.lib(options.obj) : warning LNK4049: locally defined symbol _printf imported
1>metis.lib(pmetis.obj) : warning LNK4217: locally defined symbol _printf imported in function _libmetis__MlevelRecursiveBisection
1>metis.lib(kmetis.obj) : warning LNK4217: locally defined symbol _printf imported in function _libmetis__MlevelKWayPartitioning
1>metis.lib(mesh.obj) : warning LNK4049: locally defined symbol _printf imported
1>metis.lib(ometis.obj) : warning LNK4217: locally defined symbol _printf imported in function _libmetis__MlevelNodeBisectionL2
1>metis.lib(mesh.obj) : warning LNK4217: locally defined symbol _free imported in function _libmetis__CreateGraphDual
1>metis.lib(auxapi.obj) : warning LNK4049: locally defined symbol _free imported
1>metis.lib(memory.obj) : warning LNK4049: locally defined symbol _free imported
1>metis.lib(mcore.obj) : warning LNK4049: locally defined symbol _free imported
1>metis.lib(mesh.obj) : warning LNK4217: locally defined symbol _malloc imported in function _libmetis__CreateGraphDual
1>metis.lib(memory.obj) : warning LNK4049: locally defined symbol _malloc imported
1>metis.lib(mcore.obj) : warning LNK4049: locally defined symbol _malloc imported
1>metis.lib(meshpart.obj) : warning LNK4217: locally defined symbol _raise imported in function _METIS_PartMeshNodal
1>metis.lib(error.obj) : warning LNK4217: locally defined symbol _raise imported in function _gk_siguntrap
1>metis.lib(gklib.obj) : warning LNK4217: locally defined symbol _memmove imported in function _libmetis__icopy
1>metis.lib(memory.obj) : warning LNK4049: locally defined symbol _memmove imported
1>metis.lib(memory.obj) : warning LNK4217: locally defined symbol _fprintf imported in function _gk_malloc
1>metis.lib(error.obj) : warning LNK4049: locally defined symbol _fprintf imported
1>metis.lib(memory.obj) : warning LNK4217: locally defined symbol ___iob_func imported in function _gk_malloc
1>metis.lib(error.obj) : warning LNK4049: locally defined symbol ___iob_func imported
1>metis.lib(memory.obj) : warning LNK4217: locally defined symbol _realloc imported in function _gk_realloc
1>metis.lib(mcore.obj) : warning LNK4049: locally defined symbol _realloc imported
1>metis.lib(error.obj) : warning LNK4217: locally defined symbol _exit imported in function _errexit
1>metis.lib(error.obj) : warning LNK4217: locally defined symbol _fflush imported in function _errexit
1>metis.lib(error.obj) : warning LNK4217: locally defined symbol _vfprintf imported in function _errexit
1>metis.lib(error.obj) : warning LNK4217: locally defined symbol _signal imported in function _gk_siguntrap
1>metis.lib(error.obj) : warning LNK4217: locally defined symbol _strerror imported in function _gk_strerror
1>metis.lib(util.c.obj) : warning LNK4217: locally defined symbol _rand imported in function _gk_RandomPermute
1>metis.lib(random.obj) : warning LNK4217: locally defined symbol _rand imported in function _gk_randinit
1>metis.lib(random.obj) : warning LNK4217: locally defined symbol _srand imported in function _gk_randinit
1>metis.lib(timers.obj) : error LNK2019: unresolved external symbol __imp___time64 referenced in function _time
1>metis.lib(timers.obj) : error LNK2019: unresolved external symbol __imp__clock referenced in function _gk_CPUSeconds
1>metis.lib(error.obj) : error LNK2019: unresolved external symbol __imp__longjmp referenced in function _gk_sigthrow
1>Release\METIS for Fortran.exe : fatal error LNK1120: 3 unresolved externals
1>
1>Build log written to "file://C:\Users\Administrator\Documents\Visual Studio 2008\Projects\Etc\METIS_API_call\Release\BuildLog. htm"
1>METIS for Fortran - 4 error(s), 60 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
dokeun is offline   Reply With Quote

Old   January 29, 2013, 04:06
Default
  #8
Member
 
Dokeun, Hwang
Join Date: Apr 2010
Location: Korea, Republic of
Posts: 98
Rep Power: 16
dokeun is on a distinguished road
I resolve the link problem by excluding a library so called as libcmt.lib. I don't know what it is... without this, there was no problem linking to files(fortran obj and metis obj) But I have another problem, during passing argument from my code.

I want to set some options but it is not impossible until now. Anyone who did this?!(ex. METIS_OPTION_NUMBERING)

Below is my code for simple 4 quads with 9 nodes, it look like normal but the result is not normal. Even if npart is 4 or 10!!, the result is not changed. How is this possible!?

program METIS_call
implicit none

!input variables
integer :: ne, nn
integer, dimension(: ), allocatable :: eptr, eind
integer, pointer :: vwgt(: )=>null(), vsize=>null()
integer :: nparts = 2
real(kind=8), pointer :: tpwgt(: )=>null()
integer, pointer :: opts(: )
integer :: objval
!output variables
integer, dimension(: ), allocatable :: epart, npart

! read grid
! TODO Below will be modified to read a grid and initialize variables for real cases
ne = 4
nn = 9
allocate(eptr(ne+1), eind(4*ne))
allocate(opts(40))
allocate(epart(ne), npart(nn))

eptr(: ) = (/0,4,8,12,16/)
eind(: ) = (/1,2,4,5,2,3,5,6,4,5,7,8,5,6,8,9/)

npart = 4 ! what ever this value is set, result is the same..
!opts = -1 ! this causes violation error
!opts(1) = 1 ! ignore all options...
!opts(5) = 1
!opts(7) = 1

!initialize
epart = 0
npart = 0

call METIS_SetDefaultOptions(opts)
call METIS_PartMeshNodal(ne, nn, eptr, eind, vwgt, vsize, nparts, tpwgt, opts, objval, epart, npart)end program

Last edited by dokeun; January 29, 2013 at 04:41.
dokeun is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fortran Compiler-CFX12.1 Araz CFX 13 March 27, 2017 05:37
Using Fortran with CFX: How to connect Fortran to CFX? l.te CFX 0 October 21, 2012 11:42
Metis on OF 2.0.0 pere OpenFOAM Running, Solving & CFD 0 February 29, 2012 06:28
Context of user fortran functions Bloshchitsyn Vladimir CFX 0 October 17, 2007 06:28
visual fortran Monica Main CFD Forum 1 August 28, 2004 20:45


All times are GMT -4. The time now is 16:41.