Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor I
2 Views

Crash on return from subroutine

This is a weird problem.  Fortran subroutine A calls B.  B calls C.  C calls a c++ routine that spawns several processes.

Those processes complete, and C terminates them.  C returns to B.  B returns to A.

In debug mode all is well.  The release version crashes when B returns to A.  "Access violation reading location ...".

Any thoughts as to what is going on?  The code is huge, so I can't list it here.  I put a statement that writes to a window when B returns.  It never gets there.

How can I diagnose what is going wrong?  As I said, weird.

0 Kudos
5 Replies
Highlighted
New Contributor III
2 Views

You should study Mixed

You should study Mixed Language Programming

https://software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-mixed-language-progr...

Crash is caused by different conventions of calling routines in Fortran and C.

I have found some samples at

https://software.intel.com/en-us/node/611723

0 Kudos
Highlighted
New Contributor I
2 Views

While that is a good

While that is a good suggestion, be aware that my code calls c++ all over the place and has been working just fine for years.  So I think I got the calling conventions under control.

What's different this time is the c++ spawning other processes.  If I disable that step everything works as it should.

So the question is, why would spawing and then killing those processes cause a return from Fortran to Fortran to crash.  There are no calling conventions at play there.

0 Kudos
Highlighted
New Contributor III
2 Views

I have following suggestions

I have following suggestions then:

1. Program crashes during return from B to A? Or let's say code write(*,*) 'Return' can be executed after C++ call?

   If it crashes during return then problem should be in stack corruption - i.e. wrong calling convention.

   If it crashes after return, some of spawned process probably manipulated some pointer to your fortran data. Is it possible that some process can write out of bounds of your Fortran arrays?

2. Acces violation reading location ... shows some nonzero address?

3. Try to enable spawning another processes step by step and find which causes the error. Then try to comment parts of this code to see which routine causes the problem.

0 Kudos
Highlighted
Valued Contributor II
2 Views

I agree with Jakub, is clear

I agree with Jakub, is clear case of Stack corruption IMO. Mismatched call parameters or calling conventions. Also mismatch intent in args e.g. trying to modify something passed as a constant.

0 Kudos
Highlighted
2 Views

>>So the question is, why

>>So the question is, why would spawing and then killing those processes cause a return from Fortran to Fortran to crash

Add to Jakub's advice is to spawn the processes as you do now, however, setup these process such that they do not do anything productive. If you are structured to kill these processes as opposed to join with them, then place them in a innocuous spin loop. Leave the original compute code in place such that should this test configuration result in your application not crashing, then you can one-by-one enable each of these processes original code to see where the problem occurs.

>>and has been working just fine for years

This is often an indication that the code my have worked by accident rather than by design. IOW the juxtaposition of code and data were such that errant writes were not exposed by means of crash or abnormal behavior of the application.

Jim Dempsey

0 Kudos