/[escript]/branches/diaplayground/cusplibrary/testing/monitor.cu
ViewVC logotype

Contents of /branches/diaplayground/cusplibrary/testing/monitor.cu

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4955 - (show annotations)
Tue May 20 04:33:15 2014 UTC (5 years, 4 months ago) by caltinay
File size: 1680 byte(s)
added pristine copy of cusplibrary (apache license) to be used by ripley.

1 #include <unittest/unittest.h>
2
3 #include <cusp/monitor.h>
4
5 template <typename MemorySpace>
6 void TestMonitorSimple(void)
7 {
8 cusp::array1d<float,MemorySpace> b(2);
9 b[0] = 10;
10 b[1] = 0;
11
12 cusp::array1d<float,MemorySpace> r(2);
13 r[0] = 10;
14 r[1] = 0;
15
16 cusp::default_monitor<float> monitor(b, 5, 0.5, 1.0);
17
18 ASSERT_EQUAL(monitor.finished(r), false);
19 ASSERT_EQUAL(monitor.iteration_count(), 0);
20 ASSERT_EQUAL(monitor.iteration_limit(), 5);
21 ASSERT_EQUAL(monitor.relative_tolerance(), 0.5);
22 ASSERT_EQUAL(monitor.absolute_tolerance(), 1.0);
23 ASSERT_EQUAL(monitor.tolerance(), 6.0);
24
25 ++monitor;
26
27 ASSERT_EQUAL(monitor.finished(r), false);
28 ASSERT_EQUAL(monitor.iteration_count(), 1);
29 ASSERT_EQUAL(monitor.residual_norm(), 10.0);
30
31 r[0] = 2;
32
33 ASSERT_EQUAL(monitor.finished(r), true);
34 ASSERT_EQUAL(monitor.iteration_count(), 1);
35 ASSERT_EQUAL(monitor.residual_norm(), 2.0);
36
37 r[0] = 7;
38
39 ASSERT_EQUAL(monitor.finished(r), false);
40 ASSERT_EQUAL(monitor.iteration_count(), 1);
41 ASSERT_EQUAL(monitor.residual_norm(), 7.0);
42
43 ++monitor;
44
45 ASSERT_EQUAL(monitor.finished(r), false);
46 ASSERT_EQUAL(monitor.iteration_count(), 2);
47 ASSERT_EQUAL(monitor.residual_norm(), 7.0);
48
49 ++monitor;
50 ++monitor;
51
52 ASSERT_EQUAL(monitor.finished(r), false);
53 ASSERT_EQUAL(monitor.iteration_count(), 4);
54 ASSERT_EQUAL(monitor.residual_norm(), 7.0);
55
56 ++monitor;
57
58 ASSERT_EQUAL(monitor.finished(r), true);
59 ASSERT_EQUAL(monitor.iteration_count(), 5);
60 ASSERT_EQUAL(monitor.residual_norm(), 7.0);
61 }
62 DECLARE_HOST_DEVICE_UNITTEST(TestMonitorSimple);
63

  ViewVC Help
Powered by ViewVC 1.1.26