This module contains procedures and generic interfaces for splitting arrays of various types at the specified instances of occurrence of pattern.
More...
This module contains procedures and generic interfaces for splitting arrays of various types at the specified instances of occurrence of pattern.
- Benchmarks:
Benchmark :: The runtime performance of setSplit for scalar vs. vector input sep
argument. ⛓
4 use iso_fortran_env,
only:
error_unit
13 integer(IK) :: fileUnit
14 integer(IK) ,
parameter :: NSIZE
= 15_IK
15 integer(IK) ,
parameter :: NBENCH
= 2_IK
16 integer(IK) :: arraySize(NSIZE)
17 logical(LK) :: dummy
= .true._LK
18 integer(IK) ,
allocatable :: array(:)
19 integer(IK) ,
parameter :: sep(
1)
= 0_IK
20 type(bench_type) :: bench(NBENCH)
21 type(cvi_type),
allocatable :: ArraySplit(:)
23 bench(
1)
= bench_type(name
= SK_
"scalar_sep", exec
= scalar_sep , overhead
= setOverhead)
24 bench(
2)
= bench_type(name
= SK_
"vector_sep", exec
= vector_sep , overhead
= setOverhead)
26 arraySize
= [(
2_IK**isize, isize
= 1_IK, NSIZE )]
28 write(
*,
"(*(g0,:,' '))")
29 write(
*,
"(*(g0,:,' '))")
"scalar_sep() vs. vector_sep()"
30 write(
*,
"(*(g0,:,' '))")
32 open(newunit
= fileUnit, file
= "main.out", status
= "replace")
34 write(fileUnit,
"(*(g0,:,','))")
"arraySize", (bench(i)
%name, i
= 1, NBENCH)
36 loopOverArraySize:
do isize
= 1, NSIZE
38 write(
*,
"(*(g0,:,' '))")
"Benchmarking with size", arraySize(isize)
39 allocate(array(arraySize(isize)))
42 bench(i)
%timing
= bench(i)
%getTiming(minsec
= 0.05_RK)
46 write(fileUnit,
"(*(g0,:,','))") arraySize(isize), (bench(i)
%timing
%mean, i
= 1, NBENCH)
48 end do loopOverArraySize
49 write(
*,
"(*(g0,:,' '))") dummy
50 write(
*,
"(*(g0,:,' '))")
60 subroutine setOverhead()
65 subroutine initialize()
70 dummy
= dummy
.and. size(ArraySplit,
kind = IK)
== 1_IK
73 subroutine scalar_sep()
76 call setSplit(ArraySplit, array, sep(
1))
80 subroutine vector_sep()
84 call setSplit(ArraySplit, array, sep)
Return the parts of the input array split at the requested occurrences of the input sep.
Generate and return an object of type timing_type containing the benchmark timing information and sta...
This module contains procedures and generic interfaces for splitting arrays of various types at the s...
This module contains abstract interfaces and types that facilitate benchmarking of different procedur...
This module contains the derived types for generating allocatable containers of scalar,...
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
integer, parameter RK
The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
This is the class for creating benchmark and performance-profiling objects.
This is the derived type for generating a container of a vector component of type integer of default ...
Example Unix compile command via Intel ifort
compiler ⛓
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example Windows Batch compile command via Intel ifort
compiler ⛓
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
Example Unix / MinGW compile command via GNU gfortran
compiler ⛓
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Postprocessing of the benchmark output ⛓
3import matplotlib.pyplot
as plt
9methods = [
"scalar_sep",
"vector_sep"]
11df = pd.read_csv(
"main.out")
17ax = plt.figure(figsize = 1.25 * np.array([6.4,4.6]), dpi = 200)
21 plt.plot( df[
"arraySize"].values
26plt.xticks(fontsize = fontsize)
27plt.yticks(fontsize = fontsize)
28ax.set_xlabel(
"Array Size", fontsize = fontsize)
29ax.set_ylabel(
"Runtime [ seconds ]", fontsize = fontsize)
30ax.set_title(
"Splitting array with sep(1) (scalar) vs. sep(1:1) (vector).\nLower is better.", fontsize = fontsize)
34plt.grid(visible =
True, which =
"both", axis =
"both", color =
"0.85", linestyle =
"-")
35ax.tick_params(axis =
"y", which =
"minor")
36ax.tick_params(axis =
"x", which =
"minor")
44plt.savefig(
"benchmark.scalarSep_vs_vectorSep.runtime.png")
50ax = plt.figure(figsize = 1.25 * np.array([6.4,4.6]), dpi = 200)
53plt.plot( df[
"arraySize"].values
54 , np.ones(len(df[
"arraySize"].values))
59plt.plot( df[
"arraySize"].values
60 , df[
"vector_sep"].values / df[
"scalar_sep"].values
64plt.xticks(fontsize = fontsize)
65plt.yticks(fontsize = fontsize)
66ax.set_xlabel(
"Array Size", fontsize = fontsize)
67ax.set_ylabel(
"Runtime compared to scalar_sep()", fontsize = fontsize)
68ax.set_title(
"Runtime Ratio: split with sep(1:1) / split with sep(1).\nLower means faster. Lower than 1 means faster than scalar_sep.", fontsize = fontsize)
72plt.grid(visible =
True, which =
"both", axis =
"both", color =
"0.85", linestyle =
"-")
73ax.tick_params(axis =
"y", which =
"minor")
74ax.tick_params(axis =
"x", which =
"minor")
75ax.legend ( [
"scalar_sep",
"vector_sep"]
82plt.savefig(
"benchmark.scalarSep_vs_vectorSep.runtime.ratio.png")
Visualization of the benchmark output ⛓
Benchmark moral ⛓
- The procedures under the generic interface setSplit take both scalar and vector
sep
arguments.
As evidenced by the above benchmark, when the input sep
is vector of length 1
, it is much faster, up to 4X, to pass sep
as a scalar instead of a whole array of length 1
.
Note that this benchmark is likely irrelevant to removing substrings from Fortran strings.
- Test:
- test_pm_arraySplit
- Todo:
- Normal Priority: A benchmark comparing the performance of output index array vs. output jagged array would be informative here.
Final Remarks ⛓
If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.
-
If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
-
If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.
This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.
- Copyright
- Computational Data Science Lab
- Author:
- Fatemeh Bagheri, Wednesday 12:20 AM, October 13, 2021, Dallas, TX