Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

question about efficiency of fortran in parallel environments
Thanks in advance to everyone who responds!

Over the last many years, I've developed modeling codes that solve
Maxwell's equations at low frequencies for 3D earth models. We use
these for geophysical exploration and resource evaluation.

In the past year, I've been modifying my code to run on a cluster,
using a combination of PETSc and MPI. PETSc is very nice because
it's object oriented, and it shields the user from all the details
about data communication structures, etc. It works very nicely.

One of the programmers in my company, who programs mainly in c,
has said that my program could be made more efficient if it
were converted from Fortran to C. I'm not sure I'm convinced
of this at all, but I was hoping for some feedback from people
who program in both Fortran and C, especially in parallel environments.

Other people (the PETSc programmers) have said it doesn't make any differenc
e whether I use
C or Fortran. But, we have to make a decision, and I'm afraid I
don't know the correct answer as I seem to be getting conflicting
advice. Any help would be appreciated.

Thanks in advance.

Randy Mackie

Report this thread to moderator Post Follow-up to this message
Old Post
Randall Mackie
05-27-05 09:01 PM


Re: question about efficiency of fortran in parallel environments
In article <esKdnfign_8rygrfRVn-1g@comcast.com>,
Randall Mackie <rlmackie862@yahoo.com> wrote:

> One of the programmers in my company, who programs mainly in c,
> has said that my program could be made more efficient if it
> were converted from Fortran to C.

Does he actually give any justification, or just a "my way is better"?
You can find people who will tell you almost anything, particularly if
they don't need to provide supporting evidence.

> Other people (the PETSc programmers) have said it doesn't make any differe
nce
> whether I use C or Fortran.

Hmm. Which input sounds like an unbiased one to you? I think I hear in
your posting that you already know the answer to that.

Frankly, I would not trust the advice of anyone who tells you that using
any particular language (including Fortran) is the secret to efficiency.
That is far too simplistic a viewpoint to have much connection to
reality.

By *FAR* the most important issue in terms of efficiency is the choice
of good algorithms. Algorithm selection can and does make many orders of
magnitude difference in some cases; yes I meant that "many" and I know
what an order of magnitude means. I've personally seen such cases. For a
start, since you mention parallelism, it can be a fairly major issue to
select algorithms that parallelize well.

Even when one gets down to the relatively minor issues of language
selection, it is quite possible to write horribly slow code in either C
or Fortran (or other languages), and it is also possible to write very
efficient code in either language. Plentiful examples of all cases
exist. If you know Fortran well, and know how to make Fortran code
efficient, but you don't know much about C, then you'll likely do better
in Fortran than C. The converse is also true. If your first-mentioned
programmer acquaintance knows C much better than Fortran, then perhaps
*HIS* C code is more efficient than his Fortran code; that doesn't have
much to do with the languages in general, and it doesn't have much to do
with your code.  (On the other hand, if he thinks that switching
languages is the secret to making code efficient, I might suspect that
he doesn't know how to really code efficiently in any language -
narrowness of viewpoint isn't a good start.)

There is no "magic" language that automatically makes things better. It
still takes a programmer.

You will also hear from plenty of people (possibly some on this
newsgroup) about how Fortran is more efficient than C.  Certainly many
people who are highly concerned about efficiency work in Fortran; it is
generally considered one of Fortran's strengths. But when phrased as
broadly as "Fortran is more efficient than C", I personally think that
is about as silly an argument as the one that C is more efficient than
Fortran. So I won't go into the technical details.

There is abundant direct evidence that skilled Fortran programmers can
write highly efficient code in Fortran. That much is safe to say. Anyone
who disputes that is probably saying more about their own biases than
about anything else. But there is also evidence that skilled C
programmers can write highly efficient code in C.

--
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

Report this thread to moderator Post Follow-up to this message
Old Post
Richard E Maine
05-27-05 09:01 PM


Re: question about efficiency of fortran in parallel environments
Randall Mackie wrote:

> Over the last many years, I've developed modeling codes that solve
> Maxwell's equations at low frequencies for 3D earth models. We use
> these for geophysical exploration and resource evaluation.

> In the past year, I've been modifying my code to run on a cluster,
> using a combination of PETSc and MPI. PETSc is very nice because
> it's object oriented, and it shields the user from all the details
> about data communication structures, etc. It works very nicely.

I am pretty sure MPI had both C and Fortran APIs.  Most likely
you could figure out how to call the C routines from Fortran if
needed.

> One of the programmers in my company, who programs mainly in c,
> has said that my program could be made more efficient if it
> were converted from Fortran to C. I'm not sure I'm convinced
> of this at all, but I was hoping for some feedback from people
> who program in both Fortran and C, especially in parallel environments.

It could be that the compilers have different amounts of support for it.
It might also be that a mixed C/Fortran system would make sense.
There are reasons for converting programs to a different language,
such as a language that the people working on it know better.
It doesn't sound like a convincing reason for this case.

-- glen


Report this thread to moderator Post Follow-up to this message
Old Post
glen herrmannsfeldt
05-27-05 09:01 PM


Re: question about efficiency of fortran in parallel environments
C used to be provably slower than Fortran, just on theoretical grounds.
That is, it was possible to write compilers for Fortran that could
regularly make optimizations that simply could not be applied to
the corresponding C code.  Of course, not all Fortran compilers
made full use of these possibilities. So, it has always been true
that an occasional really good C implementation might beat
the occasional really bad Fortran on corresponding code.

Some of this you could code around by writing the optimizations
yourself (forcing a given code order by making it explicit in C, for
example).  This had the divantage that different optimizations
may be better on different platforms and your hand optimized C
would have to be rewritten as you port.

Fortran's default behavior is to allow the compiler more flexibility
while C's default behavior (and, until the C99 standard, the *only*
way) does not.  With modern C is is possible to carefully write code
that matches Fortran for the "optimizability" of your program.  However,
most C (or C++, etc.) programmers still don't use such techniques and
those compilers that recognize the new features may still not fully
optimize based upon them.

All of this ignores the more subjective issues of programming style
that Rich Maine mentioned.

--
J. Giles

"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies."  -- C. A. R. Hoare




Report this thread to moderator Post Follow-up to this message
Old Post
James Giles
05-28-05 01:57 AM


Re: question about efficiency of fortran in parallel environments
Hello,

On Fri, 27 May 2005 10:24:05 -0700, Randall Mackie
<rlmackie862@yahoo.com> wrote:

<snip>

>One of the programmers in my company, who programs mainly in c,
>has said that my program could be made more efficient if it
>were converted from Fortran to C. I'm not sure I'm convinced
>of this at all, but I was hoping for some feedback from people
>who program in both Fortran and C, especially in parallel environments.

MPI is written in C, so there's an extra layer of call executed
for each MPI call.  But that's one call/return per call.

An MPI procedure execution usually involves a switch to the OS
to start a communication (on both processes), then communicating
between processes.  On a cluster, this means establishing
the logical connection between two processors.

Compared to which the extra call and return are very small.
Note that the extra call and return also apply to the C++ binding
as well.

>Other people (the PETSc programmers) have said it doesn't make any =
difference whether I use
>C or Fortran. But, we have to make a decision, and I'm afraid I
>don't know the correct answer as I seem to be getting conflicting
>advice. Any help would be appreciated.

Trying to learn a new programming language to save a clock cycle
here and there is unlikely to succeed.

As soon as you have an f03 compiler, you could call the C binding
directly from Fortran, and shave those few cycles as well.

>Thanks in advance.
>
>Randy Mackie

--=20
Cheers!

Dan Nagle
Purple Sage Computing Solutions, Inc.

Report this thread to moderator Post Follow-up to this message
Old Post
Dan Nagle
05-28-05 01:57 PM


Re: question about efficiency of fortran in parallel environments
Dan Nagle wrote:
> Hello,
>
> On Fri, 27 May 2005 10:24:05 -0700, Randall Mackie
> <rlmackie862@yahoo.com> wrote:
>
> <snip>
> 
>


Thanks to everyone who replied.

Randy

Report this thread to moderator Post Follow-up to this message
Old Post
Randall Mackie
05-28-05 08:58 PM


Re: question about efficiency of fortran in parallel environments
Dan Nagle wrote:
> Hello,
>
> On Fri, 27 May 2005 10:24:05 -0700, Randall Mackie
> <rlmackie862@yahoo.com> wrote:
>
> <snip>
> 
>
>
> MPI is written in C, so there's an extra layer of call executed
> for each MPI call.  But that's one call/return per call.
>
> An MPI procedure execution usually involves a switch to the OS
> to start a communication (on both processes), then communicating
> between processes.  On a cluster, this means establishing
> the logical connection between two processors.
>
> Compared to which the extra call and return are very small.
> Note that the extra call and return also apply to the C++ binding
> as well.
>
> 
>
>
> Trying to learn a new programming language to save a clock cycle
> here and there is unlikely to succeed.
>
> As soon as you have an f03 compiler, you could call the C binding
> directly from Fortran, and shave those few cycles as well.
>
Can't most compilers already call the C binding directly?  So there
shoulnd't be any overhead at all.

> 
>
>


--

Gary Scott
mailto:garyscott@ev1.net

Fortran Library:  http://www.fortranlib.com

Support the Original G95 Project:  http://www.g95.org
-OR-
Support the GNU GFortran Project:  http://gcc.gnu.org/fortran/index.html

Why are there two?  God only knows.


If you want to do the impossible, don't hire an expert because he knows
it can't be done.

-- Henry Ford

Report this thread to moderator Post Follow-up to this message
Old Post
Gary L. Scott
05-29-05 01:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Fortran archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:31 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.