Topic: Confused - Application runs sometimes but sometimes does not!!

Hello dear FORTRAN users,

I am having a strange problem with my FORTRAN application. Here are some details about my application:

- Uses ALLOCATABLE Data structures to hold information
- Interfaces with a C++ dll which returns an array pointer. I convert the C++ array pointer to FORTRAN pointer using the intrinsic method c_f_pointer
- Reads from an XML file and writes outputs to an XML file, and two text files.

The application builds without any problem and after I built it, I tried it in debug mode within SF and it runs perfectly. So today morning I just thought I will double click the application EXE. In doing so, I found out that the application is not responding. I had to go to Task manager and kill the program. I tried multiple times and everytime that happened. So just randomly, I deleted the output files created by the application and gmon.out and again double clicked the EXE. Voila, the program runs again.

It might run a few times and randomly it will freeze. Then I repeat the above process and bring the application back to life. I am really lost what is the problem here. Is it a process of bad memory management? Is it something to do with how the C++ pointer and FORTRAN pointer is handled?

I thought it could be a problem with the debug version, so I changed the project to options to no include Debug variables. The problem however exists.

Any ideas/help/suggestion is much appreciated.

Regards
Sankar

Regards
skp

Re: Confused - Application runs sometimes but sometimes does not!!

I am experiencing a not dissimilar problem.  A program that compiles and builds correctly, sometimes runs and remains alive, sometimes dies half a second after running it, with no discernable pattern to this behaviour.

It only happens when I compile and build in 64bit.
32 bit runs always.

It has many allocatable dynamic arrays, allocated according to problem size at runtime.

Jeff is currently trying to help me understand what is happening and whether the problem is in my code, in GFortran or in SF2.1.  I suspect the first two of these more than the last.  Does my description seem similar to your problem?
----
John

Re: Confused - Application runs sometimes but sometimes does not!!

John,

The description of your program seems similar to mine except that in my case the application freezes instead of crashing out. Mine also have lot of allocatable dynamic arrays. In my first working version of the program there was no interface to C++ and it ran perfectly. I did change part of the program and moved some of the repetitive calculation to the C++ dll. The problem arose after that change.

I hope this information will help Jeff.

Regards
Sankar

Regards
skp

Re: Confused - Application runs sometimes but sometimes does not!!

Just to eliminate one possible cause (in the case of my problem):

I have one small C dependency.
Its purpose is to store a date string, for the compilation date, which I can display in the program output alongside the program version string.

It is in this code:

                DateCompiled = __DATE__  ! Invokes a macro in the C language
                                                            ! as long as compiler flag -cpp is set.
                                                            ! Date will be in the form, "Feb 15 2013.

                PDAT9  = DateCompiled(5:6)//' '//
     +         DateCompiled(1:3)//' '//
     +         DateCompiled(10:11)

I tried removing this code and rebuilding.
It did not remove the problem.
---
John

Re: Confused - Application runs sometimes but sometimes does not!!

Sankar,

In your problem project, have you tried adding the following flag:

-fcheck=bounds

You might actually wish to try:

-fcheck=all

since you're passing pointers (possibly) between C++ and Fortran.  You can add the flag to "Fortran Flags" under Project Options.  Make sure to first Clean, then Build after you set the flag.

Jeff Armstrong
Approximatrix, LLC

Re: Confused - Application runs sometimes but sometimes does not!!

Jeff,

You suggesting seemed to help a bit. My call to the C++ dll is in a loop. Previously, the loop would go only once. Now at least it goes multiple times. So the change did fix something. I will keep digging and see what is going on.

Thanks for your help.

Regards
Sankar

Regards
skp

Re: Confused - Application runs sometimes but sometimes does not!!

update: I take my previous comment back!! It again is random. By luck this morning it ran multiple times. But now again it is back to where it runs only once.

I have posted the question to FORTRAN forum and see if there is any FORTRAN - C++ issue here. I will update the post if I hear something.

Regards
Sankar

Regards
skp