Changeset 651


Ignore:
Timestamp:
12/28/17 12:42:10 (6 years ago)
Author:
dubos
Message:

devel/unstructured : basic profiling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • codes/icosagcm/devel/src/unstructured/data_unstructured.F90

    r638 r651  
    4444  INTEGER(C_INT), BIND(C) :: comm_icosa 
    4545 
     46  INTEGER, PARAMETER :: id_pvort_only=1, id_slow_hydro=2, id_fast=3, id_coriolis=4, id_theta=5, & 
     47       id_vert_NH=6, id_solver=7, id_slow_NH=8, id_NH_geopot=9, id_vert=10, id_NH_Phi_star=11, nb_routines=11 
     48  DBL, PRIVATE :: start_time, time_spent(nb_routines) ! time spent in each kernel 
     49  INTEGER, PRIVATE :: current_id, nb_calls(nb_routines), bytes(nb_routines) ! bytes read or written be each kernel 
     50  CHARACTER(len = 10) :: id_name(nb_routines) = & 
     51       (/'pvort_only', 'slow_hydro', 'fast      ', 'coriolis  ', 'theta     ', & 
     52       'vert_NH   ', 'solver    ', 'slow_NH   ', 'NH_geopot ', 'vert      ', & 
     53       'Phi_star  '/) 
     54 
    4655CONTAINS 
    4756 
     57  !----------------------------      PROFILING      -------------------------- 
     58   
     59  SUBROUTINE init_trace() 
     60    time_spent(:)=0. 
     61    bytes(:)=0 
     62    nb_calls(:)=0 
     63  END SUBROUTINE init_trace 
     64 
     65  SUBROUTINE print_trace() 
     66    INTEGER :: id 
     67    DBL :: total_spent 
     68    total_spent=SUM(time_spent) 
     69    PRINT *, '========================= Performance metrics =========================' 
     70    PRINT *, 'Total time spent in instrumented code (seconds) :', total_spent 
     71    PRINT *, 'Name, #calls, %time, microsec/call, MB/sec'     
     72    DO id=1,nb_routines 
     73       IF(nb_calls(id)>0) PRINT *, id_name(id), nb_calls(id), INT(100.*time_spent(id)/total_spent), & 
     74            INT(1e6*time_spent(id)/nb_calls(id)), INT(1e-6*bytes(id)/time_spent(id)) 
     75    END DO 
     76    CALL init_trace() 
     77  END SUBROUTINE print_trace 
     78 
     79  SUBROUTINE enter_trace(id, nbytes) 
     80    INTEGER :: id, nbytes 
     81    current_id = id 
     82    bytes(id) = bytes(id) + nbytes 
     83    nb_calls(id)=nb_calls(id)+1 
     84    start_time = OMP_GET_WTIME() 
     85  END SUBROUTINE enter_trace 
     86 
     87  SUBROUTINE exit_trace() 
     88    DBL :: elapsed 
     89    elapsed = OMP_GET_WTIME()-start_time 
     90    IF(elapsed<0.) elapsed=0. 
     91    time_spent(current_id) = time_spent(current_id) + elapsed 
     92  END SUBROUTINE exit_trace 
    4893 
    4994  !---------------------------- CONTEXT INITIALIZATION -------------------------- 
Note: See TracChangeset for help on using the changeset viewer.