forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Home made multithreading (part A - the code)

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Thu May 22, 2008 11:16 pm    Post subject: Home made multithreading (part A - the code) Reply with quote

This is the code for "SERVER_A"

Code:
       OPTIONS (INTL)
       WINAPP
       PROGRAM SERVER_A
       EXTERNAL MESSAGE_FN
       INCLUDE <WINDOWS.INS>
       IA=WINIO@('%ca[Server_A code]%ww&')
       IA=WINIO@('%nc[A]%rm',MESSAGE_FN)
       END
       INTEGER FUNCTION MESSAGE_FN()
       DOUBLE PRECISION A
       INCLUDE <WINDOWS.INS>
       CALL REPLY_TO_TEXT_MESSAGE@ ('OK')
       A=0.0D0
       DO 100 I=1,100000000
       A=A+I
 100   CONTINUE
       MESSAGE_FN=1
       END


and this is the code for "CLIENT"

Code:
       OPTIONS (INTL)
       WINAPP
       PROGRAM CLIENT
       EXTERNAL GO_FN
       INCLUDE <WINDOWS.INS>
       CALL START_PPROCESS@('SERVA', ' ')
       CALL START_PPROCESS@('SERVB', ' ')
       IA=WINIO@('%ca[Client code]%ww&')
       IA=WINIO@('%nl%^BT[GO]%nc[S]',GO_FN)
       END
       INTEGER FUNCTION GO_FN()
       CHARACTER*(255) TEXT1
       INCLUDE <WINDOWS.INS>
       DO 100 I=1,10
       CALL SEND_TEXT_MESSAGE@ ('A','GO',TEXT1)
       CALL SEND_TEXT_MESSAGE@ ('B','GO',TEXT1)
 100   CONTINUE
       WRITE(*,*) 'OK'
       GO_FN=1
       END


The description follows in a separate post .....
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Thu May 22, 2008 11:27 pm    Post subject: Reply with quote

.... and now for the description

I have written 3 short programs. SERVER_A.FOR is listed in the foregoing post. It basically waits for a windows message, and when one is received, it does something useless for enough time to count. The useless thing is adding integers 1 to 10^8 to a double precision number. This takes enough to time for me to be aware of how long it takes without using a timer!

SERVER_B.FOR is essentially the same, except that its class name (in the %nc[ ] format code) is B instead of A.

CLIENT.FOR (also in the foregoing post) sets up a window, and launches SERVER_A and SERVER_B. When the "GO" button is pressed, messages are sent to both SERVER_A and SERVER_B to get going.
Without the GO button, SERVER_A and SERVER_B don't have time to initialise, and the process terminates very quickly.

Before "GO" is pressed, I use CTRL-ALT-DEL to launch the task manager, and I choose the "performance" tab to see what my cpu is doing. I have a choice of machines to run this on, with single and dual core cpus - but unfortunately, not two which are identical but for the number of cores. They are a mix of Intel and AMD.

On a single core cpu, the usage figure goes up to around 100% and stays there until the calculations are done.

On a dual core cpu, the usage figure for cpu 0 goes to about 2/3 and for cpu 1 to about 1/3. Since this is about the same as 100% load on one cpu core, it is not surprising that the run time seems about the same as on a single core machine. I have the choice in task manager to set the priority
for processes SERVER_A and SERVER_B, and also to choose whether SERVER_A and SERVER_B have access to both cpus, or just to one. If I set SERVER_A (for example) to only use cpu 0, and SERVER_B only to use cpu 1, then when I press GO, the cpu utilisation is near 100% on both cores, and the whole run becomes noticeably shorter.

It strikes me that because SEND_TEXT_MESSAGE@ "expects" a return message, we don't get to execute the next statement until the target window class "replies", although if the target class is not running, .e. the message can't be delivered, the "return to sender" counts as a reply, and the next statement is executed. Accordingly, SERVER_A and SERVER_B need to reply (with REPLY_TO_TEXT_MESSAGE@) ASAP on receipt of
their "Get going" messages.

I deduce from this simple experiment that Windows XP does split the load between cpu cores, but in a way that doesn't necessarily help anyone looking for speed.

I wrote another thread on how to do this, and here is the example. It works. I don't know whether the servers need a few big tasks or lots of little ones to optimise it all. (e.g. for FE codes, do you send "substructures" or "individual elements". My demo here doesn't transfer any data or results between processes.

I'd be interested to hear from anyone with a quad core machine (and SERVER_C and SERVER_D, obviously) if they get a speedup when the cores are allocated, and, indeed, what the default relative workload is.

Eddie
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group