Example 4 Example 6 Back to GPTL home page

Example 5: Fortran use of gptlprocess_namelist() to set GPTL options

This example is a Fortran code which uses convenience function gptlprocess_namelist() to set GPTL options instead of inserting calls to gptlsetoption() into the application code. The main advantage to this approach is that it avoids having to recompile and relink the application code when changing GPTL options.

nlreader.F90:

program nlreader use gptl implicit none integer :: ret ret = gptlsetoption (gptlverbose, 1) write(6,*)'nlreader: Testing gptlprocess_namelist...' call gptlprocess_namelist ('gptlnl', 1, ret) if (ret /= 0) then write(6,*)'Failure' call exit (1) end if ! Now turn off verbosity ret = gptlsetoption (gptlverbose, 0) ret = gptlinitialize () ret = gptlstart ('main') ret = gptlstop ('main') ret = gptlpr (0) write(6,*)'Success' end program nlreader
Next are the contents of the namelist file. Note that verbose = 1, which results in printout when each namelist variable is set. The namelist group name must always be gptlnl. The equivalent library call is commented next to each namelist setting.

gptlnl:

&gptlnl ! These settings are all the opposite of the default wall = .false. ! gptlsetoption (gptlwall,0) cpu = .true. ! gptlsetoption (gptlcpu,1) abort_on_error = .true. ! gptlsetoption (gptlabort_on_error,1) overhead = .true. ! gptlsetoption (gptloverhead,1) depthlimit = 5 ! gptlsetoption (gptldepthlimit,5) verbose = .true. ! gptlsetoption (gptlverbose,1) percent = .true. ! gptlsetoption (gptlpercent,1) ! Comment out persec and multiplex so "nlreader" test won't fail even if ! PAPI unavailable ! persec = .false. ! gptlsetoption (gptlpersec,0) ! multiplex = .true. ! gptlsetoption (gptlmultiplex,1) dopr_preamble = .false. ! gptlsetoption (gptldopr_preamble,0) dopr_threadsort = .false. ! gptlsetoption (gptldopr_threadsort,0) dopr_multparent = .false. ! gptlsetoption (gptldopr_multparent,0) dopr_collision = .false. ! gptlsetoption (gptldopr_collision,0) ! utr, print_method, and eventlist use character variables instead of integer ! to avoid "magic number" settings in the namelist utr = 'nanotime' ! gptlsetutr (gptlnanotime) print_method = 'full_tree' ! gptlsetoption (gptlprintmethod, gptlfull_tree) !print_method = 'first_parent' ! gptlsetoption (gptlprintmethod, gptlfirst_parent) !print_method = 'last_parent' ! gptlsetoption (gptlprintmethod, gptllast_parent) !print_method = 'most_frequent'! gptlsetoption (gptlprintmethod, gptlmost_frequent) ! List of events to count. PAPI_FP_OPS is a PAPI event, and GPTL_CI is a ! PAPI-based derived event. ! Comment out eventlist so "nlreader" test won't fail even if PAPI unavailable ! eventlist = 'PAPI_FP_OPS','GPTL_CI' /
Now compile and run:
% gfortran nlreader.F90 -o nlreader -I${GPTL}/include -I${GPTL}/lib -lgptlf -lgptl % ./nlreader
Here's the output:
GPTLsetoption: boolean verbose = 1 GPTLsetoption: boolean abort_on_error = 1 GPTLsetoption: boolean wallstats = 0 GPTLsetoption: cpustats = 1 GPTLsetoption: depthlimit = 1 GPTLsetoption: boolean percent = 1 GPTLsetoption: boolean dopr_preamble = 0 GPTLsetoption: boolean dopr_threadsort = 0 GPTLsetoption: boolean dopr_multparent = 0 GPTLsetoption: boolean dopr_collision = 0 GPTLsetutr: underlying wallclock timer = nanotime GPTLsetoption: print_method = full_tree gptlprocess_namelist: skipping check for PAPI-based events because GPTL was built without PAPI support

Explanation of the above output

Each namelist setting results in a call to GPTLsetoption() or GPTLsetutr() with the listed value. The output appears because verbose was set to true.
Example 4 Example 6 Back to GPTL home page