This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Flushing libgfortran from C


On 03/03/2011 12:37 AM, Yuri Gribov wrote:
Hi all,

Perhaps this is a well known issue but I could not find suitable
solution on the web. Here is my problem.

Some of you may know about the Co-array Fortran 2.0 project in Rice
university. CAF translates it's input files to an ordinary Fortran and
then uses gfortran (4.4 in my case) to compile them (libgfortran is
linked as shared library). CAF's runtime system is written in C so
main() looks like:

int main() {
   CAF_INIT();
   MAIN__();
   CAF_EXIT();
}

The problem is that CAF_EXIT does _exit() internally (don't ask me
why) which bypasses all registered exit handlers including
libgfortran's destructor (cleanup in runtime/main.c). This seems to
cause problems with Fortran IO: I tried all sorts of fflushes, fsyncs
and sleeps in CAF_EXIT but neither of them makes libgfortran print
it's internal buffers. This results in empty stdout on most of the CAF
programs on my platform (even simple Hello world fails to print).

If I change _exit to exit or gfortran to ifort everything prints fine.

Does this sound reasonable? Is this a known IO problem/feature?

Is there any way to workaround this i.e. to ask libgfortran to flush
(from C program)? I know about `call flush()' and environment
variables but these really solve different problems and would not be
useful in CAF's case.

Are the Fortran side files being explicitly closed or are you counting on implicitly closing on exit?


From your description, it seems the C code is existing before the Fortran code.

Jerry


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]