John, this is a variation on one of the examples for the parallel processing approach. Unlike Gfortran, with FTN95 you cannot simply define a section of code to be executed in parallel. So all serial code prior to the parallel section must be within the IF( .not. IsSlaveProcess@()) THEN ...... END IF block.
It took me ages to get this example to work this way, and then I went off to do something else and never came back to it.
program main
implicit none
INCLUDE <windows.ins>
DOUBLE PRECISION start_time,end_time,sum
double precision duration, sum1
DOUBLE PRECISION,allocatable::partial_answer(:)
INTEGER(kind=4) ID
INTEGER(kind=4) k
integer(kind=4) :: np=4, i, j
!>> TEST TO FIND MAIN PROCESS. Note if IF/ENDIF is commented out, the subroutine is called NP times
IF( .not. IsSlaveProcess@()) THEN
call set_parameters(np)
ENDIF
!>> Start np-1 additional tasks. ID will be returned thus:
!>> Master task ID=0
!>> Slave task ID=1,2,3 in the different processes
ID=GetParallelTaskID@(np-1) !##
IF(ID .eq. 0) print*, 'Number of processors', np
!>> Allocate a shared array. The string 'AUTO' couples the ALLOCATE with the parallel task mechanism
ALLOCATE(partial_answer(np),SHARENAME='shared_stuff')
CALL TaskSynchronise@()
!>> Time the task using wall clock elapsed time
CALL dclock@(start_time)
sum=0d0
!>> All np processes compute the sum in an interleaved fashion
k = 10000000000_4 - ID
WHILE(k > 0)DO
sum = sum + k
k = k - np
ENDWHILE
!>> Copy the partial sum into the array shared between the processes
partial_answer(ID+1)=sum
CALL TaskSynchronise@()
CALL dclock@(end_time)
IF(ID==0)THEN
!>> We are the master task, so print out the results and the timing
sum1 = 0.d0
do i = 1, np
sum1 = sum1 + partial_answer(i)
end do
PRINT *,'Sum=',sum1
duration=end_time-start_time
PRINT *,'Parallel computation time = ',duration
ENDIF
CALL TaskSynchronise@()
!>> Kill off the slave process
IF(ID .ne. 0) STOP
DEALLOCATE(partial_answer)
END PROGRAM
subroutine set_parameters(np)
implicit none
integer(kind=4), intent(out) :: np
10 write(6,*)
write(6,*) 'Enter number of processors to use'
read(5,*) np
if (np .lt. 1) goto 10
end set_parameters