Home > Archive > Fortran > July 2006 > Multiple processes in FORTRAN
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Multiple processes in FORTRAN
|
|
| harrisrj@mit.edu 2006-07-18, 7:01 pm |
| Hi all,
I am a question about FORTRAN. So, I want my (fortran 90/95) program
to basically call two functions at once. So something like this:
CALL FUNCTION1
CALL FUNCTION2
and have the two functions be run simultaneously. Is there any way to
do that? Thanks.
| |
| highegg 2006-07-18, 7:01 pm |
|
harrisrj@mit.edu wrote:
> Hi all,
>
> I am a question about FORTRAN. So, I want my (fortran 90/95) program
> to basically call two functions at once. So something like this:
>
> CALL FUNCTION1
> CALL FUNCTION2
>
> and have the two functions be run simultaneously. Is there any way to
> do that? Thanks.
You have to use some extension to F95 to manage this. One of the
easiest to use
is OpenMP. With OpenMP, you can simply write
!$omp parallel sections
!$omp section
call function1
!$omp section
call function2
!$omp end parallel sections
another option is to use POSIX threads - more complicated, but more
powerful.
Jaroslav
| |
| Richard Edgar 2006-07-18, 7:01 pm |
| harrisrj@mit.edu wrote:
> I am a question about FORTRAN. So, I want my (fortran 90/95) program
> to basically call two functions at once. So something like this:
>
> CALL FUNCTION1
> CALL FUNCTION2
>
> and have the two functions be run simultaneously. Is there any way to
> do that? Thanks.
Within standard Fortran, no. However, if your compiler supports OpenMP,
then something like
!$OMP PARALLEL
!$OMP SECTIONS
!$OMP SECTION
CALL FUNCTION1
!$OMP SECTION
CALL FUNCTION2
!$OMP END SECTIONS
!$OMP END PARALLEL
ought to do the trick. Without further details, it's rather difficult to
give more guidance.
HTH,
Richard
| |
|
| If your compiler supports the SPAWN function, you can use it to launch
another full program, (which you can treat as a subroutine), and which
you can request to start and evolve independently (which should STOP
when finished), or run as a child process, which the calling program
waits for (by it ending with a RETURN).
In the first (independent) case you have to have a signalling
mechanism to return the results of the calculations, which could be
using a shared file or even by creating a new file, whose availablity
on closing indicates the called program has finished.
A shared file would also have to have to written with "I am working"
and "I am finished" signals.
I used shared files to allow housekeepers to enter hotel room statuses
from room telephones and terminals in floor materials centres and still
allow any hotel staff (booking, front desk, registration), to query the
situation in real time, without any sophisticated hardware and
software.
Terence Wright
| |
| Terence 2006-07-19, 7:01 pm |
| I should have pointed out that "parallel" processing with only one cpu
is only worthwhile in concept if you are very short ot time and there
is a lot of slow external i/o to perform (e.g. manual keyboard or mouse
interactions, or file searches), while you could be doing something
else with data you already have.
A single cpu only does timeslicing, like humans do while walking (or
driving) and talking. (I immediately thought of "walking and chewing
gum" and aeroplane exit steps).
There ARE multiple-cpu home computers (or transputer arrays) and
Fortran software for them (like OCCAM) to be very useful in parallel
processing. Of course large mainframe number-crunchers are now built
with thousands of cpus inside, and yes, generally use Fortran-like
source code.
Terence Wright
|
|
|
|
|