C************************************************************************ C C FILE: linda_array.fl C OTHER FILES: make.linda_array.fl C DESCRIPTION: C In this simple example, the master task initiates numer of tasks C indicated by user input. It then places the initialized array into C tuple space along with tuples describing portions of the arrays for C the workers to update. C C Each worker task will retrieve a tuple indicating a portion of C the array for it to update. It then performs a simple value C assignment to each of its elements. The value assigned to each C element is simply that element's index in the array+1. C Each worker task then places its portion of the array back to tuple C space for the master to retrieve and continues retrieving work C assignments until it retrieves a tuple telling it to stop. C C As the master receives back each portion of the array, selected C elements are displayed. When it has received the entire array, C it puts a "poison pill" into tuple space notifying the workers to C stop. C C AUTHOR: Rosanne Arnowitz C LAST REVISED: 4/7/94 Rosanne Arnowitz C ************************************************************************** subroutine real_main implicit none integer ARRAYSIZE, MAXWORKERS parameter (MAXWORKERS = 20) parameter (ARRAYSIZE = 1000) integer numworkers, index, i integer chunksize, nbr_chunks integer data(ARRAYSIZE), result(ARRAYSIZE) integer length, id C ************************ initializations ******************************** C Get the number of tasks from the user. Then c define the number of worker tasks and the array partition size as chunksize. C ******************************************************************** numworkers=0 do while ((numworkers .gt. MAXWORKERS) .or. (numworkers .le. 1)) write (*,*) 'Enter number of workers between 1 and ', + MAXWORKERS read (*,*) numworkers enddo chunksize = 100 C *************************** master task **************************** print *, '************ Starting LINDA ARRAY Example ************' C Initialize the array do 20 i=1, ARRAYSIZE data(i) = 0 20 continue C put it out there out ('init_array', data) C Start the worker tasks do 30 i=1, numworkers write(*,*) 'Starting worker task', i eval('worker', worker(i)) 30 continue C Put out the work assignments index = 1 nbr_chunks = ARRAYSIZE/chunksize do 40 i=1, nbr_chunks out ('my_section', index, chunksize) index = index + chunksize 40 continue C Get results and display a few sample values do 50 i=1, numworkers in('result_index', ?id, ?index) in('result_data', index, ?result(index):length) write(*,*) '------------------------------------------' write(*,*) 'MASTER: Sample results from worker task ', id write(*,*) ' result(', index, ')=', result(index) write(*,*) ' result(', index+10, ')=', result(index+10) write(*,*) ' result(', index+20, ')=', result(index+20) 50 continue C Tell the workers to stop by giving them a chunksize = 0 do 60 i=1, numworkers out ('my_section', 0, 0) 60 continue write(*,*) 'MASTER: All Done!' end C ************************ worker task ************************************ subroutine worker(id) implicit none integer index integer MAX parameter (MAX = 1000) integer data(MAX) integer chunksize, id, i C Get the initialized array from tuple space rd ('init_array', ? data) C Head of infinite loop - stops when workers receives notification of C no more work to do 100 continue C Get the index into array to process and the chunksize. in ('my_section', ?index, ? chunksize) C Check to see if there is any more work to do if (chunksize .eq. 0) then goto 900 endif C Do a simple value assignment to each of my array elements do 50 i=index, index + chunksize - 1 data(i) = i + 1 50 continue C Send my results back to the master out ('result_index', id, index) out ('result_data', index, data(index):chunksize) C Do it all again goto 100 900 continue return end