2626#include "ESMCI_Array.h"
2727
2828#include "ESMCI_TraceMacros.h" // for profiling
29+ #include "ESMCI_TraceRegion.h" // for profiling
2930
3031#include "Mesh/include/ESMCI_Mesh.h"
3132#include "Mesh/include/Legacy/ESMCI_MeshRead.h"
@@ -111,13 +112,19 @@ void ESMCI_regrid_create(
111112#define ESMC_METHOD "ESMCI_regrid_create()"
112113 Trace __trace (" FTN_X(regrid_test)(ESMCI::Grid **gridsrcpp, ESMCI::Grid **griddstcpp, int*rc" );
113114
114- // Create string describing regrid case
115- std ::string ristr ;
116- create_regrid_info_str (arraysrcpp , arraydstpp , regridMethod , ristr );
115+ // Declare local return code
116+ int localrc ;
117117
118- // Trace around whole regrid create
119- ESMCI ::TraceEventRegionEnter (ristr , NULL );
120-
118+ // Enter profile around whole regrid create
119+ std ::string ristr ;
120+ if (TraceGetProfileTypeInfo (ESMC_PROFILETYPE_REGRID ) > 0 ) {
121+ // Create string describing regrid case
122+ create_regrid_info_str (arraysrcpp , arraydstpp , regridMethod , ristr );
123+
124+ // Trace around whole regrid create
125+ ESMCI ::TraceEventRegionEnter (ristr , & localrc );
126+ if (ESMC_LogDefault .MsgFoundError (localrc , ESMCI_ERR_PASSTHRU , ESMC_CONTEXT , rc )) return ;
127+ }
121128
122129 // Dereference input variables
123130 ESMCI ::Array & srcarray = * * arraysrcpp ;
@@ -148,9 +155,6 @@ void ESMCI_regrid_create(
148155
149156 try {
150157
151- // Declare local return code
152- int localrc ;
153-
154158 // Initialize the parallel environment for mesh
155159 ESMCI ::Par ::Init ("MESHLOG" , false, VM ::getCurrent (& localrc )-> getMpi_c ());
156160 if (ESMC_LogDefault .MsgFoundError (localrc ,ESMCI_ERR_PASSTHRU ,ESMC_CONTEXT ,NULL )) throw localrc ; // bail out with exception
@@ -329,11 +333,11 @@ void ESMCI_regrid_create(
329333 }
330334
331335
332-
333- // Trace around weight generation
334- ESMCI ::TraceEventRegionEnter ("Weight generation" , & localrc );
335- if (ESMC_LogDefault .MsgFoundError (localrc ,ESMCI_ERR_PASSTHRU ,ESMC_CONTEXT ,NULL )) throw localrc ;
336-
336+ // Enter profile around weight generation
337+ if ( TraceGetProfileTypeInfo ( ESMC_PROFILETYPE_REGRID ) > 1 ) {
338+ ESMCI ::TraceEventRegionEnter ("Weight generation" , & localrc );
339+ if (ESMC_LogDefault .MsgFoundError (localrc ,ESMCI_ERR_PASSTHRU ,ESMC_CONTEXT ,NULL )) throw localrc ;
340+ }
337341
338342#ifdef PROGRESSLOG_on
339343 ESMC_LogDefault .Write ("c_esmc_regrid_create(): Entering weight generation." , ESMC_LOGMSG_INFO );
@@ -397,10 +401,11 @@ void ESMCI_regrid_create(
397401 }
398402 }
399403
400- // Trace around weight generation
401- ESMCI ::TraceEventRegionExit ("Weight generation" , & localrc );
402- if (ESMC_LogDefault .MsgFoundError (localrc ,ESMCI_ERR_PASSTHRU ,ESMC_CONTEXT ,NULL )) throw localrc ;
403-
404+ // Exit profile around weight generation
405+ if (TraceGetProfileTypeInfo (ESMC_PROFILETYPE_REGRID ) > 1 ) {
406+ ESMCI ::TraceEventRegionExit ("Weight generation" , & localrc );
407+ if (ESMC_LogDefault .MsgFoundError (localrc ,ESMCI_ERR_PASSTHRU ,ESMC_CONTEXT ,NULL )) throw localrc ;
408+ }
404409
405410 ESMCI_REGRID_TRACE_EXIT ("NativeMesh Weight Generation" );
406411
@@ -643,11 +648,12 @@ void ESMCI_regrid_create(
643648
644649 // Build the RouteHandle using ArraySMMStore()
645650 if (* has_rh ) {
646-
647- // Trace around routehandle creation
648- ESMCI ::TraceEventRegionEnter ("RouteHandle creation" , & localrc );
649- if (ESMC_LogDefault .MsgFoundError (localrc ,ESMCI_ERR_PASSTHRU ,ESMC_CONTEXT ,NULL )) throw localrc ;
650-
651+
652+ // Enter profile around routehandle creation
653+ if (TraceGetProfileTypeInfo (ESMC_PROFILETYPE_REGRID ) > 1 ) {
654+ ESMCI ::TraceEventRegionEnter ("RouteHandle creation" , & localrc );
655+ if (ESMC_LogDefault .MsgFoundError (localrc ,ESMCI_ERR_PASSTHRU ,ESMC_CONTEXT ,NULL )) throw localrc ;
656+ }
651657
652658 // Set some flags
653659 enum ESMC_TypeKind_Flag tk = ESMC_TYPEKIND_R8 ;
@@ -666,10 +672,11 @@ void ESMCI_regrid_create(
666672 ESMC_CONTEXT , NULL )) throw localrc ; // bail out with exception
667673
668674
669- // Trace around routehandle creation
670- ESMCI ::TraceEventRegionExit ("RouteHandle creation" , & localrc );
671- if (ESMC_LogDefault .MsgFoundError (localrc ,ESMCI_ERR_PASSTHRU ,ESMC_CONTEXT ,NULL )) throw localrc ;
672-
675+ // Exit profile around routehandle creation
676+ if (TraceGetProfileTypeInfo (ESMC_PROFILETYPE_REGRID ) > 1 ) {
677+ ESMCI ::TraceEventRegionExit ("RouteHandle creation" , & localrc );
678+ if (ESMC_LogDefault .MsgFoundError (localrc ,ESMCI_ERR_PASSTHRU ,ESMC_CONTEXT ,NULL )) throw localrc ;
679+ }
673680 }
674681
675682 ESMCI_REGRID_TRACE_EXIT ("NativeMesh ArraySMMStore" );
@@ -844,8 +851,12 @@ void ESMCI_regrid_create(
844851 ESMC_LogDefault .Write ("c_esmc_regrid_create(): Final return." , ESMC_LOGMSG_INFO );
845852#endif
846853
847- // Trace around whole regrid create
848- ESMCI ::TraceEventRegionExit (ristr , NULL );
854+
855+ // Exit profile around whole regrid create
856+ if (TraceGetProfileTypeInfo (ESMC_PROFILETYPE_REGRID ) > 0 ) {
857+ ESMCI ::TraceEventRegionExit (ristr , & localrc );
858+ if (ESMC_LogDefault .MsgFoundError (localrc , ESMCI_ERR_PASSTHRU , ESMC_CONTEXT , rc )) return ;
859+ }
849860
850861 // Set return code
851862 if (rc != NULL ) * rc = ESMF_SUCCESS ;
0 commit comments