Modifying a library not to stop at runtime errors

Windows 10 now has a direct Linux app install which is one of several Linuxes (e.g. Opensuse, Ubuntu...), if you don't want cygwin.f
  • #1
Hello everyone, I'm trying to solve a BVP that seems to be very sensitive, for which I have to provide a starting guess and hope the program can fix it to find a solution. The program has been tested many times and it is very solid, the only problem should be that I can't find the right guess, so I decided to try all the possible ones.

The program is written in fortran 77 and is essentially a giant for loop , in which there is a bunch of math and then a set of results is given. The results of different iterations are not dependent in any way from those of a previous iteration and if certain results are met then they are saved. Sometimes, when everything works fine, the result is a series of number, but other times the procedure to fix the guess goes mental, meaning that the guess is trash, and the result is a runtime error (domain error in sqrt is usually the reason, but it must be a sqrt hidden in a fortran function because I verified that I always give real positive numbers to my sqrts).

The problem is that when the runtime error is met the program stops, but what I would like it to do is to just go to the next iteration: is there a way to do it? I thought about modifying the library MATHERRQQ, which is the one that tells the program to stop I think, but I can't even find it.
I am using Microsoft Developer Studio 77 to write the code and build it in a windows XP virtual machine on windows 10, but it's executed on Windows 10.
  • #2
When this kind of problem occurs where you have no control over the library, we should consider a scripting language that does the loop part and run a new iteration of your program whether it fails or not.

As an example, you could use the windows command shell and just repeat the program with different input arguments. Each line would be an iteration of your program run. Each line will execute when the previous one ends.
  • #3
It's been a while since I used Fortran, I take it your using Windows. I'll give you my first thoughts.
My first thought is exception handling - but I'm not sure what you have available with your current platform.

So on each iteration of the loop, spawn a task to perform the operations in the body of the for loop, then wait for it to end before continuing to the next pass through the loop.

Alternatively, you could try to investigate exactly what conditions MATHERQQ is sensitive to, and check before using that library,
  • #4
Thank you for your answers, you are proposing something very similar I think. If I understood it correctly, you are suggesting to make a program to run my program and pass it the different inputs.

I can't run it manually from cmd with different inputs, because I would need to do it about 50000 times, but could I for example rename my program to subroutine, make a new program with a for that calls the subroutine old_program(inputs), save the results in a .txt from old_program if everything works fine and link the two when I'm building them?
  • #5
Answer to your question: yes you can do that. You still did not fix the problem. Instead fix the problem:

FORTRAN 77 does not have exception handling. You can create it somewhat: Download the pdf file.

That is a lot of work.

Modern FORTRAN will take F77 code pretty much unchanged, just add error handling.

Do you absolutely have to use F77? Time warp from 40 years ago... to now. Porting your code to python, modern FORTRAN, or some other language is worth the effort so you do not hit these problems. Also consider: download cygwin (free), install it, then recompile and run your FORTRAN code (plus some error handling in the code) using the Gfortran compiler.
Manual: (free, modern, has error handling, found on cygwin download site)

Are you more Windows centric? Try:
Windows 10 now has a direct Linux app install which is one of several Linuxes (e.g. Opensuse, Ubuntu...), if you don't want cygwin.
You will need some very minor UNIX skills to use Ubuntu or the others. You can still get Linux and Gfortran - free.
IMO, the directions for install are written in a confusing way. They tell you to get the very most current update for the OS, then proceed to give you instructions for the old OS, then they mention how to do it with the newer. I'm good with both Windows and UNIX. This one had me confused for little while.
  • #6
Thank you for you suggestion Jim, but although I agree with you I'm forced to use it because the program was given to me in fortran 77 to adapt it for my master thesis, and porting it to fortan95 (or even bettere 2018) would be too long (about 3000-4000 lines) and unnecessary, I would get no points for that.

Do you think that what I proposed is feasible?
  • #7
I don’t think the port would take that long. My estimate would be about 10 days tops. I think given the number of iterations planned and the issue of program faults, I would go Jim’s route.
  • #8
I like @jedishrfu 's original suggestion best. Use a script or a program to launch a second program via the COMMAND line. It doesn't matter if it has to do that 50000 times, modern computers are pretty fast, and the running time will probably be acceptable.

You could do that with much less effort than porting the code to a modern language.
  • #9
Another alternative is to dump fortran and migrate to Matlab. You could get someon to help you move your program to it and you would then have a fantastic analytical environment. I’m not sure how long it would take though.

And here’s some info of Matlab calling f77 subroutines so that maybe Matlab could be your driver program calling your f77 code as needed.
  • #10
Guys, this is not really a program with a future, it's probably going to get dumped after my thesis. Also I don't have the time to port it, even 10 days is too much to me but it would require even more since I don't know what 60% of the program actually does in details, they are advanced math libraries, my teacher would never be favorable toward it and I still would need to use fortran because of his speed in high end computing and because I only know that, C and Matlab.

Anyway, at the end I used MATLAB to call fortran, and I passed it the necessary inputs by writing them in a .txt with MATLAB and reading it with fortran, that also saves the result in a different .txt, but the link you posted jedishrfu shows a better (probably faster) way, I will try that in the future. At the moment it seems to be working but I have to wait it finishes computing, it's been running for 20 hours straight and it's 3/4 of the way.

Suggested for: Modifying a library not to stop at runtime errors