31 void transform(
const int size,
double a[],
double b[] ) {
33 for(
int k = 1; k < size; ++k ) b[k] = a[k]+a[k-1];
34 for(
int k = 0; k < size; ++k ) a[k] = a[k]-b[k];
39 double *b =
new double[size];
44 std::vector<double> b(size);
48 std::valarray<double> b(size);
57 int main(
int argc,
char* argv[] )
69 CommandLineProcessor clp(
false);
71 clp.setOption(
"verbose",
"quiet", &verbose,
"Set if output is printed or not." );
73 double rel_proc_speed = 1e-5;
74 clp.setOption(
"rel-proc-speed", &rel_proc_speed,
"Relative processor speed (try around 1.0 for timing)." );
77 clp.setOption(
"size", &size,
"Size of memory blocks created." );
79 bool allocate_workspace =
true;
80 clp.setOption(
"allocate-workspace",
"no-allocate-workspace", &allocate_workspace,
"Preallocate workspace or not." );
82 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
83 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
return parse_return;
87 default_num_loops = int( 100000000 * rel_proc_speed ),
88 num_loops = int( default_num_loops / ( size + 100 ) );
91 if( allocate_workspace )
101 if(verbose) std::cout
102 <<
"\n************************************************************************************"
103 <<
"\n*** Testing and timing Teuchos::Workspace and other methods for temporary memory ***"
104 <<
"\n************************************************************************************\n";
106 if(verbose) std::cout
107 <<
"\nMemory block size = " << size
108 <<
"\nNumber of call loops = " << num_loops
112 std::vector<double> a(size);
114 if(verbose) std::cout <<
"\nTiming raw new and delete for temporaries ...\n";
115 std::fill_n( &a[0], size, 1.0 );
117 for(
int k = 0; k < num_loops; ++k ) t.
transformRaw(size,&a[0]);
120 if(verbose) std::cout <<
" time = " << timer.
totalElapsedTime() <<
" sec\n";
122 if(verbose) std::cout <<
"\nTiming std::vector for temporaries ...\n";
123 std::fill_n( &a[0], size, 1.0 );
128 if(verbose) std::cout <<
" time = " << timer.
totalElapsedTime() <<
" sec\n";
130 if(verbose) std::cout <<
"\nTiming std::valarray for temporaries ...\n";
131 std::fill_n( &a[0], size, 1.0 );
136 if(verbose) std::cout <<
" time = " << timer.
totalElapsedTime() <<
" sec\n";
138 if(verbose) std::cout <<
"\nTiming Teuchos::Workspace for temporaries ...\n";
139 std::fill_n( &a[0], size, 1.0 );
144 if(verbose) std::cout <<
" time = " << timer.
totalElapsedTime() <<
" sec\n";
149 <<
"\nRelative time (lower is better):"
150 <<
"\n raw new/delete = " << (raw_time/workspace_time)
151 <<
"\n std::vector = " << (vector_time/workspace_time)
152 <<
"\n std::valarray = " << (valarray_time/workspace_time)
153 <<
"\n Teuchos::Workspace = " << (workspace_time/workspace_time)
154 << std::endl << std::endl;
158 catch(
const std::exception &excpt ) {
160 std::cerr <<
"*** Caught standard std::exception : " << excpt.what() << std::endl;
165 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().