Home > Archive > Fortran > November 2004 > Malloc (the most portable way)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Malloc (the most portable way)
|
|
| Kaci Tizi Ouzou 2004-11-26, 4:09 pm |
| Greetings all,
I am looking for the most portable way to perform a malloc. As far as
I know, fortran malloc/free is not standard in all fortran compilers.
I was thinking to link fortran code with some C code that takes care
for the malloc/free task.
Any comments are very welcome,
Kaci
| |
| Tim Prince 2004-11-26, 4:09 pm |
|
"Kaci Tizi Ouzou" <kaci_tizi_ouzou2000@yahoo.ca> wrote in message
news:68599ccc.0411261033.5519f0df@posting.google.com...
> Greetings all,
>
> I am looking for the most portable way to perform a malloc. As far as
> I know, fortran malloc/free is not standard in all fortran compilers.
>
> I was thinking to link fortran code with some C code that takes care
> for the malloc/free task.
That most often means using Cray pointers. Look up the documentation of the
compilers you wish to support which have such a feature. It was the "most
portable" way, prior to f90. There are reasons for Fortran having its own
ways to allocate and free memory, which are portable to any Fortran of the
last 10 years.
Among them: Cray pointers involve finding out which integer types on the
Fortran side work with pointer and size_t types on the C side. There are
several combinations in current use, at least 2 common varieties each for
Windows and linux. There may be more, if people persist in using Cray
pointers in f2003. "Most portable" doesn't measure up to standard.
| |
| beliavsky@aol.com 2004-11-26, 9:10 pm |
|
kaci_tizi_ouzou2000@yahoo.ca (Kaci Tizi Ouzou) wrote:
>Greetings all,
>
>I am looking for the most portable way to perform a malloc. As far as
>I know, fortran malloc/free is not standard in all fortran compilers.
>
>I was thinking to link fortran code with some C code that takes care
>for the malloc/free task.
Can you use the ALLOCATABLE arrays or POINTERs of Fortran 90/95 to do what
you need?
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
| |
| Richard Maine 2004-11-27, 3:57 pm |
| kaci_tizi_ouzou2000@yahoo.ca (Kaci Tizi Ouzou) writes:
> I am looking for the most portable way to perform a malloc. As far as
> I know, fortran malloc/free is not standard in all fortran compilers.
>
> I was thinking to link fortran code with some C code that takes care
> for the malloc/free task.
You don't mention what version of Fortran. It makes a huge difference;
dynamic allocation features were among the most significant features
added in Fortran 90. If you need to do dynamic allocation in new
code, then I *STRONGLY* recommend using a Fortran 90 or later compiler.
In Fortran 90, there are several standard-conforming and portable ways,
depending on the details of your needs. The inlude allocatable
arrays, pointer array allocation, and automatic arrays.
In Fortran 77, there really isn't a good portable way. There are
*LOTS* of issues. Frankly, my position is that it is not worth my
time to tutor people on all the intricacies of how to do this
in f77. If you are stuck maintaining existing code, then I can
understand that. But for new code use f90.
The cost in time to figure out how to do it well in f77 is greater
than the cost of even the most expensive of the commercial f90
compilers (and there are some free f90 compiler alternatives,
depending on details)
And this is so even if you value your own time at zero and just
include the cost of my time. I'm not very receptive to arguments
that amount to saying that my time isn't as valuable as other
people's money.
If you do jump into f77 approaches anyway, be aware that many
widely used compilers do not support Cray pointers. Thus any
approach that involves using Cray pointers to interface with
C allocation routines takes a pretty big portability hit from
the start. Yes, people do it, but portability suffers pretty
significantly. Note thet the set of compilers that don't support
Cray pointers includes g77... which is getting to be a pretty
significant fraction of the current f77-only compilers.
The more portable f77 approaches tend to be a pain; they end up
forcing program architecture in sometimes unnatural ways.
--
Richard Maine
email: my last name at domain
domain: summertriangle dot net
|
|
|
|
|