From 9941ea84a0a0df365fbc9ef3e646bf06ab427216 Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Fri, 5 Mar 2021 09:39:48 +0100
Subject: [PATCH] Philippe 05/03/2021: budgets: measure cpu_time for budgets

---
 src/MNH/budget.f90 | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/src/MNH/budget.f90 b/src/MNH/budget.f90
index 692fe059c..36863e3ea 100644
--- a/src/MNH/budget.f90
+++ b/src/MNH/budget.f90
@@ -6,16 +6,19 @@
 ! Modifications
 !  P. Wautelet 28/01/2020: new subroutines: Budget_store_init, Budget_store_end and Budget_source_id_find in new module mode_budget
 !  P. Wautelet 17/08/2020: treat LES budgets correctly
+!  P. Wautelet 05/03/2021: measure cpu_time for budgets
 !-----------------------------------------------------------------
 
 !#################
 module mode_budget
 !#################
 
-use modd_budget, only: cbutype, nbutime, tbudgetdata
+use modd_budget,     only: cbutype, nbutime, tbudgetdata, xtime_bu, xtime_bu_process
+use modd_les_budget, only: xtime_les_bu, xtime_les_bu_process
 
 use modi_cart_compress, only: Cart_compress
 use modi_mask_compress, only: Mask_compress
+use modi_second_mnh,    only: Second_mnh
 
 use mode_msg
 
@@ -27,6 +30,7 @@ public :: Budget_store_init
 public :: Budget_store_end
 public :: Budget_store_add
 
+real :: ztime1, ztime2
 
 contains
 
@@ -42,6 +46,8 @@ subroutine Budget_store_init( tpbudget, hsource, pvars )
   call Print_msg( NVERB_DEBUG, 'BUD', 'Budget_store_init', trim( tpbudget%cname )//':'//trim( hsource ) )
 
   if ( lles_call ) then
+    call Second_mnh( ztime1 )
+
     if ( allocated( tpbudget%xtmplesstore ) ) then
       call Print_msg( NVERB_ERROR, 'BUD', 'Budget_store_init', 'xtmplesstore already allocated' )
     else
@@ -50,11 +56,17 @@ subroutine Budget_store_init( tpbudget, hsource, pvars )
     tpbudget%xtmplesstore(:, :, :) = pvars(:, :, :)
 
     tpbudget%clessource = hsource
+
+    call Second_mnh( ztime2 )
+    xtime_les_bu         = xtime_les_bu         + ztime2 - ztime1
+    xtime_les_bu_process = xtime_les_bu_process + ztime2 - ztime1
   end if
 
   ! Nothing else to do if budgets are not enabled
   if ( .not. tpbudget%lenabled ) return
 
+  call Second_mnh( ztime1 )
+
   call Budget_source_id_find( tpbudget, hsource, iid )
 
   if ( tpbudget%ntmpstoresource /= 0 ) then
@@ -91,7 +103,11 @@ subroutine Budget_store_init( tpbudget, hsource, pvars )
     end if
   end if
 
-end subroutine Budget_store_init
+  call Second_mnh( ztime2 )
+  xtime_bu         = xtime_bu         + ztime2 - ztime1
+  xtime_bu_process = xtime_bu_process + ztime2 - ztime1
+
+  end subroutine Budget_store_init
 
 
 subroutine Budget_store_end( tpbudget, hsource, pvars )
@@ -133,6 +149,8 @@ subroutine Budget_store_end( tpbudget, hsource, pvars )
   ! Nothing to do if budgets are not enabled
   if ( .not. tpbudget%lenabled ) return
 
+  call Second_mnh( ztime1 )
+
   call Budget_source_id_find( tpbudget, hsource, iid )
 
   if ( tpbudget%tsources(iid)%lenabled ) then
@@ -196,6 +214,10 @@ subroutine Budget_store_end( tpbudget, hsource, pvars )
     tpbudget%ntmpstoresource = 0
   end if
 
+  call Second_mnh( ztime2 )
+  xtime_bu         = xtime_bu         + ztime2 - ztime1
+  xtime_bu_process = xtime_bu_process + ztime2 - ztime1
+
 end subroutine Budget_store_end
 
 
@@ -221,6 +243,8 @@ subroutine Budget_store_add( tpbudget, hsource, pvars )
   ! Nothing to do if budgets are not enabled
   if ( .not. tpbudget%lenabled ) return
 
+  call Second_mnh( ztime1 )
+
   call Budget_source_id_find( tpbudget, hsource, iid )
 
   if ( tpbudget%tsources(iid)%lenabled ) then
@@ -240,6 +264,10 @@ subroutine Budget_store_add( tpbudget, hsource, pvars )
     end if
   end if
 
+  call Second_mnh( ztime2 )
+  xtime_bu         = xtime_bu         + ztime2 - ztime1
+  xtime_bu_process = xtime_bu_process + ztime2 - ztime1
+
 end subroutine Budget_store_add
 
 
-- 
GitLab