I have a legacy code/simulation model that I am using with Intel Visual Fortran/Visual Studio 2012 for a numerical experiment. The experiment needs the simulation model to be run 1000 times with different initial conditions. The problem is during the simulation the 1000 models need to communicate with each other for calculating a variance between the changing outputs (the models are independent the rest of the time). Doing this outside of the model or stopping and restarting the model is not an option, so I need to find a way to communicate between the 1000 model runs at various points of the simulation.
A gross example of one program run would be
PROGRAM SIMMODEL !This do loop progresses through time for this sim model DO I=1,100 !PROCESS STUFF !CALCULATE STUFF IF(MOD(I,10).EQ.0)THEN !USE INFORMATION BETWEEN THE 1000 SIMULATION RUNS AT THE SAME INTERATION TO CALCULATE A VARIANCE !APPLY VARIANCE TO ALL 1000 SIMULATION MODELS END IF !CALCULATE MORE STUFF !START LOOP OVER AGAIN END DO END PROGRAM
My thought is that since CoArrays are similar to MPI where the entire program is cloned that it would be ideal to for INTEL FORTRAN to make a CoArray of length 1000 and use that for communicating when the variance needs to be calculated.
The problem is how to manage the images such that only 8 (for an 8 core processor) run at a time and stop/wait for the rest of the images until they all reach the IF(MOD(I,10).EQ.0) to exchange information.
Similar to the previous code:
FROM COMMAND PROMPT:
AND RUN THE FOLLOWING:
PROGRAM SIMMODEL REAL:: SHARED_INFO[*], VAR[*] !IS NOW LENGTH 1000 FROM THE "set FOR_COARRAY_NUM_IMAGES=1000" !This do loop progresses through time for this sim model DO I=1,100 !LOOP PROGRESSES USING ONLY 8 IMAGES UNTIL IF(MOD(I,10).EQ.0) IS TRUE, then the next 8 starts and this continues until all 1000 images have made it to IF(MOD(I,10).EQ.0). Then the variance is calculated and then 8 images continue one and the process repeats again until all 1000 images are at the next IF(MOD(I,10).EQ.0). !PROCESS STUFF !CALCULATE STUFF IF(MOD(I,10).EQ.0)THEN !WAIT FOR ALL 1000 IMAGES REACH THIS POINT AND USE INFORMATION BETWEEN THE 1000 SIMULATION RUNS AT THE SAME INTERATION TO CALCULATE A VARIANCE FROM SHARED_INFO !APPLY VARIANCE TO ALL 1000 SIMULATION MODELS WITH VAR[*] !START SENDING IN INTERVALS OF 8 IMAGES THROUGH THE MODEL END IF !CALCULATE MORE STUFF !START LOOP OVER AGAIN END DO END PROGRAM
What this would do is allow for a legacy code to be run multiple times with minimal modification and be a cool way of overloading a CoArray.
Another option is to clone the program and run 1000 independent models, but I have no clue how to get FORTRAN to pause/wait/transmit information ammongst 1000 independent programs.
Thanks for all the help and comments as always!