How to call a METIS subroutine from my FORTRAN code.

  • Permalink
  • submit to reddit
  • Email
  • Follow


Hello to all METIS/FORTRAN programmers..

Despite being exceedingly embarassing - i have finally succumbed to
asking this. All i seek is to call the subroutine METIS_NODEND from my
fortran code and the sad part is that despite reading the entire
section 5.8 of the users manual where even though it is mentioned that
these routines are callable from either c or fortran, there are no
examples to actually do so.

Furthermore, reading in other places, I am lead to believe that there
might be a requirement of a fortran version of the metis.h header file
that would need to be included in the FORTRAN code. However - it is not
present in the latest distributed package. :-(

If there is anyone out there who is using FORTRAN and has managed to
successfully call the METIS subroutines - I would really appreciate
some pointers and if possible some actual example files - that i can go
through and understand. 

Much thanks,

-A

0
Reply wiredashu (16) 11/30/2005 11:00:06 PM

See related articles to this posting

AM,

 I know this is possible, since I received a code from the University of
Minnesota that does this.  I have this code in object format only, therefore I
don't have any examples to do this.  What Fortran and C compilers do you have
available??

Joe



On 30 Nov 2005 15:00:06 -0800, "AM" <wiredashu@gmail.com> wrote:

>Hello to all METIS/FORTRAN programmers..
>
>Despite being exceedingly embarassing - i have finally succumbed to
>asking this. All i seek is to call the subroutine METIS_NODEND from my
>fortran code and the sad part is that despite reading the entire
>section 5.8 of the users manual where even though it is mentioned that
>these routines are callable from either c or fortran, there are no
>examples to actually do so.
>
>Furthermore, reading in other places, I am lead to believe that there
>might be a requirement of a fortran version of the metis.h header file
>that would need to be included in the FORTRAN code. However - it is not
>present in the latest distributed package. :-(
>
>If there is anyone out there who is using FORTRAN and has managed to
>successfully call the METIS subroutines - I would really appreciate
>some pointers and if possible some actual example files - that i can go
>through and understand. 
>
>Much thanks,
>
>-A

0
Reply georgecostanz50 (23) 12/1/2005 12:15:24 AM

Joe !

I am using the intel Fortran and C compilers on in a linux environment.
I did a grep to find which c files had the Metis_nodend and then - went
onto link frename.c to my fortran code. The code compiles and links
just fine - however when executing it -, just before the call to
Metis_nodend(..) it crashes.
Any hints ?

thank you taking the time to reply. Much appreciated ! 

-AM

0
Reply wiredashu (16) 12/1/2005 11:55:09 AM

AM wrote:

> Hello to all METIS/FORTRAN programmers..
>
> Despite being exceedingly embarassing - i have finally succumbed to
> asking this. All i seek is to call the subroutine METIS_NODEND from my
> fortran code and the sad part is that despite reading the entire
> section 5.8 of the users manual where even though it is mentioned that
> these routines are callable from either c or fortran, there are no
> examples to actually do so.
>
> Furthermore, reading in other places, I am lead to believe that there
> might be a requirement of a fortran version of the metis.h header file
> that would need to be included in the FORTRAN code. However - it is not
> present in the latest distributed package. :-(
>
> If there is anyone out there who is using FORTRAN and has managed to
> successfully call the METIS subroutines - I would really appreciate
> some pointers and if possible some actual example files - that i can go
> through and understand. 
> 
> Much thanks,
> 
> -A

0
Reply edunlop1 (5) 12/1/2005 3:46:26 PM

AM,

The following code works nicely with Intel Fortran 9.0 for Windows.
Hope this may help.

Edmund

------------------------------------------------------------------------------------

      subroutine MND(n, m, node, link, perm, iperm)
      implicit none
      integer,intent(in) :: n, m
      integer,intent(in),dimension(n+1) :: node
      integer,intent(in),dimension(2*m) :: link
      integer,intent(out),dimension(n) :: perm, iperm
      integer :: numflag
      integer,dimension(0:7) :: options
      external METIS_NodeND
!DEC$ ATTRIBUTES C,REFERENCE, ALIAS:"_METIS_NodeND" :: METIS_NodeND
!
! METIS_NodeND (N, NODE, LINK, NUMFLAG, OPTIONS, PERM, IPERM)
!
! Description
!
! This function computes fill reducing orderings of sparse matrices
! using the multilevel nested dissection algorithm. It provides the
! functionality of the onmetis program.
!
! Parameters
!
! N  The number of vertices in the graph.
!
! NODE, LINK
! The adjacency structure of the graph as described below.
!
! NUMFLAG  Used to indicate which numbering scheme is used for the
! adjacency structure of the graph. NUMFLAG can take the following two
! values:
! 0  C-style numbering is assumed that starts from 0
! 1  Fortran-style numbering is assumed that starts from 1
!
! OPTIONS  This is an array of 8 integers that is used to pass
! parameters for the various phases of the algorithm.
!
! If OPTIONS[0]=0 then default values are used. If OPTIONS[0]=1, then
! the remaining seven elements of options are interpreted as follows:
!
!   OPTIONS[1]  Determines the matching type. Possible values are:
!   1 Random Matching (RM)
!   2 Heavy-Edge Matching (HEM)
!   3 Sorted Heavy-Edge Matching (SHEM) (Default)
!   Experiments have shown that all three matching schemes perform
quite
!   well. In general SHEM is faster and RM is slower, but feel free to
!   experiment with the other matching schemes.
!
!   OPTIONS[2]  Determines the algorithm used during initial
!               partitioning. Possible values are:
!   1 Edge-based region growing (Default)
!   2 Node-based region growing
!
!   OPTIONS[3]  Determines the algorithm used for refinement. Possible
!               values are:
!   1 Two-sided node FM refinement
!   2 One-sided node FM refinement (Default)
!   One-sided FM refinement is faster than two-sided, but in some cases
!   two-sided refinement may produce better orderings. Feel free to
!   experiment with this option.
!
!   OPTIONS[4]  Used for debugging purposes. Always set it to 0
!               (Default).
!
!   OPTIONS[5]  Used to select whether or not to compress the graph and
!               to order connected components separately. The possible
!               values and their meaning are as follows:
!   0 Do not try to compress the graph and do not order each connected
!     component separately.
!   1 Try to compress the graph. (A compressed graph is actually formed
!     if the size of the graph can be reduced by at least 15%)
!     (Default).
!   2 Order each connected component of the graph separately. This
!     option is particularly useful when after a few levels of nested
!     dissection, the graph breaks up in many smaller disconnected
!     subgraphs. This is true for certain types of LP matrices.
!   3 Try to compress the graph and also order each connected component
!     separately.
!
!   OPTIONS[6]  Used to control whether or not the ordering algorithm
!               should remove any vertices with high degree (i.e.,
dense
!               columns). This is particularly helpful for certain
!               classes of LP matrices, in which there a few vertices
!               that are connected to many other vertices. By removing
!               these vertices prior to ordering, the quality and the
!               amount of time required to do the ordering improves.
The
!               possible values are as follows:
!   0  Do not remove any vertices (Default)
!   x  Where x > 0, instructs the algorithm to remove any vertices
whose
!      degree is greater than 0.1 * x * average degree). For example if
!      x = 40, and the average degree is 5, then the algorithm will
!      remove all vertices with degree greater than 20. The vertices
!      that are removed are ordered last (i.e., they are automatically
!      placed in the top-level separator). Good values are often in the
!      range of 60 to 200 (i.e., 6 to 20 times more than the average).
!
!   OPTIONS[7]  Used to determine how many separators to find at each
!               step of nested dissection. The larger the number of
!               separators found at each step, the higher the runtime
!               and better the quality is (in general). The default
!               value is 1, unless the graph has been compressed by
more
!               than a factor of 2, in which case it becomes 2.
!               Reasonable values are in the range of 1 to 5. For most
!               problems, a value of 5 increases the runtime by a
factor
!               of 3.
!
! PERM, IPERM
! These are vectors, each of size n. Upon successful completion, they
! store the fill-reducing permutation and inverse-permutation. Let A be
! the original matrix and A' be the permuted matrix. The arrays PERM
and
! IPERM are defined as follows. Row (column) i of A' is the PERM[i] row
! (column) of A, and row (column) i of A is the IPERM[i] row (column)
of
! A'. The numbering of this vector starts from either 0 or 1, depending
! on the value of numflag.
!
!
======================================================================
!
! The adjacency structure of the graph is stored using the compressed
! storage format (CSR). The CSR format is a widely used scheme for
! storing sparse graphs. In this format the adjacency structure of a
! graph with n vertices and m edges is represented using two arrays
NODE
! and LINK. The NODE array is of size n+1 whereas the LINK array is of
! size 2m (this is because for each edge between vertices v and u we
! actually store both (v,u) and (u,v)).
!
! The adjacency structure of the graph is stored as follows. Assuming
! that vertex numbering starts from 1 (Fortran style), then the
! adjacency list of vertex i is stored in array LINK starting at index
! NODE[i] and ending at (but not including) index NODE[i+1] (i.e.,
! LINK[NODE[i]] through and including LINK[NODE[i+1]-1]). That is, for
! each vertex i , its adjacency list is stored in consecutive locations
! in the array LINK, and the array NODE is used to point to where it
! begins and where it ends. Figure 1(b) illustrates the CSR format for
! the 15-vertex graph shown in Figure 1(a).
!
!
!    1-- 2-- 3-- 4-- 5
!    |   |   |   |   |
!    6-- 7-- 8-- 9--10
!    |   |   |   |   |
!   11--12--13--14--15
!
!   (a) A sample graph
!
!
!   N = 15;  M = 22
!
!   NODE(N+1)     1  3  6  9 12 14 17 21 25 29 32 34 37 40 43 45
!
!   LINK(2*M)     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
!
!   (b) CSR format
!
!   Figure 1: An example of the CSR format for storing sparse graphs.
!
!
      numflag = 1
      options(0) = 0
      call METIS_NodeND(n, node, link, numflag, options, perm, iperm)
      return
      end subroutine MND

0
Reply edunlop1 (5) 12/1/2005 4:02:58 PM

One further thought (on the C side - I use Intel C/C++ for Windows):

I needed to modify metis.h as follows:

/*
 * Copyright 1997, Regents of the University of Minnesota
 *
 * metis.h
 *
 * This file includes all necessary header files
 *
 * Started 8/27/94
 * George
 *
 * $Id: metis.h,v 1.1 1998/11/27 17:59:21 karypis Exp $
 */


#define __VC__

#include <stdio.h>
#ifdef __STDC__
#include <stdlib.h>
#else
#include <malloc.h>
#endif
/*
 * #include <strings.h>
 */
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <stdarg.h>
#include <time.h>

#ifdef DMALLOC
#include <dmalloc.h>
#endif

#include <defs.h>
#include <struct.h>
#include <macros.h>
#include <rename.h>
#include <proto.h>

I then compiled all the .c files and used the linker to make a .lib
file ( .a in Linux parlance?).

I then compiled my Fortran source and included a search of the .lib
file on the final link.

By the way, sorry about the blank response initially - my first time to
try Google with this newsgroup and I was too fast at pressing buttons.

Hope this helps,

Edmund

0
Reply edunlop1 (5) 12/1/2005 4:23:58 PM

Hi Edmund !

Thank you for your response(s). I do still have a few questions:

Going by your above examples - i noticed that the entire section in "!"
is commented out. What leaves is that there is just a direct call to
Metis_NodeNd from external subroutine MND. I was doign the same thing -
and it's not working. The basic problem is that how does FORTRAN and C
know where to call the function from. Ideally - if there was a fortran
version of the header file - metis.c -then all this would be been more
than evident.

I am still lost a bit. Also - from what i can see - the only change you
made to your metis.c header file is the addition of #define __VC__

apart from that what i have out here is the same - (except it's on a
Linux platform). If you wish - i can post a bit of my FORTRAN code ?

Regards,

-AM

0
Reply wiredashu (16) 12/1/2005 6:36:23 PM

I've never heard of Metis, but...

AM <wiredashu@gmail.com> wrote:

> The basic problem is that how does FORTRAN and C
> know where to call the function from. Ideally - if there was a fortran
> version of the header file - metis.c -then all this would be been more
> than evident.

Significant confusions of terminology or something here.

A procedure is "called" (invoked) from wherever the call statement or
function reference appears in the source code. I think that perhaps you
are asking about where the procedure itself comes from rather than where
it is called from. The answer to that is generally that you have either
the source code or a library for the procedure somewhere, and you have
to tell the compiler to use that. You would use compiler command-line
switches (or the GUI equivalent) to tell the compiler that. That
information is not in the invoking source code (either in C or Fortran).

And a .c file would not be a "header" file. I think you mean metis.h.

> I was doign the same thing - and it's not working.

What does "it's not working" mean? That's not very descriptive. I'm sure
you get a bit more detailed error message than that.

> i noticed that the entire section in "!" is commented out.

Ah. I just noticed this. It might be your problem. A "comment" beginning
with, for example, "!DEC$", as one of these does, is not "really" a
comment. That's a commonly used convention for a compiler directive. In
this case, that compiler directive hapens to be critically important; if
you leave it out because you think it is just a comment and therefore
doesn't matter, things probably won't work. I'm placing my money on that
being your problem.

-- 
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
0
Reply nospam47 (9747) 12/1/2005 7:12:05 PM

To expand on Richard Maine's comments:

This line:
      external METIS_NodeND
is Fortran telling the compiler the routine is an external routine.

But this line:
!DEC$ ATTRIBUTES C,REFERENCE, ALIAS:"_METIS_NodeND" :: METIS_NodeND
is a Digital (DVF/CVF) directive, not part of the Fortran language, which tells the
compiler that the external symbol METIS_NodeND is expecting the C-language calling
and naming conventions, but the arguments are to be passed by reference (i.e.,
send addresses) and the published name to find it (in external .OBJ or .LIB) is
_METIS_NodeND which will be treated in a case-sensitive manner by the compiler since
it is in quotes.  Provided the linker preserves case during link operations, the 
symbol should be found and linked properly.  

If you are not using DVF/CVF or another compiler that supports DEV-style metacommands,
then you will need a different means of informing the compiler about the name aliasing
and calling conventions.

Isn't mixed language programming fun?
0
Reply kgrhoads (401) 12/1/2005 7:38:07 PM

Hi there...the reason why i think it's a comment is because, there is
an entire subroutine description that is preceded by the "!". If it
were not so - then there would be more elementary problems..?

Also - yes..i meant metis.h. the package ships with the c header file,
however FORTRAN programmers seem to be tragically out of luck.

Finally when i mentioned it didnt work - well the code terminates..
Here is a replication of the same..
------------------------------------
Calling METIS...
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line
Source
vsim_metis_slu     00000000004D09F7  Unknown               Unknown
Unknown
vsim_metis_slu     00000000004C6612  Unknown               Unknown
Unknown
vsim_metis_slu     0000000000410826  Unknown               Unknown
Unknown
vsim_metis_slu     0000000000408C12  Unknown               Unknown
Unknown
vsim_metis_slu     0000000000405C76  Unknown               Unknown
Unknown
libc.so.6          0000002A95E301AE  Unknown               Unknown
Unknown
vsim_metis_slu     0000000000405BAA  Unknown               Unknown
Unknown
rank 0 in job 1  on <..>  caused collective abort of all ranks  exit
status of rank 0: return code 174
--------------------

Any hints ? 

-AM

0
Reply wiredashu (16) 12/1/2005 7:47:09 PM

OHHHH ! ! ! ...ok..let me try something...and then will post this back.
If am successful - i swear i will post a small guide.

Be right back. :-)

-AM

0
Reply wiredashu (16) 12/1/2005 8:08:36 PM

AM <wiredashu@gmail.com> wrote:

> Hi there...the reason why i think it's a comment is because, there is
> an entire subroutine description that is preceded by the "!". If it
> were not so - then there would be more elementary problems..?

No. Just because those are on following lines does not mean they are
part of thee directive. That one line is not a comment and *IS*
important. Really. The rest are actually comments.

Oh, but I see you said you are on Linux. Alas, that stuff is very
compiler-specific. As Kevin said, you'll probably need another way to
achieve the ends if you aren't using a compiler that supports the !$DEC
directives. Posting snippets from the C side might help.

Have I mentioned recently that I look forward to the C interop features
of f2003 so that this kind of thing can actually be done portably.  :-(

-- 
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
0
Reply nospam47 (9747) 12/1/2005 8:17:14 PM

You were right !

It was not a comment and yes..the compiler i am using does support the
!$DEC directives. However - am not having succes. I am not sure what
you were refering to "...snippets from C side". I can do so - just let
me know - if it's the C function that needs to be ultimately called
that you refer to ! :-(

<"have I mentioned recently that I look forward to the C interop
features
of f2003 so that this kind of thing can actually be done portably.  :-(
>

Me too ! ..

-AM

0
Reply wiredashu (16) 12/1/2005 8:28:51 PM

>However - am not having succes.

When in doubt, post all error messages without editting.  Context is also useful.
0
Reply kgrhoads (401) 12/1/2005 8:33:48 PM

Nope..no success as yet. My compiler DOES support the !DEC$ directives.
Still no luck ! The charm of being alive fading away ... :-(

-AM

0
Reply wiredashu (16) 12/1/2005 8:34:16 PM

AM <wiredashu@gmail.com> wrote:

> It was not a comment and yes..the compiler i am using does support the
> !$DEC directives. However - am not having succes. I am not sure what
> you were refering to "...snippets from C side". I can do so - just let
> me know - if it's the C function that needs to be ultimately called
> that you refer to ! :-(

Yes, if it is reasonable enough sized to post. The "snippets" bit was to
suggest that you could probably get by with just the beginning part of
the C function if necessary. But if the whole thing is plausibly
postable, that would be better. It is presumably the METIS_NodeND
function that we are talking about.

-- 
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
0
Reply nospam47 (9747) 12/1/2005 8:42:33 PM

Hi Richard !
Now that i have completely lost all my dignity - may i make a
suggestion ? You mentioned you have never heard of METIS. Would it be
too much for you to actually download it and take a look ? It's a
library of Sparse matrix reordering algorithms among other things.
Available from:
http://www-users.cs.umn.edu/~karypis/metis/metis/files/metis-4.0.tar.gz

It has a users guide in there..which if you look at - will state (in
section 5.8) that there is complete support for fortran programs etc...
The function Metis_Nodend is listed in this guide.

However - this is where things get tricky. There is NO actual c file
with this name. this function is found in another c file called
"ometis.c".

Since All my problems are syntactical - so you dont even have to read
about their workings or innards. All i waiting for is to be able to
overcome this interfacing issue. 

-AM

0
Reply wiredashu (16) 12/1/2005 9:02:19 PM

AM <wiredashu@gmail.com> 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
0
Reply nospam47 (9747) 12/1/2005 10:32:25 PM

Well that settles it...i am just lost. Ok. let me retrace my steps -
use your suggestions on the print out and then comeback.
BTW - Richard - thank you SO much for all this.. :-)

-Ash

0
Reply wiredashu (16) 12/1/2005 10:52:30 PM

YESS ! ! !!

<ahem> so now that is done - let me highlight - what i was doing wrong
!

deallocate(isr_a,icol_a,rv_a)
call MND(i_totalnodes,size(icol_a),isr_a,icol_a,perm,iperm)
..
..

Somehow that line of deallocate was invisible to me ! AND IT WAS RIGHT
THERE ! :-( Ofcourse there were a few other errors (such as i had ...)

allocate(iperm(i_totalnodes+1),perm(i_totalnodes+1)) - which should
have been only i_totalnodes..but ...:-(

Anyway - THANK YOU SO MUCH everyone ! Now i am going to fixing the next
step with proper usage of this routine ! Apparently - there is yet
another restriction about the structure of the "link" vector that i
will need to make sure doesn't crop up.

-Ash

ps: and what is really tragic - i have been looking at this code for
the last 2 days..(this particular problem) !

0
Reply wiredashu (16) 12/1/2005 11:35:22 PM

AM <wiredashu@gmail.com> wrote:

> YESS ! ! !!
....
> Somehow that line of deallocate was invisible to me ! AND IT WAS RIGHT
> THERE ! :-(

Been there. Done that. :-(

-- 
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
0
Reply nospam47 (9747) 12/1/2005 11:51:51 PM
comp.lang.fortran 10839 articles. 36 followers. Post

20 Replies
399 Views

Similar Articles

[PageSpeed] 41

  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Many Fortran code! How to call Fortran code from C/C++?
Hi all, As a C/C++ programmer, there are a few reasons to use Fortran: (1) Fortran is very similar to Matlab and easy to port; (2) Fortran has support of complex numbers and vectorized numbers and the operations in Fortran are naturally element-wise, operating on a whole vector. (3) There are many scientific codes are in Fortran. ------------- So how do I call Fortran program from my C program? I am using MSVS. NET 2003, VisualC++ and Intel C++ therein, and also the Intel Visual Fortran therein. To give an example, I want to call a Fortran program from C++, which is in its bare form, it ...

Calling FORTRAN functions rather than FORTRAN subroutines via call
Hi everybody, all examples I know show how to call a FORTRAN subroutine. I have a lot of FORTRAN code regarding thermophysical properties of water, steam, smoke gas etc. This code consists of many FORTRAN functions. I wish to call them inside scilab. Is it possible? If yes how can the function return value be obtained? Thank you very much, many greetings Eberhard On 2 jan, 14:41, i...@efranz.de wrote: > Hi everybody, > > all examples I know show how to call a FORTRAN subroutine. I have a > lot of FORTRAN code regarding thermophysical properties of water, > ...

Calling subroutine in fortran module
I tried calling a subroutine in a fortran module from C ,but couldn't.I always get the error: undefined reference in the main.o file (main is in C calling the subroutine). for calling the subroutine I used the following name: modulename_MP_subroutinename_(...) and all possible variant (upper case,lower case).Can anybody help (for a unix system) "Amit" <kumar20@gmail.com> writes: > I tried calling a subroutine in a fortran module from C ,but couldn't.I > always get the error: undefined reference in the main.o file (main is > in C calling the subroutine). >...

Calling fortran subroutine from c
I don't know if this is the right forum for this, and if not please suggest one which fits. I have to call a fortran sub routine from a C main program. The fortran subroutine statement is wload(starttime, duration, station, component, dataray, nsamp, calib, srate, samplength, datadir) And the variables are defined real*8 starttime real duration character*(*) sta character*(*) component integer*4 dataray(1) integer nsamp,samplength real calib,srate character*100 datadir Of these, starttime, duration, station, component are inputs. dataray is an integer vector created in the C-progra...

failed to call fortran subroutine
Hello, I followed the procedure in the example (\scilab\modules \dynamci_link_c_and_fortran) I tried to call a fortran subroutine by: ilib_for_link('B_generator','B_generator.f',[],"f") but it always shows an error message: ============================ Generate a loader file Generate a Makefile Running the Makefile !--error 10000 A Fortran or C compiler is required. at line 12 of function ilib_compile called by : at line 86 of function ilib_for_link called by : ilib_for_link('B_generator','B_generator.f',[],"...

Matlab call in fortran code
Hi all, I have a little question concerning Matlab in fortran code. I know that in Matlab, you can reallocate a matrix without doing anything. For example, A=eye(3) A = 1 0 0 0 1 0 0 0 1 >> A=[A;A] A = 1 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 1 In my fortran code, I read a mat file that contains matrices. As an example, let's consider a 1000 by 10 matrix (real data). My fortran code produces a 20 by 10 matrix (real data) and I want to apend this computed array to th...

Calling Fortran code with Photran?
Hey We have some old Fortran code that we would like to be able to use from a Java application. Have downloaded Photran and I am now looking for how to call Fortran subroutines from a Java program, but their documentation doesn't mention that and I have not been able to find the answer elsewhere on the Web. Anyone have any experience or a reference to a good source of info? Regards. On 10/25/2013 02:26 PM, Hawkan wrote: > > Hey > > We have some old Fortran code that we would like to be able to use from > a Java application. Have downloaded Photr...

how to call Fortran subroutines from Matlab?
as title hnliuhy wrote: > as title http://www.google.com/search?ie=UTF-8&q=calling+fortran+from+matlab Madhusudan Singh wrote: > > > hnliuhy wrote: > >> as title > > <http://www.google.com/search?ie=UTF-8&q=calling+fortran+from+matlab> > I have editted an example, and try to run it, it won't work. Would any one check my code? thanks 1) I make a fortran-matlab interface code, test_mex.f subroutine mexFunction(prhs, nrhs, plhs, nlhs) integer prhs(*), plhs(*), nrhs, nlhs ! pointer between Matlab and For real*8 ypr, tr, yr C Copy array point...

calling fortran subroutine in Scilab
Hello I follow the steps in this page: http://www.g95.org/scilab.shtml to call fortran subroutine in windows. I have two questions, 1). I don't understand what is "dlltool", is it a necessary steps? where 2). In the last example, " Interfacing with Fortran in Scilab " it doesn't use dlltool anymore. I followed this example, by typing: ================================================= --> link('B_generator.dll','B_generator') Shared archive loaded. Link done. B_generator_ is not an entry point. =============================...

calling metis Api in fortran program
hi can anybody help me to call metis api in fortran program...

Calling a Simulink model from a Fortran subroutine
Can we call a Simulink model from a Fortran code? If so, how? I need an example. Where do I find? Thanx NSP ...

call functions in static libraries from Fortran code?
Hello all, I have next problem: from the fortran program need to call some C code, compiled in static libraries. I heard about appending underscores to functions in C, but I haven't C sources of theese functions - just a .lib and .h files. So every time I try to compile my program, I receive "unresolved" errors. Do I need to create some wrappers in C like: void cfun_(.........) { //call here function in static library and send results to fortran } - or there exists another way for that (something like translations .h files from c to fortran etc.)? Thanks for all answers (excu...

Problem with fortran subroutines called from a c program
Hi to all, i don't know the fortran language and i need to use the program at this link http://ligin.weizmann.ac.il/space/programs/rescP.tar In the .tar file there is a .c program that call some subroutines. This subroutines are written in fortran (i am not 100% sure it is fortran) and resides in three distinct files. I have a pc with windows xp and i really need help in order to use that program... thank you kingpin@freemail.it wrote: > Hi to all, > > i don't know the fortran language and i need to use the program at > this link > > http://ligin.weizmann.ac.il...

global variables in Fortran calling C subroutine
Hi, Dear all, I had meet a problem in calling C function from Fortran main program. There are a global variable defined in C sub. When I want to visit this varaiable, it will return a wrong number. The main framework of my program is like below: Here is the fortran main program: program main a=fun1() b=fun2() end And the C sub is listed below: #include ..... static int important int fun1() { some statement important = 100 } int fun2() { printf("%d",important) } The main program works fine. The value of "important" is right in both C funtion. However,...

How to compile Fortran code to use matOpen subroutines?
Hi, all I am trying to compile a fortran code which include calling matOpen subroutine, I try the command line: f90 test.f90 /libs:dll the Fortran compiler I use is Compaq visual Fortran, but it always shows that: error LNK2001: unresolved external symbol _MATOPEN@16 Can any one help me, thanks in advance. Xianyao Chen On Tue, 24 Feb 2004 14:15:13 +0000 (UTC), xianyaochen@yahoo.com.cn (Xianyao Chen) wrote: >Hi, all > >I am trying to compile a fortran code which include calling matOpen >subroutine, I try the command line: > > f90 test.f90 /libs:dll &...

C-mex-file that call Fortran subroutine?
Hi, I'm trying to make a mex-file, written in C, which then calls a Fortran-subroutine in the code. But when I try to compile I get an error. The mex-file looks like this: ------------------------------------------------- #include <math.h> #include "mex.h" /* Input Arguments */ #define nu_IN prhs[0] #define T_IN prhs[1] #define F_IN prhs[2] #define W_IN prhs[3] /* Output Arguments */ #define A_OUT plhs[0] /* Undefined functions */ #if !defined(MAX) #define MAX(A, B) ((A) > (B) ? (A) : (B)) #endif #if !defined(MIN) #define MIN(A, B) ((A) < (B) ? (A) : (B)) #endi...

Can I have one fortran subroutine in a Matlab code?
My code has a minimization/nonlinear equation solving within it. I tried using fmincon and lsqnonlin. Both take up enormous amounts of time. I was wondering if using a fortran subroutine for minimization within the matlab code save me some time. If yes,can I get some examples on how that can be done? Thanks a lot!! On 8/2/2012 3:35 PM, sarita wrote: > My code has a minimization/nonlinear equation solving within it. I tried > using fmincon and lsqnonlin. Both take up enormous amounts of time. I > was wondering if using a fortran subroutine for minimization within the > matlab ...

Calling Matlab functions in Fortran code
Hello, My work is on numerical techniques which require to solve sparse matrices etc. All my work is in fortran and I have almost no skill in Matlab.But I have just realized that Matlab can do some computations quite easily with its built-in functions and I want to take advantage of this. I have no time to learn Matlab deeply or work on matlab-fortran communication (very much off-focus issues and have deadline soon) Some details: I need to solve Ax=b system where A is very large and sparse matrix (20000x20000 or more). At every time step (iteration) I need to solve this system, get 'x...

fortran code for 'cp' / subroutine file_copy
Hi all, I would like to issue a copy operation from within my Fortran code. I have been using the system intrinsic, however, some compilers do not know about this intrinsic. While trying to implement my file_copy subroutine, I got stuck at the open and read statements for an arbitrary (binary or ascii) file to copy. both gfortran and f90 (nag) give different runtime errors. Any recommendations, has anyone else implemented this? TIA, Carsten subroutine file_copy(arg1,arg2,status,delete) character(len=*),intent(in) :: arg1,arg2 integer,intent(out) :: status logical,intent(i...

Array pointer changed after calling FORTRAN subroutine in C++
hi I am working on a library written in F90 and compiled by gfortran. Now I am trying to write a C++ header to use the fortran library (.so/.a). I am very new to interfacing C/Fortran and found a strange issue when calling the fortran code: Here is a sample of my header file: "DBLQMRPrep" is a function defined in a fortran module: .... #define DBLQMRPrep __blit_blqmr_real_MOD_blqmrprep extern void DBLQMRPrep(BLQMRSolver *qmr, int *Ap, double *Ax, int *nz); template <class T> class MyClass{ DBLQMRPrep qmr; int *Ap; T *Ax; public: void Prepare(int *App, T *Axx, i...

can fortran program with multiple subroutine be called in Matalb
Hi, I have a main program in FORTRAN which has about 10 subroutine. I want to call this main program as an executable file (using mex) in matalb. can this be done? When i create a fortran program without any subroutine in it then i am able to create an executable file for it. But when i have fortran program which calls another fortran subroutine in it then i am unable to create an executable file. do i have to write a seperate gateway subroutine for each of these 10 subroutine? Hi Prashant, I have made mex files which call other subroutines. I just put the subs at the bottom of the same...

IDL code with fortran subroutine and C linker on OSX
In nutshell, my problem is with linking all of my different language codes together. One of the languages seem to thing there should be a leading underscore on a subroutine name, and I just don't know why. Here's a more detailed explanation of what is going on. I have an IDL code, and a fortran subroutine called mainsub. I have a C linker as a go-between from IDL and fortran called field_c. They both compile fine on their own, but don't seem to want to be linked. Here is my set of compiling commands so far: f90 -c mainsub.f gcc -c field_c.c (these both work fine) gcc -bundle -fl...

call Fortran subroutine from Mathematica // use NETLink and DLL
This post explains how to call a Fortran subroutine as a DLL from Mathematica. I don't think the hints in this post exist in explicit form in the Wolfram documentation or in the MathArchive, at least so far as I could find. There is information in a post from Wolfram for how to use Mathlink via C wrappers to get to Fortran subroutines (version 3 of Mathematica? http://library.wolfram.com/infocenter/TechNotes/174/). *BUT* I think since the introduction of NETLink into Mathematica (version 6?), the matter is now much more straightforward, at least in a Windows environment. The purpo...

C call, in a Fortran subroutine, within a C main program
Hi guys, I have a main program, in C (which contains the "main" ). I have some subroutine in Fortran. There is no problems there since I know how to call back Fortran in a C program, using the following: in .c where I want my fortran sub to be called: extern void __stdcall ice(long*); .... int main(void) { .... int anInteger = 0; ice(&anInteger); .... return(0); } in the fortran: SUBROUTINE ice(theInt); INTEGER theInt .... END ok, but the question is, how to call a C function, within a fortran subroutine, previously called by the main "C" routine? That is of great i...