int main()
{
- std::ofstream logfile("output");
- deallog.attach(logfile);
+ initlog();
deallog.threshold_double(1.e-10);
- for (unsigned int i=0; i<MultithreadInfo::n_cores()*2; ++i)
- Threads::new_task (outer);
+ {
+ const std::size_t n_tasks = MultithreadInfo::n_cores()*2;
+#ifdef _POSIX_C_SOURCE
+ // get rid of the environment variable if it exists (this may not be
+ // possible under MSVC, but the test will still pass; it just won't test
+ // what we want it to test)
+ unsetenv("DEAL_II_NUM_THREADS");
+#endif
+ // Since this test relies on providing more tasks than there are cores,
+ // reset the concurrency limit that exists in tests.h:
+ MultithreadInfo::set_thread_limit(n_tasks);
+ std::vector<Threads::Task<void>> tasks(n_tasks);
+ for (std::size_t task_n=0; task_n<n_tasks; ++task_n)
+ {
+ // We must save each task, otherwise it will join before the next loop
+ // iteration
+ tasks.emplace_back(Threads::new_task(outer));
+ }
+ }
deallog << "OK" << std::endl;
}
int main ()
{
- std::ofstream logfile("output");
- deallog.attach(logfile);
+ initlog();
deallog.threshold_double(1.e-10);
- Timer t1,t2;
- burn (50);
- double s01 = t1.stop();
- double s02 = t2();
- burn (50);
- double s11 = t1.stop();
- double s12 = t2();
- t1.start();
- burn (50);
- double s21 = t1();
- double s22 = t2();
- burn (50);
- double s31 = t1();
- double s32 = t2();
-
- compare (s01,s02,1.);
- compare (s11,s12,2.);
- compare (s21,s22,3./2.);
- compare (s31,s32,4./3.);
+ Timer t;
+ burn(50);
+
+ double s1 = t();
+
+ if (s1 > 0.)
+ deallog << "OK" << std::endl;
+ else
+ deallog << "ERROR - s1 should be nonzero" << std::endl;
+
+ burn(50);
+ t.stop();
+ double s2 = t();
+
+ if (s2 > s1)
+ deallog << "OK" << std::endl;
+ else
+ deallog << "ERROR - s2 should be greater than s1" << std::endl;
+
+ burn(50);
+ double s3 = t();
+
+ if (s3 == s2)
+ deallog << "OK" << std::endl;
+ else
+ deallog << "ERROR - s3 should be equal to s2" << std::endl;
+
+ t.start();
+ burn(50);
+ double s4 = t();
+
+ if (s4 > s3)
+ deallog << "OK" << std::endl;
+ else
+ deallog << "ERROR - s4 should be greater than s3" << std::endl;
+
+ t.stop();
+ t.reset();
+ burn(50);
+ double s5 = t();
+
+ if (s5 == 0.)
+ deallog << "OK" << std::endl;
+ else
+ deallog << "ERROR - s5 should be zero" << std::endl;
+
+ t.start();
+ burn(50);
+ t.reset();
+ burn(50);
+ double s6 = t();
+
+ if (s6 == 0.)
+ deallog << "OK" << std::endl;
+ else
+ deallog << "ERROR - s6 should be zero" << std::endl;
+
}