This module contains procedures and generic interfaces for removing a pattern from arrays of various types at the specified instances of occurrence of pattern.
More...
This module contains procedures and generic interfaces for removing a pattern from arrays of various types at the specified instances of occurrence of pattern.
- Benchmarks:
Benchmark :: The runtime performance of setRemoved for scalar vs. vector input pattern
argument. ⛓
4 use iso_fortran_env,
only:
error_unit
12 integer(IK) :: fileUnit
13 integer(IK) ,
parameter :: NSIZE
= 15_IK
14 integer(IK) ,
parameter :: NBENCH
= 2_IK
15 integer(IK) :: arraySize(NSIZE)
16 logical(LK) :: dummy
= .true._LK
17 integer(IK) ,
allocatable :: Array(:)
18 integer(IK) ,
parameter :: pattern(
1)
= 0_IK
19 type(bench_type) :: bench(NBENCH)
21 bench(
1)
= bench_type(name
= SK_
"scalarPattern", exec
= scalarPattern , overhead
= setOverhead)
22 bench(
2)
= bench_type(name
= SK_
"vectorPattern", exec
= vectorPattern , overhead
= setOverhead)
24 arraySize
= [(
2_IK**isize, isize
= 1_IK, NSIZE )]
26 write(
*,
"(*(g0,:,' '))")
27 write(
*,
"(*(g0,:,' '))")
"scalarPattern() vs. vectorPattern()"
28 write(
*,
"(*(g0,:,' '))")
30 open(newunit
= fileUnit, file
= "main.out", status
= "replace")
32 write(fileUnit,
"(*(g0,:,','))")
"arraySize", (bench(i)
%name, i
= 1_IK, NBENCH)
34 loopOverArraySize:
do isize
= 1, NSIZE
36 write(
*,
"(*(g0,:,' '))")
"Benchmarking with size", arraySize(isize)
37 allocate(Array(arraySize(isize)))
40 bench(i)
%timing
= bench(i)
%getTiming(minsec
= 0.05_RK)
44 write(fileUnit,
"(*(g0,:,','))") arraySize(isize), (bench(i)
%timing
%mean, i
= 1_IK, NBENCH)
46 end do loopOverArraySize
47 write(
*,
"(*(g0,:,' '))") dummy
48 write(
*,
"(*(g0,:,' '))")
58 subroutine setOverhead()
63 subroutine initialize()
68 dummy
= dummy
.and. size(Array,
kind = IK)
< 1_IK
71 subroutine scalarPattern()
78 subroutine vectorPattern()
Return the remaining parts of the input array as a sequence after removing the input pattern at the r...
Generate and return an object of type timing_type containing the benchmark timing information and sta...
This module contains procedures and generic interfaces for removing a pattern from arrays of various ...
This module contains abstract interfaces and types that facilitate benchmarking of different procedur...
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.
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 = [
"scalarPattern",
"vectorPattern"]
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(
"Removing array segments with pattern(1) (scalar) vs. pattern(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.setRemoved-scalarPattern_vs_vectorPattern.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[
"vectorPattern"].values / df[
"scalarPattern"].values
64plt.xticks(fontsize = fontsize)
65plt.yticks(fontsize = fontsize)
66ax.set_xlabel(
"Array Size", fontsize = fontsize)
67ax.set_ylabel(
"Runtime compared to scalarPattern()", fontsize = fontsize)
68ax.set_title(
"Runtime Ratio: Remove pattern(1:1) / Remove pattern(1).\nLower means faster. Lower than 1 means faster than scalarPattern.", 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 ( [
"scalarPattern",
"vectorPattern"]
82plt.savefig(
"benchmark.setRemoved-scalarPattern_vs_vectorPattern.runtime.ratio.png")
Visualization of the benchmark output ⛓
Benchmark moral ⛓
- The procedures under the generic interface setRemoved take both scalar and vector
pattern
arguments.
As evidenced by the above benchmark, when the input pattern
is vector of length 1
, it is much faster, up to 4X, to pass pattern
as a scalar instead of a whole array of length 1
.
Note that this benchmark is likely irrelevant to removing substrings from Fortran strings.
Benchmark :: The runtime performance of getRemoved vs. setRemoved ⛓
4 use iso_fortran_env,
only:
error_unit
12 integer(IK) :: fileUnit
13 integer(IK) ,
parameter :: NSIZE
= 12_IK
14 integer(IK) :: arraySize(NSIZE)
15 logical(LK) :: dummy
= .true._LK
16 character(:, SK),
allocatable :: array
17 character(
*, SK),
parameter :: pattern
= "a"
18 type(bench_type),
allocatable :: bench(:)
20 bench
= [
bench_type(name
= SK_
"setRemoved", exec
= setRemoved, overhead
= setOverhead)
&
21 ,
bench_type(name
= SK_
"getRemoved", exec
= getRemoved, overhead
= setOverhead)
&
23 arraySize
= [(
2_IK**isize, isize
= 1_IK, NSIZE )]
25 write(
*,
"(*(g0,:,' '))")
26 write(
*,
"(*(g0,:,' '))")
"setRemoved() vs. getRemoved()"
27 write(
*,
"(*(g0,:,' '))")
29 open(newunit
= fileUnit, file
= "main.out", status
= "replace")
31 write(fileUnit,
"(*(g0,:,','))")
"arraySize", (bench(i)
%name, i
= 1,
size(bench,
1,
IK))
33 loopOverArraySize:
do isize
= 1, NSIZE
35 write(
*,
"(*(g0,:,' '))")
"Benchmarking with size", arraySize(isize)
37 do i
= 1,
size(bench,
1,
IK)
38 bench(i)
%timing
= bench(i)
%getTiming(minsec
= 0.05_RK)
41 write(fileUnit,
"(*(g0,:,','))") arraySize(isize), (bench(i)
%timing
%mean, i
= 1,
size(bench,
1,
IK))
43 end do loopOverArraySize
44 write(
*,
"(*(g0,:,' '))") dummy
45 write(
*,
"(*(g0,:,' '))")
55 subroutine setOverhead()
60 subroutine initialize()
61 array
= repeat(pattern, arraySize(isize))
65 dummy
= dummy
.and. 0_IK < len(array,
IK)
69 subroutine setRemoved()
78 subroutine getRemoved()
Generate and return an allocatable array containing the remaining parts of the input array as a seque...
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 = [
"setRemoved",
"getRemoved"]
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(
"setRemoved() vs. getRemoved()\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.getRemoved_vs_setRemoved.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[
"getRemoved"].values / df[
"setRemoved"].values
64plt.xticks(fontsize = fontsize)
65plt.yticks(fontsize = fontsize)
66ax.set_xlabel(
"Array Size", fontsize = fontsize)
67ax.set_ylabel(
"Runtime compared to setRemoved()", fontsize = fontsize)
68ax.set_title(
"getRemoved / setRemoved\nLower means faster. Lower than 1 means faster than setRemoved().", 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 ( [
"setRemoved",
"getRemoved"]
82plt.savefig(
"benchmark.getRemoved_vs_setRemoved.runtime.ratio.png")
Visualization of the benchmark output ⛓
Benchmark moral ⛓
- The procedures under the generic interface getRemoved are functions while the procedures under the generic interface setRemoved are subroutines.
From the benchmark results, it appears that the functional interface performs slightly less efficiently than the subroutine interface, despite the two algorithms having the same implementation.
- Note that this benchmark does not even include the cost of repeated reallcations, that is, the allocation of
Removed
happen only once in all tests.
- Note that this benchmark considers the worst-case scenario where all elements of the input
array
match the input pattern
and must be therefore, removed.
- Test:
- test_pm_arrayRemove
- Bug:
Status: Unresolved
Source: Intel Classic Fortran Compiler ifort
version 2021.2.0
Description: The Intel Classic Fortran Compiler ifort
version 2021.2.0 has a bug for use
ing the following two modules simultaneously in the implementation of the procedures in this module,
Sort the input scalar string or contiguous vector in ascending order, or return the sorted indices of...
Generate and return a vector of unique values in the input array.
This module contains procedures and generic interfaces for various sorting tasks.
This module contains procedures and generic interfaces for finding unique values of an input array of...
The following is example error message from the Intel Classic Fortran Compiler ifort
,
pm_arrayRemove@routines@setRemoved_D1.inc.F90(196): error #6405: The same named entity from different modules and/or program units cannot be referenced. [UNIQUE]
if (present(unique)) unique_def = unique
----------------------------^
Searching this error on the web points to the possibility that the internal representation of entities by Intel Classic Fortran Compiler ifort
has a naming conflict.
Remedy (as of ParaMonte Library version 2.0.0): For now, the remedy was to isolate the use of one of the modules to exactly where it is needed, like,
block
InstanceNew
= getUnique(InstanceNew(
1:lenInstanceNew))
end block
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