C $Header: /home/ubuntu/mnt/e9_copy/MITgcm_contrib/mlosch/cg2d_sr_bench/code/the_model_main.F,v 1.1 2009/11/29 11:02:03 mlosch Exp $ C $Name: $ CBOI C This is a dummy model main to initialize and invoke the cg2d routine. Most of the C guts of the model have been taken out. C C CLW, clwolfe@ucsd.edu November 2009 C CEOI #include "AD_CONFIG.h" #include "PACKAGES_CONFIG.h" #include "CPP_OPTIONS.h" CBOP C !ROUTINE: THE_MODEL_MAIN C !INTERFACE: SUBROUTINE THE_MODEL_MAIN(myThid) IMPLICIT NONE C !DESCRIPTION: \bv C *==========================================================* C | SUBROUTINE THE_MODEL_MAIN C | o Master controlling routine for model using the MITgcm C | UV parallel wrapper. C *==========================================================* C | THE_MODEL_MAIN is invoked by the MITgcm UV parallel C | wrapper with a single integer argument "myThid". This C | variable identifies the thread number of an instance of C | THE_MODEL_MAIN. Each instance of THE_MODEL_MAIN works C | on a particular region of the models domain and C | synchronises with other instances as necessary. The C | routine has to "understand" the MITgcm parallel C | environment and the numerical algorithm. Editing this C | routine is best done with some knowledge of both aspects. C | Notes C | ===== C | This variant of THE_MODEL_MAIN has been stripped down to C | call difference variants of the conjugate gradient solver C | and compare results and performance C *==========================================================* C \ev C !USES: C == Global variables === #include "SIZE.h" #include "EEPARAMS.h" #include "PARAMS.h" C !INPUT/OUTPUT PARAMETERS: C == Routine arguments == C myThid - Thread number for this instance of the routine. INTEGER myThid C !LOCAL VARIABLES: C == Local variables == C Note: Under the multi-threaded model myCurrentIter and C myCurrentTime are local variables passed around as routine C arguments. Although this is fiddly it saves the need to C impose additional synchronisation points when they are C updated. C myCurrentTime - Time counter for this thread C myCurrentIter - Iteration counter for this thread INTEGER myCurrentIter _RL myCurrentTime logical exst logical lastdiva _RL firstResidual1,lastResidual1 _RL firstResidual2,lastResidual2 INTEGER numIters1, numIters2 INTEGER ks,i,nIter _RL cg2d_b(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) _RL cg2d_x1(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) _RL cg2d_x2(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) _RL port_rand CEOP c-- set default: lastdiva = .TRUE. #ifdef ALLOW_DEBUG IF (debugMode) CALL DEBUG_ENTER('THE_MODEL_MAIN',myThid) #endif C-- This timer encompasses the whole code CALL TIMER_START('ALL [THE_MODEL_MAIN]',myThid) #ifdef ALLOW_DEBUG IF (debugMode) CALL DEBUG_CALL('INITIALISE_FIXED',myThid) #endif C-- Set model configuration (fixed arrays) CALL TIMER_START('INITIALISE_FIXED [THE_MODEL_MAIN]',myThid) CALL INITIALISE_FIXED( myThid ) CALL TIMER_STOP ('INITIALISE_FIXED [THE_MODEL_MAIN]',myThid) myCurrentTime = startTime myCurrentIter = nIter0 #ifdef ALLOW_DEBUG IF (debugMode) CALL DEBUG_CALL('THE_MAIN_LOOP',myThid) #endif C-- Call time stepping loop of full model C firstResidual1 = port_rand(1618033.+myProcId) DO I=1, nTimeSteps nIter = nIter0 + I C-- Initialize RHS for 2DCG solver. CALL INI_RHS(cg2d_b,cg2d_x1,cg2d_x2,myThid) firstResidual1=0. lastResidual1=0. firstResidual2=0. lastResidual2=0. numIters1=cg2dMaxIters numIters2=cg2dMaxIters CALL TIMER_START('CG2D [THE_MODEL_MAIN]',myThid) CALL CG2D(cg2d_b, & cg2d_x1, & firstResidual1, & lastResidual1, & numIters1, & myThid ) CALL TIMER_STOP('CG2D [THE_MODEL_MAIN]',myThid) _BEGIN_MASTER(myThid) WRITE(*,'(1x,a,i5,2(4x,a,e15.7),(4x,a,i5))') 'CG2D: ', i, & 'firstResidual =',firstResidual1, & 'lastResidual =',lastResidual1, & 'numIters =',numIters1 _END_MASTER(myThid) CALL TIMER_START('CG2D_SR [THE_MODEL_MAIN]',myThid) CALL CG2D_SR(cg2d_b, & cg2d_x2, & firstResidual2, & lastResidual2, & numIters2, & myThid ) CALL TIMER_STOP('CG2D_SR [THE_MODEL_MAIN]',myThid) _BEGIN_MASTER(myThid) WRITE(*,'(1x,a,i5,2(4x,a,e15.7),(4x,a,i5))') 'CG2D_SR: ', i, & 'firstResidual =',firstResidual2, & 'lastResidual =',lastResidual2, & 'numIters =',numIters2 _END_MASTER(myThid) ENDDO CALL WRITE_REC_XY_RL('rhs',cg2d_b,1,1,myThid) CALL WRITE_REC_XY_RL('soln',cg2d_x1,1,1,myThid) CALL WRITE_REC_XY_RL('soln_sr',cg2d_x2,1,1,myThid) #ifdef ALLOW_MNC IF (useMNC) THEN C Close all open NetCDF files _BEGIN_MASTER( mythid ) CALL MNC_FILE_CLOSE_ALL( myThid ) _END_MASTER( mythid ) ENDIF #endif C-- This timer encompasses the whole code CALL TIMER_STOP ('ALL [THE_MODEL_MAIN]',myThid) C-- Write timer statistics IF ( myThid .EQ. 1 ) THEN CALL TIMER_PRINTALL( myThid ) CALL COMM_STATS ENDIF C-- Check threads synchronization : CALL BAR_CHECK( 9, myThid ) #ifdef ALLOW_DEBUG IF (debugMode) CALL DEBUG_LEAVE('THE_MODEL_MAIN',myThid) #endif RETURN END