ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
test_pm_bench.F90
Go to the documentation of this file.
1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3!!!! !!!!
4!!!! ParaMonte: Parallel Monte Carlo and Machine Learning Library. !!!!
5!!!! !!!!
6!!!! Copyright (C) 2012-present, The Computational Data Science Lab !!!!
7!!!! !!!!
8!!!! This file is part of the ParaMonte library. !!!!
9!!!! !!!!
10!!!! LICENSE !!!!
11!!!! !!!!
12!!!! https://github.com/cdslaborg/paramonte/blob/main/LICENSE.md !!!!
13!!!! !!!!
14!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
15!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16
28
29!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30
32
33 use pm_bench
34 use pm_test, only: test_type, LK
35 use pm_timer, only: timerCPU_type
36 use pm_timer, only: timerDAT_type
37 use pm_timer, only: timerSYS_type
38 use pm_kind, only: IK, RK, RKS, RKD, RKQ
39
40 implicit none
41
42 private
43 public :: setTest
44 type(test_type) :: test
45
47 real(RKS) :: unifsum_RKS = 0._RKS ! dummy calculation to prevent aggressive compiler optimizations.
49 real(RKD) :: unifsum_RKD = 0._RKD ! dummy calculation to prevent aggressive compiler optimizations.
51 real(RKQ) :: unifsum_RKQ = 0._RKQ ! dummy calculation to prevent aggressive compiler optimizations.
52
53!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54
55contains
56
57!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58
59 subroutine setTest()
60
62 call test%run(test_constructBench, SK_"test_constructBench")
63 call test%run(test_constructBenchMulti, SK_"test_constructBenchMulti")
64 call test%summarize()
65
66 end subroutine setTest
67
68!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69
70 function test_constructBench() result(assertion)
71 use pm_timer, only: timerCPU_type
72 use pm_timer, only: timerDAT_type
73 use pm_timer, only: timerSYS_type
74 logical(LK) :: assertion
75 type(timerCPU_type) :: TimerCPU
76 type(timerDAT_type) :: TimerDAT
77 type(timerSYS_type) :: TimerSYS
78 type(bench_type) :: bench
79 integer(IK) :: miniter_def
80 integer(IK) :: miniter
81 real(RKD) :: minsec_def
82 real(RKD) :: minsec
83
84 miniter = 100_IK
85 minsec = 0.02_RKD
86 miniter_def = 1
87 minsec_def = 0.05_RKD
88 assertion = .true._LK
89
90 TimerCPU = timerCPU_type()
91 TimerDAT = timerDAT_type()
92 TimerSYS = timerSYS_type()
93
94 bench = bench_type("testing", exec)
95 assertion = assertion .and. logical(bench%name == SK_"testing", LK)
96 call test%assert(assertion, line = int(__LINE__, IK))
97
98 TimerSYS%start = TimerSYS%time()
99 call bench%setTiming()
100 TimerSYS%delta = TimerSYS%time(since = TimerSYS%start)
101 !assertion = assertion .and. logical(TimerSYS%delta >= minsec_def, LK)
102 call test%assert(assertion, line = int(__LINE__, IK))
103 assertion = assertion .and. logical(size(bench%timing%values, kind = IK) >= miniter_def, LK)
104 call test%assert(assertion, line = int(__LINE__, IK))
105
106 bench = bench_type("testing", exec, overhead)
107 assertion = assertion .and. logical(bench%name == SK_"testing", LK)
108 call test%assert(assertion, line = int(__LINE__, IK))
109
110 call bench%setTiming()
111 assertion = assertion .and. logical(size(bench%timing%values, kind = IK) >= miniter_def, LK)
112 call test%assert(assertion, line = int(__LINE__, IK))
113
114 bench = bench_type("testing", exec, overhead, minsec = minsec)
115 assertion = assertion .and. logical(bench%name == SK_"testing", LK)
116 call test%assert(assertion, line = int(__LINE__, IK))
117 assertion = assertion .and. logical(bench%minsec == minsec, LK)
118 call test%assert(assertion, line = int(__LINE__, IK))
119
120 call bench%setTiming()
121 assertion = assertion .and. logical(size(bench%timing%values, kind = IK) >= miniter_def, LK)
122 call test%assert(assertion, line = int(__LINE__, IK))
123
124 bench = bench_type("testing", exec, overhead, minsec = minsec, miniter = miniter)
125 assertion = assertion .and. logical(bench%name == SK_"testing", LK)
126 call test%assert(assertion, line = int(__LINE__, IK))
127 assertion = assertion .and. logical(bench%minsec == minsec, LK)
128 call test%assert(assertion, line = int(__LINE__, IK))
129 assertion = assertion .and. logical(bench%miniter == miniter, LK)
130 call test%assert(assertion, line = int(__LINE__, IK))
131
132 bench = bench_type("testing", exec, overhead, minsec = minsec, miniter = miniter, timer = timerCPU_type())
133 assertion = assertion .and. logical(bench%name == SK_"testing", LK)
134 call test%assert(assertion, line = int(__LINE__, IK))
135 assertion = assertion .and. logical(bench%minsec == minsec, LK)
136 call test%assert(assertion, line = int(__LINE__, IK))
137 assertion = assertion .and. logical(bench%miniter == miniter, LK)
138 call test%assert(assertion, line = int(__LINE__, IK))
139
140 TimerCPU%start = TimerCPU%time()
141 call bench%setTiming()
142 TimerCPU%delta = TimerCPU%time(since = TimerCPU%start)
143 !assertion = assertion .and. logical(TimerCPU%delta >= minsec, LK)
144 call test%assert(assertion, line = int(__LINE__, IK))
145
146 bench = bench_type("testing", exec, overhead, minsec = minsec, miniter = miniter, timer = timerDAT_type())
147 assertion = assertion .and. logical(bench%name == SK_"testing", LK)
148 call test%assert(assertion, line = int(__LINE__, IK))
149 assertion = assertion .and. logical(bench%minsec == minsec, LK)
150 call test%assert(assertion, line = int(__LINE__, IK))
151 assertion = assertion .and. logical(bench%miniter == miniter, LK)
152 call test%assert(assertion, line = int(__LINE__, IK))
153
154 TimerDAT%start = TimerDAT%time()
155 call bench%setTiming(miniter = miniter)
156 TimerDAT%delta = TimerDAT%time(since = TimerDAT%start)
157 !assertion = assertion .and. logical(TimerDAT%delta >= minsec, LK)
158 !print *, TimerDAT%delta, minsec
159 !print *, TimerDAT%resol, bench%timer%resol
160 call test%assert(assertion, line = int(__LINE__, IK))
161 assertion = assertion .and. logical(size(bench%timing%values, kind = IK) >= miniter, LK)
162 call test%assert(assertion, line = int(__LINE__, IK))
163
164 bench = bench_type("testing", exec, overhead, minsec = minsec, miniter = miniter, timer = timerSYS_type())
165 assertion = assertion .and. logical(bench%name == SK_"testing", LK)
166 call test%assert(assertion, line = int(__LINE__, IK))
167 assertion = assertion .and. logical(bench%minsec == minsec, LK)
168 call test%assert(assertion, line = int(__LINE__, IK))
169 assertion = assertion .and. logical(bench%miniter == miniter, LK)
170 call test%assert(assertion, line = int(__LINE__, IK))
171
172 TimerSYS%start = TimerSYS%time()
173 call bench%setTiming(miniter = miniter)
174 TimerSYS%delta = TimerSYS%time(since = TimerSYS%start)
175 !assertion = assertion .and. logical(TimerSYS%delta >= minsec_def, LK)
176 call test%assert(assertion, line = int(__LINE__, IK))
177 assertion = assertion .and. logical(size(bench%timing%values, kind = IK) >= miniter, LK)
178 call test%assert(assertion, line = int(__LINE__, IK))
179
180 bench%timing = bench%getTiming(miniter = miniter)
181 assertion = assertion .and. logical(size(bench%timing%values, kind = IK) >= miniter, LK)
182 call test%assert(assertion, line = int(__LINE__, IK))
183
184 bench%timing = bench%getTiming(miniter = miniter)
185 assertion = assertion .and. logical(size(bench%timing%values, kind = IK) >= miniter, LK)
186 call test%assert(assertion, line = int(__LINE__, IK))
187
188 bench%timing = bench%getTiming(minsec = minsec, miniter = miniter)
189 assertion = assertion .and. logical(size(bench%timing%values, kind = IK) >= miniter, LK)
190 call test%assert(assertion, line = int(__LINE__, IK))
191
192 bench%timing = bench%getTiming(miniter = miniter)
193 assertion = assertion .and. logical(size(bench%timing%values, kind = IK) >= miniter, LK)
194 call test%assert(assertion, line = int(__LINE__, IK))
195
196 call bench%setTiming(miniter = miniter)
197 assertion = assertion .and. logical(size(bench%timing%values, kind = IK) >= miniter, LK)
198 call test%assert(assertion, line = int(__LINE__, IK))
199
200 call bench%setTiming(minsec = minsec)
201 call test%assert(assertion, line = int(__LINE__, IK))
202
203 call bench%setTiming(minsec = minsec, miniter = miniter)
204 assertion = assertion .and. logical(size(bench%timing%values, kind = IK) >= miniter, LK)
205 call test%assert(assertion, line = int(__LINE__, IK))
206
207 miniter = 10001_IK
208 call bench%setTiming(miniter = miniter)
209 assertion = assertion .and. logical(size(bench%timing%values, kind = IK) >= miniter, LK)
210 call test%assert(assertion, line = int(__LINE__, IK))
211
212 end function
213
214!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215
216 function test_constructBenchMulti() result(assertion)
217 use pm_io, only: display_type
218 logical(LK) :: assertion
219 type(display_type) :: disp
220 type(benchMulti_type) :: benchMulti
221
222 assertion = .true._LK
223
224 disp = display_type(file = "test_constructBenchMulti.tmp")
225
226 benchMulti= benchMulti_type([ bench_type(SK_'rng_single', procwrap_RKS, overhead_RKS) & ! LCOV_EXCL_LINE
227 , bench_type(SK_'rng_double', procwrap_RKD, overhead_RKD) & ! LCOV_EXCL_LINE
228 , bench_type(SK_'rng_quadro', procwrap_RKQ, overhead_RKQ) & ! LCOV_EXCL_LINE
229 ])
230 call test%assert(assertion, line = int(__LINE__, IK))
231 call benchMulti%showsum(unit = disp%unit) ! Display the results in a nice tabular format.
232 call test%assert(assertion, line = int(__LINE__, IK))
233 call benchMulti%showsum(unit = disp%unit, tabular = .true._LK) ! Display the results in a nice tabular format.
234 call test%assert(assertion, line = int(__LINE__, IK))
235 call benchMulti%showsum(unit = disp%unit, tabular = .false._LK) ! Display the results in a nice tabular format.
236 call test%assert(assertion, line = int(__LINE__, IK))
237 benchMulti= benchMulti_type([ bench_type(SK_'rng_single', procwrap_RKS, overhead_RKS) & ! LCOV_EXCL_LINE
238 , bench_type(SK_'rng_double', procwrap_RKD, overhead_RKD) & ! LCOV_EXCL_LINE
239 , bench_type(SK_'rng_quadro', procwrap_RKQ, overhead_RKQ) & ! LCOV_EXCL_LINE
240 ] & ! LCOV_EXCL_LINE
241 , sorted = .false. & ! LCOV_EXCL_LINE
242 )
243 benchMulti= benchMulti_type([ bench_type(SK_'rng_single', procwrap_RKS, overhead_RKS) & ! LCOV_EXCL_LINE
244 , bench_type(SK_'rng_double', procwrap_RKD, overhead_RKD) & ! LCOV_EXCL_LINE
245 , bench_type(SK_'rng_quadro', procwrap_RKQ, overhead_RKQ) & ! LCOV_EXCL_LINE
246 ] & ! LCOV_EXCL_LINE
247 , sorted = .true. & ! LCOV_EXCL_LINE
248 )
249 benchMulti= benchMulti_type([ bench_type(SK_'rng_single', procwrap_RKS, overhead_RKS) & ! LCOV_EXCL_LINE
250 , bench_type(SK_'rng_double', procwrap_RKD, overhead_RKD) & ! LCOV_EXCL_LINE
251 , bench_type(SK_'rng_quadro', procwrap_RKQ, overhead_RKQ) & ! LCOV_EXCL_LINE
252 ] & ! LCOV_EXCL_LINE
253 , repeat = 1_IK & ! LCOV_EXCL_LINE
254 )
255
256 end function
257
258!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259
260 subroutine overhead_RKS(); call random_number(unifrnd_RKS); unifsum_RKS = unifsum_RKS + unifrnd_RKS; end
261 subroutine overhead_RKD(); call random_number(unifrnd_RKD); unifsum_RKD = unifsum_RKD + unifrnd_RKD; end
262 subroutine overhead_RKQ(); call random_number(unifrnd_RKQ); unifsum_RKQ = unifsum_RKQ + unifrnd_RKQ; end
263 subroutine procwrap_RKS(); call random_number(unifrnd_RKS); unifsum_RKS = unifsum_RKS + 2._RKS**unifrnd_RKS; end
264 subroutine procwrap_RKD(); call random_number(unifrnd_RKD); unifsum_RKD = unifsum_RKD + 2._RKD**unifrnd_RKD; end
265 subroutine procwrap_RKQ(); call random_number(unifrnd_RKQ); unifsum_RKQ = unifsum_RKQ + 2._RKQ**unifrnd_RKQ; end
266
267!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
268
269 subroutine exec()
270 real :: summ
271 summ = wasteTime()
272 end subroutine
273
274 subroutine overhead()
275 end subroutine
276
277!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278
279 function wasteTime() result(summ)
280 real :: summ, Matrix(100,100)
281 call random_number(Matrix)
282 summ = sum(Matrix)
283 end function
284
285!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286
287end module test_pm_bench
Generate and return an object of type timing_type containing the benchmark timing information and sta...
Definition: pm_bench.F90:574
Time the user-specified procedure wrapper in the parent object of type bench_type and store the outpu...
Definition: pm_bench.F90:643
Time the user-specified procedure wrappers in the case vector component of the parent object of type ...
Definition: pm_bench.F90:873
This module contains abstract interfaces and types that facilitate benchmarking of different procedur...
Definition: pm_bench.F90:41
character(*, SK), parameter MODULE_NAME
Definition: pm_bench.F90:57
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter RK
The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
Definition: pm_kind.F90:543
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter RKQ
The quadru-precision real kind in Fortran mode. On most platforms, this is an 128-bit real kind.
Definition: pm_kind.F90:569
integer, parameter RKD
The double precision real kind in Fortran mode. On most platforms, this is an 64-bit real kind.
Definition: pm_kind.F90:568
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Definition: pm_kind.F90:567
This module contains a simple unit-testing framework for the Fortran libraries, including the ParaMon...
Definition: pm_test.F90:42
This module contains the timer procedures and derived types to facilitate timing applications at runt...
Definition: pm_timer.F90:99
This module contains tests of the module pm_bench.
subroutine procwrap_RKS()
logical(LK) function test_constructBenchMulti()
real function wasteTime()
subroutine procwrap_RKQ()
real(RKD) unifrnd_RKD
subroutine overhead()
logical(LK) function test_constructBench()
subroutine setTest()
subroutine overhead_RKQ()
real(RKQ) unifsum_RKQ
subroutine overhead_RKS()
real(RKD) unifsum_RKD
real(RKS) unifrnd_RKS
type(test_type) test
subroutine procwrap_RKD()
real(RKQ) unifrnd_RKQ
subroutine overhead_RKD()
subroutine exec()
real(RKS) unifsum_RKS
This is the class for creating object to perform multiple benchmarks and performance-profiling.
Definition: pm_bench.F90:735
This is the class for creating benchmark and performance-profiling objects.
Definition: pm_bench.F90:386
Generate and return an object of type display_type.
Definition: pm_io.F90:10282
This is the derived type test_type for generating objects that facilitate testing of a series of proc...
Definition: pm_test.F90:209
This is the timerCPU_type class, containing attributes and static methods for setting up a timer base...
Definition: pm_timer.F90:271
This is the timerDAT_type class, containing attributes and static methods for setting up a timer base...
Definition: pm_timer.F90:322
This is the timerSYS_type class, containing attributes and static methods for setting up a timer base...
Definition: pm_timer.F90:502
subroutine bench(sort, arraySize)