n2p2 - A neural network potential package
nnp-cutoff.cpp File Reference
#include "CutoffFunction.h"
#include "Log.h"
#include "Stopwatch.h"
#include "utility.h"
#include <iostream>
#include <fstream>
Include dependency graph for nnp-cutoff.cpp:

Go to the source code of this file.

Functions

void runTest (bool write)
 
void runTest (CutoffFunction::CutoffType cutoffType)
 
int main ()
 

Variables

CutoffFunction fc
 
Log nnplog
 
ofstream logFile
 
Stopwatch swf
 
Stopwatch swdf
 
Stopwatch swfdf
 
size_t p = 100000000
 
double d = 0.99999 / p
 
double tbf = 0.0
 
double tbdf = 0.0
 
double tbfdf = 0.0
 
double tlf = 0.0
 
double tldf = 0.0
 
double tlfdf = 0.0
 

Function Documentation

◆ runTest() [1/2]

void runTest ( bool  write)

Definition at line 42 of file nnp-cutoff.cpp.

43{
44 swf.reset();
45 swf.start();
46 for (size_t i = 0; i < p; ++i)
47 {
48 __asm__ __volatile__("");
49 }
50 tlf = swf.stop();
51 if (write) nnplog << strpr(" %10.2E %6.1f ", tlf, tlf / tlf);
52
53 swdf.reset();
54 swdf.start();
55 for (size_t i = 0; i < p; ++i)
56 {
57 __asm__ __volatile__("");
58 }
59 tldf = swdf.stop();
60 if (write) nnplog << strpr(" %10.2E %6.1f ", tldf, tldf / tldf);
61
62 swfdf.reset();
63 swfdf.start();
64 for (size_t i = 0; i < p; ++i)
65 {
66 __asm__ __volatile__("");
67 }
68 tlfdf = swfdf.stop();
69 if (write) nnplog << strpr(" %10.2E %6.1f %10.2E %9.1f\n",
70 tlfdf,
71 tlfdf / tlfdf,
72 tlfdf - (tlf + tldf),
73 100.0 * tlfdf / (tlf + tldf));
74}
void reset()
Reset stopwatch (total and loop time zero, clock not running).
Definition: Stopwatch.cpp:76
double stop()
Stop and return total time.
Definition: Stopwatch.cpp:62
void start(bool newLoop=true)
Start the stopwatch.
Definition: Stopwatch.cpp:40
string strpr(const char *format,...)
String version of printf function.
Definition: utility.cpp:90
Stopwatch swf
Definition: nnp-cutoff.cpp:30
Log nnplog
Definition: nnp-cutoff.cpp:28
double tlfdf
Definition: nnp-cutoff.cpp:40
double tlf
Definition: nnp-cutoff.cpp:38
size_t p
Definition: nnp-cutoff.cpp:33
double tldf
Definition: nnp-cutoff.cpp:39
Stopwatch swdf
Definition: nnp-cutoff.cpp:31
Stopwatch swfdf
Definition: nnp-cutoff.cpp:32

References nnplog, p, nnp::Stopwatch::reset(), nnp::Stopwatch::start(), nnp::Stopwatch::stop(), nnp::strpr(), swdf, swf, swfdf, tldf, tlf, and tlfdf.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ runTest() [2/2]

void runTest ( CutoffFunction::CutoffType  cutoffType)

Definition at line 76 of file nnp-cutoff.cpp.

77{
78 fc.setCutoffType(cutoffType);
79
80 swf.reset();
81 swf.start();
82 for (size_t i = 0; i < p; ++i)
83 {
84 fc.f(i * d);
85 }
86 double tf = swf.stop();
87 if (cutoffType == CutoffFunction::CT_HARD) tbf = tf;
88 nnplog << strpr(" %10.2E %6.1f %6.1f", tf, tf / tlf, tf / tbf);
89
90 swdf.reset();
91 swdf.start();
92 for (size_t i = 0; i < p; ++i)
93 {
94 fc.df(i * d);
95 }
96 double tdf = swdf.stop();
97 if (cutoffType == CutoffFunction::CT_HARD) tbdf = tdf;
98 nnplog << strpr(" %10.2E %6.1f %6.1f", tdf, tdf / tldf, tdf / tbdf);
99
100 swfdf.reset();
101 swfdf.start();
102 for (size_t i = 0; i < p; ++i)
103 {
104 double f;
105 double df;
106 fc.fdf(i * d, f, df);
107 }
108 double tfdf = swfdf.stop();
109 if (cutoffType == CutoffFunction::CT_HARD) tbfdf = tfdf;
110
111 nnplog << strpr(" %10.2E %6.1f %6.1f %10.2E %9.1f\n",
112 tfdf,
113 tfdf / tlfdf,
114 tfdf / tbfdf,
115 tfdf - (tf + tdf),
116 100.0 * tfdf / (tf + tdf));
117}
double f(double r) const
Cutoff function .
void fdf(double r, double &fc, double &dfc) const
Calculate cutoff function and derivative .
void setCutoffType(CutoffType const cutoffType)
Set cutoff type.
double df(double r) const
Derivative of cutoff function .
double tbf
Definition: nnp-cutoff.cpp:35
double tbfdf
Definition: nnp-cutoff.cpp:37
double tbdf
Definition: nnp-cutoff.cpp:36
double d
Definition: nnp-cutoff.cpp:34
CutoffFunction fc
Definition: nnp-cutoff.cpp:27

References d, nnp::CutoffFunction::df(), nnp::CutoffFunction::f(), fc, nnp::CutoffFunction::fdf(), nnplog, p, nnp::Stopwatch::reset(), nnp::CutoffFunction::setCutoffType(), nnp::Stopwatch::start(), nnp::Stopwatch::stop(), nnp::strpr(), swdf, swf, swfdf, tbdf, tbf, tbfdf, tldf, tlf, and tlfdf.

Here is the call graph for this function:

◆ main()

int main ( )

Definition at line 119 of file nnp-cutoff.cpp.

120{
121 logFile.open("nnp-cutoff.log");
123
124 nnplog << "-------------------------------------------------------------------------------------------------------------\n";
125 nnplog << "Speed test tool for cutoff functions:\n";
126 nnplog << "-------------------------------------------------------------------------------------------------------------\n";
127 nnplog << "Column f : Time for calling f (no derivatives ).\n";
128 nnplog << "Column df : Time for calling df (only derivatives).\n";
129 nnplog << "Column fdf : Time for calling fdf (f and df at once).\n";
130 nnplog << "Column compL : Time compared to LOOP ONLY.\n";
131 nnplog << "Column compH : Time compared to CT_HARD.\n";
132 nnplog << "Column diff : Time difference between calling f + df (separately) and fdf.\n";
133 nnplog << "Column ratio : Ratio time(fdf) / (time(f) + time(df)) in %.\n";
134 nnplog << "-------------------------------------------------------------------------------------------------------------\n";
135 nnplog << "CutoffType : f [s] compL compH df [s] compL compH fdf[s] compL compH diff [s] ratio [%]\n";
136 nnplog << "-------------------------------------------------------------------------------------------------------------\n";
137
138 // Initialize...
139 runTest(false);
140
141 nnplog << "LOOP ONLY : ";
142 runTest(true);
143
144 fc.setCutoffRadius(1.0);
145
146 nnplog << "CT_HARD : ";
147 runTest(CutoffFunction::CT_HARD);
148
149 nnplog << "CT_COS : ";
151 runTest(CutoffFunction::CT_COS);
152
153 nnplog << "CT_TANHU : ";
154 runTest(CutoffFunction::CT_TANHU);
155
156 nnplog << "CT_TANH : ";
157 runTest(CutoffFunction::CT_TANH);
158
159 nnplog << "CT_EXP : ";
161 runTest(CutoffFunction::CT_EXP);
162
163 nnplog << "CT_POLY1 : ";
165 runTest(CutoffFunction::CT_POLY1);
166
167 nnplog << "CT_POLY2 : ";
169 runTest(CutoffFunction::CT_POLY2);
170
171 nnplog << "CT_POLY3 : ";
173 runTest(CutoffFunction::CT_POLY3);
174
175 nnplog << "CT_POLY4 : ";
177 runTest(CutoffFunction::CT_POLY4);
178
179 logFile.close();
180
181 return 0;
182}
void setCutoffParameter(double const alpha)
Set parameter for polynomial cutoff function (CT_POLY).
void setCutoffRadius(double const cutoffRadius)
Set cutoff radius.
void registerStreamPointer(std::ofstream *const &streamPointer)
Register new C++ ofstream pointer.
Definition: Log.cpp:91
void runTest(bool write)
Definition: nnp-cutoff.cpp:42
ofstream logFile
Definition: nnp-cutoff.cpp:29

References fc, logFile, nnplog, nnp::Log::registerStreamPointer(), runTest(), nnp::CutoffFunction::setCutoffParameter(), and nnp::CutoffFunction::setCutoffRadius().

Here is the call graph for this function:

Variable Documentation

◆ fc

◆ nnplog

Log nnplog

Definition at line 28 of file nnp-cutoff.cpp.

Referenced by main(), and runTest().

◆ logFile

ofstream logFile

Definition at line 29 of file nnp-cutoff.cpp.

Referenced by main().

◆ swf

Stopwatch swf

Definition at line 30 of file nnp-cutoff.cpp.

Referenced by runTest().

◆ swdf

Stopwatch swdf

Definition at line 31 of file nnp-cutoff.cpp.

Referenced by runTest().

◆ swfdf

Stopwatch swfdf

Definition at line 32 of file nnp-cutoff.cpp.

Referenced by runTest().

◆ p

◆ d

◆ tbf

double tbf = 0.0

Definition at line 35 of file nnp-cutoff.cpp.

Referenced by runTest().

◆ tbdf

double tbdf = 0.0

Definition at line 36 of file nnp-cutoff.cpp.

Referenced by runTest().

◆ tbfdf

double tbfdf = 0.0

Definition at line 37 of file nnp-cutoff.cpp.

Referenced by runTest().

◆ tlf

double tlf = 0.0

Definition at line 38 of file nnp-cutoff.cpp.

Referenced by runTest().

◆ tldf

double tldf = 0.0

Definition at line 39 of file nnp-cutoff.cpp.

Referenced by runTest().

◆ tlfdf

double tlfdf = 0.0

Definition at line 40 of file nnp-cutoff.cpp.

Referenced by runTest().