63 void transform(
const int size,
double a[],
double b[] ) {
65 for(
int k = 1; k < size; ++k ) b[k] = a[k]+a[k-1];
66 for(
int k = 0; k < size; ++k ) a[k] = a[k]-b[k];
71 double *b =
new double[size];
76 std::vector<double> b(size);
80 std::valarray<double> b(size);
89 int main(
int argc,
char* argv[] )
101 CommandLineProcessor clp(
false);
103 clp.setOption(
"verbose",
"quiet", &verbose,
"Set if output is printed or not." );
105 double rel_proc_speed = 1e-5;
106 clp.setOption(
"rel-proc-speed", &rel_proc_speed,
"Relative processor speed (try around 1.0 for timing)." );
109 clp.setOption(
"size", &size,
"Size of memory blocks created." );
111 bool allocate_workspace =
true;
112 clp.setOption(
"allocate-workspace",
"no-allocate-workspace", &allocate_workspace,
"Preallocate workspace or not." );
114 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
115 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
return parse_return;
119 default_num_loops = int( 100000000 * rel_proc_speed ),
120 num_loops = int( default_num_loops / ( size + 100 ) );
123 if( allocate_workspace )
133 if(verbose) std::cout
134 <<
"\n************************************************************************************"
135 <<
"\n*** Testing and timing Teuchos::Workspace and other methods for temporary memory ***"
136 <<
"\n************************************************************************************\n";
138 if(verbose) std::cout
139 <<
"\nMemory block size = " << size
140 <<
"\nNumber of call loops = " << num_loops
144 std::vector<double> a(size);
146 if(verbose) std::cout <<
"\nTiming raw new and delete for temporaries ...\n";
147 std::fill_n( &a[0], size, 1.0 );
149 for(
int k = 0; k < num_loops; ++k ) t.
transformRaw(size,&a[0]);
152 if(verbose) std::cout <<
" time = " << timer.
totalElapsedTime() <<
" sec\n";
154 if(verbose) std::cout <<
"\nTiming std::vector for temporaries ...\n";
155 std::fill_n( &a[0], size, 1.0 );
160 if(verbose) std::cout <<
" time = " << timer.
totalElapsedTime() <<
" sec\n";
162 if(verbose) std::cout <<
"\nTiming std::valarray for temporaries ...\n";
163 std::fill_n( &a[0], size, 1.0 );
168 if(verbose) std::cout <<
" time = " << timer.
totalElapsedTime() <<
" sec\n";
170 if(verbose) std::cout <<
"\nTiming Teuchos::Workspace for temporaries ...\n";
171 std::fill_n( &a[0], size, 1.0 );
176 if(verbose) std::cout <<
" time = " << timer.
totalElapsedTime() <<
" sec\n";
181 <<
"\nRelative time (lower is better):"
182 <<
"\n raw new/delete = " << (raw_time/workspace_time)
183 <<
"\n std::vector = " << (vector_time/workspace_time)
184 <<
"\n std::valarray = " << (valarray_time/workspace_time)
185 <<
"\n Teuchos::Workspace = " << (workspace_time/workspace_time)
186 << std::endl << std::endl;
190 catch(
const std::exception &excpt ) {
192 std::cerr <<
"*** Caught standard std::exception : " << excpt.what() << std::endl;
197 std::cerr <<
"*** Caught an unknown std::exception\n";
Templated class for workspace creation.
TEUCHOSCORE_LIB_DLL_EXPORT void set_default_workspace_store(const Teuchos::RCP< WorkspaceStore > &default_workspace_store)
Set pointer to global workspace object.
WorkspaceStore class that can be used to actually reinitialize memory.
Basic wall-clock timer class.
Initialize, finalize, and query the global MPI session.
void start(bool reset=false)
Start the timer, if the timer is enabled (see disable()).
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
double stop()
Stop the timer, if the timer is enabled (see disable()).
Workspace encapsulation class.
std::string Teuchos_Version()
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
int main(int argc, char *argv[])
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Basic command line parser for input from (argc,argv[])
double totalElapsedTime(bool readCurrentTime=false) const
The total time in seconds accumulated by this timer.
TEUCHOSCORE_LIB_DLL_EXPORT void print_memory_usage_stats(const WorkspaceStore *workspace_store, std::ostream &out)
Print statistics on memory usage.
Class that helps parse command line input arguments from (argc,argv[]) and set options.
TEUCHOSCORE_LIB_DLL_EXPORT Teuchos::RCP< WorkspaceStore > get_default_workspace_store()
Get the global workspace object set by set_default_workspace_store().