Skip to content

Commit 9a6f083

Browse files
authored
Merge pull request plumed#1307 from Iximiel/nit/longlonglog-dict
A faster parser
2 parents 8ec372b + 77b7932 commit 9a6f083

File tree

19 files changed

+958
-95
lines changed

19 files changed

+958
-95
lines changed

CHANGES/v2.11.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
This page contains changes that will end up in 2.11
44

5-
__Changes relevant for users:__
5+
### Changes relevant for users:
66

77
- When using [MOLINFO](MOLINFO.md) with the `WHOLE` flag, PBCs in the following actions will be reconstructed using a minimum spanning tree based on the coordinates stored in the MOLFILE reference pdb.
88

9+
### Changes relevant for developers:
10+
11+
- The inputlines now are parsed using a dictionary instead of an array. This speeds up the parsing of massive input lines. It is not possible anymore to register lowercase keywords and the developer must always specify the keywords completely as uppercase while parsing in the action constructor. There are no differences for the user, apart the entry in the manual for the DEBUG action: the user can still specify lowercase and mixed case keywords in the input file.

configure

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ enable_af_cuda
754754
enable_af_cpu
755755
enable_libtorch
756756
enable_libmetatomic
757+
enable_linuxperf
757758
enable_openacc
758759
enable_openmp
759760
'
@@ -1459,6 +1460,8 @@ Optional Features:
14591460
--enable-af_cpu enable search for arrayfire_cpu, default: no
14601461
--enable-libtorch enable search for libtorch, default: no
14611462
--enable-libmetatomic enable search for libmetatomic, default: no
1463+
--enable-linuxperf enable activate the compile options for a more
1464+
accurate report with perf on linux, default: no
14621465
--enable-openacc enable search for openacc (use PLUMED_ACC_TYPE and
14631466
PLUMED_ACC_GPU for controlling the settings),
14641467
default: no
@@ -3254,6 +3257,24 @@ fi
32543257

32553258

32563259

3260+
linuxperf=
3261+
# Check whether --enable-linuxperf was given.
3262+
if test "${enable_linuxperf+set}" = set; then :
3263+
enableval=$enable_linuxperf; case "${enableval}" in
3264+
(yes) linuxperf=true ;;
3265+
(no) linuxperf=false ;;
3266+
(*) as_fn_error $? "wrong argument to --enable-linuxperf" "$LINENO" 5 ;;
3267+
esac
3268+
else
3269+
case "no" in
3270+
(yes) linuxperf=true ;;
3271+
(no) linuxperf=false ;;
3272+
esac
3273+
3274+
fi
3275+
3276+
3277+
32573278
openacc=
32583279
# Check whether --enable-openacc was given.
32593280
if test "${enable_openacc+set}" = set; then :
@@ -3287,7 +3308,6 @@ if test -z "$CXXFLAGS"
32873308
then
32883309
CXXFLAGS=-O3
32893310
fi
3290-
32913311
# this is a list of common compilers
32923312
compilers="g++ c++ cxx icpc"
32933313
c_compilers="gcc cc icc"
@@ -5215,6 +5235,103 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
52155235

52165236
fi
52175237

5238+
# useful for having a clearer (and correct) flamegraph in linux
5239+
if test $linuxperf = true
5240+
then
5241+
5242+
save_CXXFLAGS="$CXXFLAGS"
5243+
CXXFLAGS="$CXXFLAGS -fno-omit-frame-pointer"
5244+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -fno-omit-frame-pointer" >&5
5245+
$as_echo_n "checking whether $CXX accepts -fno-omit-frame-pointer... " >&6; }
5246+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
5247+
/* end confdefs.h. */
5248+
5249+
int
5250+
main ()
5251+
{
5252+
5253+
;
5254+
return 0;
5255+
}
5256+
_ACEOF
5257+
if ac_fn_cxx_try_compile "$LINENO"; then :
5258+
5259+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
5260+
/* end confdefs.h. */
5261+
5262+
int
5263+
main ()
5264+
{
5265+
5266+
;
5267+
return 0;
5268+
}
5269+
_ACEOF
5270+
if ac_fn_cxx_try_link "$LINENO"; then :
5271+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
5272+
$as_echo "yes" >&6; }
5273+
else
5274+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not linking" >&5
5275+
$as_echo "not linking" >&6; }; CXXFLAGS="$save_CXXFLAGS"
5276+
fi
5277+
rm -f core conftest.err conftest.$ac_objext \
5278+
conftest$ac_exeext conftest.$ac_ext
5279+
5280+
else
5281+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
5282+
$as_echo "no" >&6; }; CXXFLAGS="$save_CXXFLAGS"
5283+
5284+
fi
5285+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
5286+
5287+
5288+
save_CXXFLAGS="$CXXFLAGS"
5289+
CXXFLAGS="$CXXFLAGS -gdwarf"
5290+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -gdwarf" >&5
5291+
$as_echo_n "checking whether $CXX accepts -gdwarf... " >&6; }
5292+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
5293+
/* end confdefs.h. */
5294+
5295+
int
5296+
main ()
5297+
{
5298+
5299+
;
5300+
return 0;
5301+
}
5302+
_ACEOF
5303+
if ac_fn_cxx_try_compile "$LINENO"; then :
5304+
5305+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
5306+
/* end confdefs.h. */
5307+
5308+
int
5309+
main ()
5310+
{
5311+
5312+
;
5313+
return 0;
5314+
}
5315+
_ACEOF
5316+
if ac_fn_cxx_try_link "$LINENO"; then :
5317+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
5318+
$as_echo "yes" >&6; }
5319+
else
5320+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not linking" >&5
5321+
$as_echo "not linking" >&6; }; CXXFLAGS="$save_CXXFLAGS"
5322+
fi
5323+
rm -f core conftest.err conftest.$ac_objext \
5324+
conftest$ac_exeext conftest.$ac_ext
5325+
5326+
else
5327+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
5328+
$as_echo "no" >&6; }; CXXFLAGS="$save_CXXFLAGS"
5329+
5330+
fi
5331+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
5332+
5333+
fi
5334+
52185335
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX declares c++17 support" >&5
52195336
$as_echo_n "checking whether $CXX declares c++17 support... " >&6; }
52205337
cat confdefs.h - <<_ACEOF >conftest.$ac_ext

configure.ac

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ PLUMED_CONFIG_ENABLE([af_cuda],[search for arrayfire_cuda],[no])
324324
PLUMED_CONFIG_ENABLE([af_cpu],[search for arrayfire_cpu],[no])
325325
PLUMED_CONFIG_ENABLE([libtorch],[search for libtorch],[no]) #added by luigibonati
326326
PLUMED_CONFIG_ENABLE([libmetatomic],[search for libmetatomic],[no])
327+
PLUMED_CONFIG_ENABLE([linuxperf],[activate the compile options for a more accurate report with perf on linux],[no])
327328
PLUMED_CONFIG_ENABLE([openacc],[search for openacc (use PLUMED_ACC_TYPE and PLUMED_ACC_GPU for controlling the settings)],[no])
328329

329330
AC_ARG_VAR(SOEXT,[extension of dynamic libraries (so/dylib)])
@@ -341,7 +342,6 @@ if test -z "$CXXFLAGS"
341342
then
342343
CXXFLAGS=-O3
343344
fi
344-
345345
# this is a list of common compilers
346346
compilers="g++ c++ cxx icpc"
347347
c_compilers="gcc cc icc"
@@ -433,6 +433,13 @@ then
433433
PLUMED_CHECK_CXXFLAG([-Wold-style-cast])
434434
fi
435435

436+
# useful for having a clearer (and correct) flamegraph in linux
437+
if test $linuxperf = true
438+
then
439+
PLUMED_CHECK_CXXFLAG([-fno-omit-frame-pointer])
440+
PLUMED_CHECK_CXXFLAG([-gdwarf])
441+
fi
442+
436443
AC_MSG_CHECKING([whether $CXX declares c++17 support])
437444
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
438445
#if __cplusplus < 201703L
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ../../scripts/test.make

regtest/basic/rt-make-FSUM/config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type=make
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include "plumed/tools/Tools.h"
2+
#include <iostream>
3+
#include <fstream>
4+
#include <iomanip>
5+
#include <string>
6+
using namespace PLMD;
7+
8+
class tee {
9+
//TODO:: put this tee into a common test utilities lib
10+
std::ofstream ofs;
11+
public:
12+
tee(std::string filename) : ofs(filename) {}
13+
template<typename T>
14+
tee& operator<<(const T& t) {
15+
ofs<<t;
16+
std::cout <<t;
17+
return *this;
18+
}
19+
};
20+
21+
template<typename T>
22+
using FSUM=PLMD::Tools::FastStringUnorderedMap<T>;
23+
24+
int main() {
25+
try {
26+
tee out("output");
27+
FSUM<int> mymap;
28+
//insertions
29+
std::string addr;
30+
for (int i=0; i<90; i+=10) {
31+
addr=std::to_string(i);
32+
mymap[addr]= i;
33+
}
34+
{
35+
//This tests that conv will actually insert a "90\0"
36+
//and not a"900" with not null char at the end
37+
std::string tmp = "90123456";
38+
std::string_view k {tmp.c_str(),2};
39+
mymap[k] = 90;
40+
}
41+
for (const auto & x: {
42+
"90", "0", "10","20","30","40","50","60","70","80"
43+
} ) {
44+
auto kk = mymap.find(x);
45+
plumed_assert(kk != mymap.end())
46+
<<"\""<< x << "\" should have been inserted";
47+
out <<std::left<< std::setw(3) << x << mymap[x] <<"\n";
48+
}
49+
} catch(PLMD::Exception &e) {
50+
std::cerr << "Exception:" << e.what() << "\n";
51+
}
52+
return 0;
53+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
90 90
2+
0 0
3+
10 10
4+
20 20
5+
30 30
6+
40 40
7+
50 50
8+
60 60
9+
70 70
10+
80 80
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ../../scripts/test.make
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type=make
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#include "plumed/tools/Tools.h"
2+
#include <fstream>
3+
#include <iomanip>
4+
#include <iostream>
5+
6+
using namespace PLMD;
7+
8+
class tee {
9+
//TODO:: put this tee into a common test utilities lib
10+
std::ofstream ofs;
11+
public:
12+
tee(std::string filename) : ofs(filename) {}
13+
template<typename T>
14+
tee& operator<<(const T& t) {
15+
ofs<<t;
16+
std::cout <<t;
17+
return *this;
18+
}
19+
};
20+
21+
int main() {
22+
try {
23+
//NOTE:: We are simply checking that gw has the expected behaviour
24+
tee out("output");
25+
for (auto test : {
26+
"{abcd},{a b d}","a,b,c,d","{1,2,3},4,5,{6}",
27+
"@ndx:{file1 second}","@ndx:file,@ndx:{file 1 second}",
28+
"@replicas:{1,2,3} {0,0,0} {2,4,6}",
29+
"{1 @replicas:{2 0 4} 3}"
30+
}) {
31+
out << std::quoted(test)<< '\n';
32+
gch::small_vector<std::string_view> gws ;
33+
Tools::getWordsSimple(gws,test,", \t\n");
34+
auto gw = Tools::getWords(test,", \t\n");
35+
for(auto x : gws ) {
36+
37+
out <<"\tgws:"<< std::quoted(x) << "\n";
38+
}
39+
for(auto x : gw ) {
40+
out <<"\tgw :"<< std::quoted(x) << "\n";
41+
}
42+
out <<'\n';
43+
}
44+
out << "\n\nunravelReplicas\n";
45+
for(auto test: {
46+
"@replicas:{1,2,3} {0,0,0} {2,4,6}",
47+
"@replicas:{{1,2,3} {0,0,0} {2,4,6}}",
48+
"@replicas:1 2 3"
49+
}) {
50+
out << std::quoted(test) << "\n";
51+
for (int rep : {
52+
0,1,2
53+
}) {
54+
auto res=Tools::unravelReplicas(test, rep);
55+
out << "Replica: "<< rep << "\n";
56+
out << "\t" << res << " ";
57+
out << "\n";
58+
}
59+
}
60+
out << "\n\nreadVector\n";
61+
for(auto test: {
62+
//this will be passed as intended by the LineToken class, the output of this first line is wrong!
63+
//"@replicas:{{1,2,3} {0,0,0} {2,4,6}}",
64+
//"@replicas:1 2 3",
65+
"1,@replicas:{1,2,3},31,999,3",
66+
"1,999,3",
67+
//this works as intended, sadly it is not a possible input, currently
68+
"@replicas:{1,2,3},999,3",
69+
"@replicas:{1,2,3},@replicas:{3,5,6},3"
70+
}) {
71+
out << std::quoted(test) << "\n";
72+
for (int rep : {
73+
0,1,2
74+
}) {
75+
std::vector<int> res;
76+
Tools::parseVector(test,res,rep);
77+
out << "Replica: "<< rep << "\n";
78+
out << "\t" ;
79+
for (auto x:res) {
80+
out << x << " ";
81+
}
82+
out << "\n";
83+
}
84+
}
85+
} catch(PLMD::Exception &e) {
86+
std::cerr << "Exception:" << e.what() << "\n";
87+
}
88+
return 0;
89+
}

0 commit comments

Comments
 (0)