Silverfrost Forums

Welcome to our forums

Parallel processing

6 Nov 2008 9:57 #3968

Hi (and sorry for my question - up to now I really have no idea about it):

nowadys more and more PCs have more than one processor. What is the way to use all of them? Is it necessary to modify the code in the way that the programme subdivide the work, or does the operating system manage this? In other words: If I use my 'standard' fortran code, will only one single processor run the programme?

Thanks in advance and best regards, Wilfried

6 Nov 2008 11:28 #3970

If I use my 'standard' fortran code, will only one single processor run the programme?

Yes !

However it is possible for a FTN95 written application to spawn more processes using CISSUE to issue a DOS command prompt to start another FTN95 application or alternatively START_PPROCESS@ could also be used to start another process and return immediately to the iniating application.

BUT it would take some very clever programming to split up the job so that more than one process could work on it simultaneously, then monitor all the processes and wait for them all to complete (perhaps by each process writing a log file), marshall all the results and assemble them back together.

If you intend to this, let us know how you get on and Good luck!

6 Nov 2008 9:57 #3976

hmmm... but first thank you!

Part of my work is image processing what simply means that operations must be done on millions of pixels. For instance (to use a very simple example) imagine that for each pixel I would like to carry out the function new_value = 2*old_value. Also imagine that the image size is 10000 by 10000 pixels. If I have 4 processors I'ld like to handle the work like processor 1 = lines 1 ... 2500, processor 2 = lines 2501 ... 5000 and so on.

As far as I understood, first I must get information about the number of processors (how to do this?). After that I must split the work using (say) four times start_pprocess@, then waiting until the last processor has done the work, then matching the results together to a new image. Is that right?

Again thanks in advance... Wilfried

7 Nov 2008 8:41 #3978

Wilfried,

first I must get information about the number of processors (how to do this?).

Excuse me if I appear rude but that is simple, using environmental variables as follows:-

      CHARACTER*10 getenv@

      READ(getenv@('NUMBER_OF_PROCESSORS'),*)NPROC

After that I must split the work using (say) four times start_pprocess@, then waiting until the last processor has done the work, then matching the results together to a new image. Is that right?

Yes, that's right! Sounds like a very interesting piece of work, I'm sure that it can be done. I've used start_pprocess@ myself to launch third party applications (FEA solvers like CalculiX), I then have a loop which checks the status of output and log files from these third party applications, when they complete my application then imports results from these other products. I have successfully done this for most of the leading FEA solvers, and it gives the impression that your own software is working seamlessly with the other packages which of course it is. 😛

7 Nov 2008 9:05 #3980

Thank you very much!

Sorry for my questions... May be I need more precise information about ftn95. I only have the manuals salfordftn95.pdf and clearwin.pdf. For instance, the fortran manual tells me about a function getenv@ but didn't show any list of possible valid parameters (like 'number_of_processors' you wrote).

Also, within these two documents no information is given about start_pprocess@. I don't what to disturb you too much - so, can you please give me an address or so to get more actual manuals? It will be the best that I first read them carefully before going on.

Best regards, Wilfried

7 Nov 2008 10:08 #3982

start_pprocess@ is described in the current ftn95.chm under start_process@.

7 Nov 2008 10:36 #3983

Wilfried,

You will not find a list of arguments for getenv@ in the manuals, it is not necessary.

Instead go to:-

Start --> Settings --> Control Panel --> System Icon --> Advanced tab --> Environment variables

and you will see a list of them with their current values, gentenv@ can retrieve the value of any of them.

If that has whetted your appetite then you can get even more information about your OS and hardware using the function REGOPENKEYEX to extract stuff from the registry (but thats more involved than using getenv@ !)

7 Nov 2008 1:46 #3984

Thanks again!

Paul: I tried to get the ftn95.chm from your website (Documentation > Silverfrost FTN95 User Guide), but in vain. I tried it in my office, I tried it at home, I tried to read and also to download, but all times an error occurs. I really have no idea what happened...

John: I found the variables and it works. Thanks!

Best regards, Wilfried

8 Nov 2008 1:48 #3986

Not all that long ago I posted all the code necessary to get a whole bunch of processes running. You also have to make sure that they run on separate cpu cores. You can do that too. The facilities to get all the separate applications to talk to each other are standard things in Clearwin. I thought that no-one was interested!

Search for 'Home made multithreading'

Eddie

8 Nov 2008 4:11 #3987

Hi friend from the saxonian coast, THAT'S WHAT I NEED;-) Thanks, I'm very interested and I will report about my work - and disturb you with questions if necessary ...

Wilfried

10 Nov 2008 12:21 #3992

Very interesting, indeed... I made the first tests and I hope that I begin to understand the principles.

As far as I see up to now, I must split my programme into several executables, right? Or is there any alternative to devide the work to several processors from within a single executable? What I mean is something like this:

getenv@(number_of_processors)
if (number .eq. 2) then
  switch_to_processor@(1)

  tell_him_what_to_do

  switch_to_processor@(2)

  tell_him_what_to_do
end if

...or similar, from within a single programme. But may be I have not yet understand and this is not possible.

Thanks for your patience and best regards, Wilfried

10 Nov 2008 12:52 #3993

Hi Wilfried,

In the Dawn of Time, Salford FTN77 supported multithreading. Later, following sale of soul to devil (which happened in 2 stages, and which is what I call the move to Windows!), multithreading is not officially supported with Clearwin. Whether or not it is with .NET, I can't tell you.

The principles involved in running your Clearwin application on a multiprocessor machine is that up to a point, Windows does appear to use all the cores, but in a way that gives you no real nett benefit - although you can run multiple applications to raise the load on each cpu core.

Each window is a sort of independent application - again, up to a point. I could find no way of making particular windows attach to particular cpu cores, or even to different ones, although some sort of allocation and scheduling must be done by windows.

What I was able to do was to create separate standalone applications that could talk to each other. Then, I found that I could associate particular applications with a given cpu core (through task manager). I imagine that one could also create a flurry of mini-applications that would cause Windows to associate some with one core, and others with another core. Indeed, you can obtain (buy!) software that makes the association of a program with a particular core 'persistent' (I wrote a post in reply to a 'core duo' discussion thread on this).

In your example, you wouldn't get any benefit, because you wouldn't 'switch_to_processor@(2)' until processor 1 had completed the tasks set in 'tell_him_what_to_do@' - whereas if you start_pprocess@, you do move to the next statement (you don't with 'start_process@'). In order to do what you want within a single application, there needs to be specific facilities for multi-threading, and they don't exist. However, a set of intercommunicating applications are, by definition, multithreaded, and Clearwin does have that.

In a multithreaded system, you have to be able to handle the results coming back in an order that is different from the tasks being issued. The phrase that springs to mind is 'client-server computing'. As that is american, the 'client' is a customer in a restaurant, the 'server' is a waiter. If the client has only one server, then the dishes ordered are likely to be served in the correct order. However, if there are several servers, and one is sent for starter, one for main course, and one for wine etc, then the dishes could be delivered in any sequence!

This analogy is nested, for example, the server is effectively the client for the chefs in the kitchen.

With conventional Fortran, there is only one server, and you don't ask him for the main course until after the starter has been delivered!

I think you need a different mindset to cope with multithreading, whichever way you do it.

Eddie

10 Nov 2008 1:15 #3995

Thank you, Eddie.

You wrote 'Later, following sale of soul to devil (... which is what I call the move to Windows!), ... '. Really nice to read that other people have the same feeling about that like me. But of course, we will not stop the time 😉

Wilfried

10 Nov 2008 4:20 #3999

Hi Wilfried,

That was just a throwaway expression. If it wasn't Windows, it would be GEM, or possibly some other Mac lookalike. FTN77 with DBOS wasn't just the fastest and 'bestest' at compiling, it also had multithreading (although why, I never worked out), excellent graphics (up to VGA), loads of extra facilities like virtual memory AND some of the fastest run times for the compiled code.

I don't think that the Windows way of working is always the best. It certainly doesn't fit easily with Fortran. Quite obviously, Salford/Silverfrost did a fantastic job with Clearwin, but there are some loose ends.

The tradeoff for getting Clearwin is that you no longer have the fastest EXE. If that bothers you, write the front-end in FTN95/Clearwin and the back-end in (say) Intel Fortran. Run the back-end using start_pprocess@ ...

Regards

Eddie

10 Nov 2008 10:23 #4000

Eddie,

As I recall the graphics under DOS and FTN77 was only limited by the graphics card you had installed. I recall getting SVGA and beyond with FTN77 and certainly a lot better than Win3.1 could achieve!

cheers John

11 Nov 2008 9:35 #4002

Hi John,

I recollect it being said that you could go higher, but never achieved it. My Win 3.1 PC went up to 1024x768 on a £500 Sony monitor.

Eddie

15 Nov 2008 7:26 #4014

Wilfried, Yes, multicore CPUs WORK in parallel wery nicely. Look at multithreading example in FTN95 release.

I also posted here simplified to the extreme version of this example a while ago, make a search for it, so now even your dog can do parallelization.

15 Nov 2008 6:22 #4015

Hmm... Dan, I found a thread from you concerning parallel processing (click), but I didn't found useful code there (?). In one of your postings you mentioned commands like %em (???) or %we ('write in exponential form'; ???). May be I found the wrong thread.

In the moment I think that parallel processing is a bit more complicated (hope that I'll be wrong). Of course the operating system spreads different programmes to different processors if present, but parallelsation of a single programme is in the responsibility of the developer.

I made first tests with call_pprocess@ which seems to give good results. Of course there remains some work for a good logistic between the single threads. What I'm missing are commands to spread the work to several processors from within a single programme (exe file). Nevertheless, even if it will be necessary to subdivide my software into several executables, I will use parallelisation as soon as possible. In my work I deal with image processing and up to now in some subroutines I offer a 'batch' mode saying that image per image will be processed one after another. I think that these are places where parallelisation will give a significant increase of speed.

Have a nice weekend, Wilfried

15 Nov 2008 8:14 (Edited: 16 Nov 2008 5:18) #4017

Quoted from Wilfried Linder Hmm... Dan, I found a thread from you concerning parallel processing (click), but I didn't found useful code there (?). In one of your postings you mentioned commands like %em (???) or %we ('write in exponential form'; ???). May be I found the wrong thread.

You've mentioned wrong post. Here they are: https://forums.silverfrost.com/Forum/Topic/898&highlight= https://forums.silverfrost.com/Forum/Topic/882&highlight= and about environment variables and number of processors https://forums.silverfrost.com/Forum/Topic/770&highlight=

Compilation: ftn95 Filename.FOR /clr /link /free /multi_threaded

You can see in Task Manager how threads grab one, two or more processors.

(https://forums.silverfrost.com/Forum/Topic/759&postdays=0&postorder=asc&start=0)), but I didn't found useful code there (?). In one of your postings you mentioned commands like %em (???) or %we ('write in exponential form'; ???). May be I found the wrong thread.

You've mentioned wrong post. Here they are: https://forums.silverfrost.com/Forum/Topic/898&highlight= https://forums.silverfrost.com/Forum/Topic/882&highlight= and about environment variables and number of processors https://forums.silverfrost.com/Forum/Topic/770&highlight=

Compilation: ftn95 Filename.FOR /clr /link /free /multi_threaded

You can see in Task Manager how threads grab one, two or more processors.

[quote:1983b06c99]In the moment I think that parallel processing is a bit more complicated (hope that I'll be wrong).

If your imaging processing data is sequential and can be easily devided into multiple independent streams (which is usually true) then multithreading is obvious solution and it can be done using FTN95 with its rich extensions. The call_process@ can be also used but is not particularly elegant way of doing that, though may be more portable. Above mentioned way is much more cool

15 Nov 2008 9:27 #4018

Thanks a lot, Dan. OK, this week I will implement your ideas. Regards to Frisco from cold and foggy Germany, Wilfried

Please login to reply.