forked from LLNL/Caliper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BufferedRegionProfile for Fortran and C (LLNL#268)
* Add a Fortran RegionProfile wrapper * Add cali_begin_region() / cali_end_region() * Example updates * Enable Fortran in gitlab configs * Skip Fortran option with xlc for now * Add test for BufferedRegionProfile
- Loading branch information
Showing
31 changed files
with
858 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
program fortran_example | ||
use caliper_mod | ||
|
||
implicit none | ||
|
||
type(BufferedRegionProfile) :: rp | ||
type(ConfigManager) :: mgr | ||
|
||
integer :: i, count, argc | ||
real :: innertime, outertime, tottime | ||
|
||
logical :: ret | ||
character(len=:), allocatable :: errmsg | ||
character(len=256) :: arg | ||
|
||
! Initialize Caliper. Use cali_mpi_init() in an MPI program. | ||
call cali_init() | ||
|
||
! (Optional) create a ConfigManager object to control profiling. | ||
! Users can provide a configuration string (e.g., 'runtime-report') | ||
! on the command line. | ||
mgr = ConfigManager_new() | ||
argc = command_argument_count() | ||
if (argc .ge. 1) then | ||
call get_command_argument(1, arg) | ||
call mgr%add(arg) | ||
ret = mgr%error() | ||
if (ret) then | ||
errmsg = mgr%error_msg() | ||
write(*,*) 'ConfigManager: ', errmsg | ||
endif | ||
endif | ||
|
||
! Start configured profiling channels | ||
call mgr%start | ||
|
||
! A scope annotation. Start region 'main' | ||
call cali_begin_region('main') | ||
|
||
! Create a BufferedRegionProfile instance to query Caliper region times | ||
rp = BufferedRegionProfile_new() | ||
|
||
do i = 1, 4 | ||
! Start the region profile | ||
call rp%start() | ||
|
||
! Add region 'outer' using cali_begin_region() | ||
call cali_begin_region('outer') | ||
! Add another region 'inner' nested under 'outer' | ||
call cali_begin_region('inner') | ||
|
||
call cali_end_region('inner') | ||
call cali_end_region('outer') | ||
|
||
! Stop the region profile and fetch region times | ||
call rp%stop | ||
call rp%fetch_inclusive_region_times | ||
innertime = rp%region_time('inner') | ||
outertime = rp%region_time('outer') | ||
tottime = rp%total_region_time() | ||
|
||
write(*,*) 'Cycle ', i, ': ', tottime, ' sec' | ||
write(*,*) 'outer: ', outertime, ' sec' | ||
write(*,*) ' inner: ', innertime, ' sec' | ||
|
||
! Reset the profile | ||
call rp%clear | ||
end do | ||
|
||
! Delete the RegionProfile instance | ||
call BufferedRegionProfile_delete(rp) | ||
|
||
call cali_end_region('main') | ||
|
||
! Compute and flush output for the ConfigManager profiles. | ||
call mgr%flush | ||
call ConfigManager_delete(mgr) | ||
end program fortran_example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "caliper/caliper-config.h" | ||
|
||
#include "../../interface/c_fortran/wrapBufferedRegionProfile.h" | ||
|
||
#include "caliper/cali.h" | ||
|
||
#define _XOPEN_SOURCE | ||
#include <unistd.h> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
TEST(C_Wrapper, BufferedRegionProfile) { | ||
cali_BufferedRegionProfile rp; | ||
cali_BufferedRegionProfile_new(&rp); | ||
|
||
cali_BufferedRegionProfile_start(&rp); | ||
|
||
CALI_MARK_BEGIN("wrap.rp.outer"); | ||
CALI_MARK_BEGIN("wrap.rp.inner"); | ||
usleep(20000); | ||
CALI_MARK_END("wrap.rp.inner"); | ||
usleep(10000); | ||
CALI_MARK_END("wrap.rp.outer"); | ||
|
||
cali_BufferedRegionProfile_stop(&rp); | ||
|
||
cali_BufferedRegionProfile_fetch_exclusive_region_times(&rp); | ||
double e_tot = cali_BufferedRegionProfile_total_profiling_time(&rp); | ||
double e_reg = cali_BufferedRegionProfile_total_region_time(&rp); | ||
double e_out = cali_BufferedRegionProfile_region_time(&rp, "wrap.rp.outer"); | ||
double e_inn = cali_BufferedRegionProfile_region_time(&rp, "wrap.rp.inner"); | ||
|
||
cali_BufferedRegionProfile_fetch_inclusive_region_times(&rp); | ||
double i_tot = cali_BufferedRegionProfile_total_profiling_time(&rp); | ||
double i_reg = cali_BufferedRegionProfile_total_region_time(&rp); | ||
double i_out = cali_BufferedRegionProfile_region_time(&rp, "wrap.rp.outer"); | ||
double i_inn = cali_BufferedRegionProfile_region_time(&rp, "wrap.rp.inner"); | ||
|
||
cali_BufferedRegionProfile_delete(&rp); | ||
|
||
EXPECT_GT(e_inn, 0.0); | ||
EXPECT_GT(e_out, 0.0); | ||
EXPECT_GT(e_inn, e_out); | ||
EXPECT_GE(e_reg, e_inn + e_out); | ||
EXPECT_GE(e_tot, e_reg); | ||
|
||
EXPECT_FLOAT_EQ(e_inn, i_inn); | ||
EXPECT_FLOAT_EQ(e_reg, i_reg); | ||
EXPECT_FLOAT_EQ(e_tot, i_tot); | ||
|
||
EXPECT_GT(i_inn, 0.0); | ||
EXPECT_GT(i_out, i_inn); | ||
EXPECT_GE(i_reg, i_out); | ||
EXPECT_GE(i_tot, i_reg); | ||
} |
Oops, something went wrong.