Re: How to call a METIS subroutine from my FORTRAN code.



AM <wiredashu@xxxxxxxxx> wrote:

> Now that i have completely lost all my dignity

Not at all!

> http://www-users.cs.umn.edu/~karypis/metis/metis/files/metis-4.0.tar.gz

Ok. Done. Hmm. This ought to be simple. Looking at the function, I see
that all its arguments are integers (some are typedefed, but that turns
out to be integer) and passed by reference. I don't happen to be using a
compiler that supports the !$DEC stuff, so I was about to do a trivial
workaround, which should be simple for a C function like this, but...

Then I took a look at the manual on pg 43 where it mentions C and
Fortran support. It comments that they specifically did all the
arguments that way to make Fortran simple, and... I see... they already
did one of the workarounds I was planning on. Namely, they made trivial
wrapper functions with names METIS_NODEND, metis_nodend, metis_nodend_,
and metis_nodend__ (the last 2 there differ in the number of trailing
underscores). Indeed I see those functions in the file frename.c
(obviously for "Fortran renames"). That pretty much covers all the
common cases. This ought to just work, even without a compiler that
supports the !$DEC stuff. Ok.

I went over to one of my Linux boxes (RedHat 7.3), untarred the metis
library and typed make. Seemed to build. Then I did the simplest Fortran
test program I could come up with without actually having to think. :-)
I took your posted code exactly as is, doing nothing other than fix a
few comment lines that wrapped in the posting. Then I threw the
following trivial main program in front of it, where I got the data
values from the comments in your code. I used slight editor trickery to
turn the values into valid array constructors without actually retyping
them (so as to lower the odds of typos). Thus my main program is:

program testmet
implicit none
integer, parameter :: n=15, m=22
integer,dimension(n+1) :: node
integer,dimension(2*m) :: link
integer,dimension(n) :: perm, iperm
node = (/1,3,6,9,12,14,17,21,25,29,32,34,37,40,43,45/)
link = (/2,6,1,3,7,2,4,8,3,5,9,4,10,1,7,11,2,6, &
8,12,3,7,9,13,4,8,10,14,5,9,15,6,12,7,11,13, &
8,12,14,9,13,15,10,14/)

call mnd(n, m, node, link, perm, iperm)
write (*,*) 'perm = ', perm
write (*,*) 'iperm = ', iperm
end

Compiled and linked it using the NAG f90 compiler with

f90 clf.f90 -Lmetis-4.0 -lmetis

Runs fine and gives the result

perm = 15 5 9 4 14 10 12 2 6 1 11 7 13 8 3
iperm = 10 8 15 4 2 9 12 14 3 6 11 7 13 5 1

which I didn't check, but sure beats a segmentation fault.

Just for kicks, did the same thing on my Mac with both the Nag and g95
compilers. That's odd. The Mac ones give different answers than the
Linux one (both Mac compilers giving the same answer). Well, I don't
think I'll try to track that one down. Doesn't look like a Fortran
interface problem anyway, as far as I can see. The stuff doesn't claim
to have been tested on OS X. Oh well.

This leaves me with two... make it three... questions about your
experience.

1. I assume that the compilation and linking did go without error?
Probably did or you wouldn't have an executable to run, but it seems
worth asking.

2. Are you sure that you have good data for the node and link arrays? I
note that the value of m doesn't get fed to the C code. Apparently it
just depends on the arrays being valid without having any handy way to
check. This seems like asking for problems where bad data causes array
bounds to be exceeded. Specifically, have you tried it with known valid
data such as the sample case in the comments (for example, using the
main program II posted above)?

3. How sure are you that the code even got to the Metis_ND invocation?
The error messages almost sound like it is still in some vsim_metis_slu
file (presumably of yours, as I don't see anything of that name in the
metis stuff. I see that your output says "Calling METIS", but I don't
see that message in either metis or in your MND subroutine. What are the
odds that you didn't yet actually get into MND sucessfully? Maybe add a
printout in it?

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
.



Relevant Pages

  • Re: Who uses clapack?
    ... > functions like SUM and MAXVAL and the ability to use array sections ... > drastically change the meaning of a Fortran code. ... >>Have you ever seen those bills for a Fortran compiler for an ... engineering applications in the C and C++ languages. ...
    (comp.lang.fortran)
  • Re: Who uses clapack?
    ... > functions like SUM and MAXVAL and the ability to use array sections ... > drastically change the meaning of a Fortran code. ... >>Have you ever seen those bills for a Fortran compiler for an ... engineering applications in the C and C++ languages. ...
    (sci.math.num-analysis)
  • Re: Use string syntax with array
    ... you declare a as a character with length 1 variable. ... matter whether or not the compiler detects it, ... scalar and point to an array. ... Would someone try below with Intel Fortran? ...
    (comp.lang.fortran)
  • Re: Double precision arrays and subroutines
    ... to be the start of an nx * nx array. ... What happens is that, in Fortran, these two program units are independent. ... The subroutine and the program that calls it are compiled separately, and normally the compiler doesn't know about one when it's compiling the other. ... Thus, the compiler doesn't know about the mismatch between the fact that the subroutine call is being given an integer and two scalar doubles, and the subroutine declaration is expecting an integer and two double arrays. ...
    (comp.lang.fortran)
  • Re: Idea for ECMA/C# Standard - compile time hash for performance
    ... I agree with you the chance of a compiler change is slim, ... and then delegating to the standard hash for fields accessed less frequently. ... or the array lookup which would require the ... > 64-bit architecture) for each enum value that doesn't map to anything. ...
    (microsoft.public.dotnet.languages.csharp)