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

Multithread QuickWin project possible in IVF10?

onkelhotte
New Contributor II
820 Views

Hi there,
the subject names my question: Is it possible to create a multithreaded QuickWin application? There is no entry for that type of project in my project properties (Fortran -> Libraries, IVF10, VS2003) andtyping /libs:qwin /threads manually wont work. Or is QuickWin a multithread application from the start?

Basicly I want to run my calculationand my plotting routines in different threads. Is that possible in a QuickWin application in general?

Thanks in advance,
Markus

0 Kudos
6 Replies
anthonyrichards
New Contributor III
820 Views

A QuickWin program is already multithreaded. Take a look at the sample programs and you will see that, after setting up any menu modifications that are wanted, the 'main' program contains an infinite do-nothing loop, which does not tie up all resources and halt thingsbecause the main work of handling menu callbacks is being done in another thread.

It would be straightforward to have a 'Calculate' menu item create a new thread which, when finished, puts up an informative message box to that effect and then terminates itself.

Data can be shared between the plotting routines and the computation thread using modules.

0 Kudos
onkelhotte
New Contributor II
820 Views
So, "all" I have to do is to place a Start Calculation entry as a menuitem, click itand thats all? I dont have to use CreateThread or something?
0 Kudos
anthonyrichards
New Contributor III
820 Views

Of course you have to supply the code to start a thread, but this is fairly easy. You use CreateThread, for example:

module ThreadGlobals
!allows storage of thread handles etc. and any other data
! that the main program may need to send to and get from the thread
INTEGER*4 HTHREAD, IDTHREAD
! Declare your variables that will be filled with your computed data
REAL(8) X(1000),Y(1000),Z(1000)
INTEGER(4) NUMVALUES
..etc..etc..
end module

SUBROUTINE MYCALLBACK(DLG,ID,CALLBACKTYPE)
...
USE THREADGLOBALS
integer(4) threadarg
..
threadarg=1 ! argument suppliedto ThreadFunc. User selects the value. Doesn't have to be used
HTHREAD=CreateThread(0,0,loc(THREADFUNC),threadarg,0,idthread)
.....
END SUBROUTINE MYCALLBACK

INTEGER(4) FUNCTION THREADFUNC(arg)
!Function containing the code to be executed in the thread
!DEC$ ATTRIBUTES VALUE :: arg
USE THREADGLOBALS
integer(4) arg
...
...add your computation code here...
...
THREADFUNC= 1! Sets exit code to 1
RETURN !The thread is automatically terminated after it returns
END FUNCTION THREADFUNC

0 Kudos
onkelhotte
New Contributor II
820 Views

Thanks Anthony,
I will try that when I have time for it...

Markus

0 Kudos
Jugoslav_Dujic
Valued Contributor II
820 Views
Simpler still, you can reuse the existing idle PROGRAM's thread. (Putting the actual long-lasting calculation in a callback would actually clog the program, as the callbacks' thread is the one who responds to repainting and command messages).

Along the following lines:

In the program:

DO WHILE (.TRUE.)
IF (bWakeUp) THEN
!Long lasting calculation
bWakeUp = .FALSE.
ELSE
CALL SLEEPQQ(0)
END IF
END DO

In some menu callback for calculation, simply set global bWakeUp to .TRUE. (and set up other parameters for calculation, if necessary). Also take care to disable UI items which could cause havoc if clicked during the process (e.g. user changes parameters in the midst of calculation).
0 Kudos
Steven_L_Intel1
Employee
820 Views
I usually prefer to have the loop sleep for at least 100 ms, if not a bit longer. You will have to balance the sleep time against how responsive you want to computation part to be. Of course, if there's nothing else going on on the system then it doesn't matter.
0 Kudos
Reply