Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28546 Discussions

How to call a routine asynchronously in Fortran?

tms15
Beginner
422 Views

Could anybody help or comment?

I created a windows dialog form. Also, a console is created for output. I click on a CALCULATE button. This starts a multi-variable chi-square minimization routine. The results of chi-square minimization are written to the console iteration by iteration. This can take several minutes for a complicated numerical problem. I created another button INTERRUPT to stop minimization when it starts diverging. However, the problem is that my minimization routine works synchronously, therefore it does not return control to the dialog and I cannot click INTERRUPT. Therefore, I need the minimization routine to run asynchronously, so that the control returns to the dialog and I could press INTERRUPT.

I did a work around by reading input from a keyboard once per iteration, so I can interrupt this way. But it is an ugly and old-fashion solution.

Thank you - Tom Semkow

0 Kudos
2 Replies
Paul_Curtis
Valued Contributor I
422 Views
Your situation is very common and easily addressed in Windows by putting the calculation code in a separate thread, so that the UI remains in the main program thread and thus always active. When the user signals to start or stop the calculation (ie, a button press or whatever from the dialog), that sets a flag in the threadproc which then allows the calculation code to proceed. If your calculation activity involves iteration, the flag can be checked within the calculation loop so an exit signal sent from the UI will be instantly responded to. The threadproc containing the calculational code should be in a module which USEs the global variables defining the calculation (difficult to pass arguments directly to a Windows threadproc). I am just now unable to add a code sample since this forum has been so thoroughly degraded (no more paste-in code window, can't upload .f90 or .for files -- who would ever want to do that in a Fortran forum?), but I will somehow provide more details if you need them.
0 Kudos
tms15
Beginner
422 Views
Thank you Paul for your insight. I am not such an experienced Windows programmer. Would you, please, describe how this threadproc works? I would appreciate a few lines of code, if possible. You may send it to tms15@health.state.ny.us. Thanks - Tom Semkow
0 Kudos
Reply