Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
TestHost.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include <iostream>
43 
44 #include "Kokkos_Core.hpp"
45 
46 #ifdef KOKKOS_ENABLE_THREADS
48 #endif
49 #ifdef KOKKOS_ENABLE_OPENMP
51 #endif
52 
53 #include "TestStochastic.hpp"
54 
55 namespace unit_test {
56 
57 template<typename Scalar, typename Device>
59 
60  static void run(bool test_flat, bool test_orig, bool test_deg, bool test_lin,
61  bool test_block, bool symmetric, bool mkl) {
62 
63  int nGrid;
64  int nIter;
65 
66  // All methods compared against flat-original
67  if (test_flat) {
68  nGrid = 12 ;
69  nIter = 1 ;
70  performance_test_driver_all<Scalar,Device>(
71  3 , 1 , 9 , nGrid , nIter , test_block , symmetric );
72  performance_test_driver_all<Scalar,Device>(
73  5 , 1 , 5 , nGrid , nIter , test_block , symmetric );
74  }
75 
76  // Just polynomial methods compared against original
77  if (test_orig) {
78 #ifdef __MIC__
79  nGrid = 32 ;
80 #else
81  nGrid = 32 ;
82 #endif
83  nIter = 1 ;
84  // Something funny happens when we go to larger problem sizes on the
85  // MIC where it appears to slow down subsequent calculations (i.e.,
86  // the degree 5 cases will run slower). Maybe it is getting too hot?
87 #ifdef __MIC__
88  performance_test_driver_poly<Scalar,Device,Stokhos::DefaultMultiply>(
89  3 , 1 , 9 , nGrid , nIter , test_block , symmetric );
90 #else
91  performance_test_driver_poly<Scalar,Device,Stokhos::DefaultMultiply>(
92  3 , 1 , 12 , nGrid , nIter , test_block , symmetric );
93 #endif
94  performance_test_driver_poly<Scalar,Device,Stokhos::DefaultMultiply>(
95  5 , 1, 6 , nGrid , nIter , test_block , symmetric );
96  }
97 
98  // Just polynomial methods compared against original
99  if (test_deg) {
100  #ifdef __MIC__
101  nGrid = 32 ;
102 #else
103  nGrid = 64 ;
104 #endif
105  nIter = 1 ;
106  performance_test_driver_poly_deg<Scalar,Device,Stokhos::DefaultMultiply>(
107  3 , 1 , 12 , nGrid , nIter , test_block , symmetric );
108  }
109 
110  // Just polynomial methods compared against original
111  if (test_lin) {
112 #ifdef __MIC__
113  nGrid = 32 ;
114 #else
115  nGrid = 64 ;
116 #endif
117  nIter = 10 ;
118  performance_test_driver_linear<Scalar,Device,Stokhos::DefaultMultiply>(
119  31 , 255 , 32 , nGrid , nIter , test_block , symmetric );
120  }
121 
122  //------------------------------
123  }
124 
125 };
126 
127 }
128 
129 template <typename Scalar, typename Device>
130 int mainHost(bool test_flat, bool test_orig, bool test_deg, bool test_lin,
131  bool test_block, bool symmetric, bool mkl)
132 {
133  const size_t team_count =
134  Kokkos::hwloc::get_available_numa_count() *
135  Kokkos::hwloc::get_available_cores_per_numa();
136  const size_t threads_per_team =
137  Kokkos::hwloc::get_available_threads_per_core();
138 
139  Kokkos::InitArguments init_args;
140  init_args.num_threads = team_count*threads_per_team;
141  Kokkos::initialize( init_args );
142 
143  std::string name = "Host";
144 #ifdef KOKKOS_ENABLE_THREADS
145  Kokkos::Threads::print_configuration( std::cout );
146  if (std::is_same<Device,Kokkos::Threads>::value)
147  name = "Threads";
148 #endif
149 #ifdef KOKKOS_ENABLE_OPENMP
150  Kokkos::OpenMP::print_configuration( std::cout );
151  if (std::is_same<Device,Kokkos::OpenMP>::value)
152  name = "OpenMP";
153 #endif
154  std::cout << std::endl << "\"" << name << " Performance with "
155  << team_count * threads_per_team << " threads\"" << std::endl ;
156 
158  test_flat, test_orig, test_deg, test_lin, test_block, symmetric, mkl);
159 
160  Kokkos::finalize();
161 
162  return 0 ;
163 }
164 
165 #ifdef KOKKOS_ENABLE_SERIAL
166 template int mainHost<float,Kokkos::Serial>(bool, bool, bool, bool, bool, bool, bool);
167 template int mainHost<double,Kokkos::Serial>(bool, bool, bool, bool, bool, bool, bool);
168 #endif
169 
170 #ifdef KOKKOS_ENABLE_THREADS
171 template int mainHost<float,Kokkos::Threads>(bool, bool, bool, bool, bool, bool, bool);
172 template int mainHost<double,Kokkos::Threads>(bool, bool, bool, bool, bool, bool, bool);
173 #endif
174 
175 #ifdef KOKKOS_ENABLE_OPENMP
176 template int mainHost<float,Kokkos::OpenMP>(bool, bool, bool, bool, bool, bool, bool);
177 template int mainHost<double,Kokkos::OpenMP>(bool, bool, bool, bool, bool, bool, bool);
178 #endif
int mainHost(bool test_flat, bool test_orig, bool test_deg, bool test_lin, bool test_block, bool symmetric, bool mkl)
Definition: TestHost.cpp:130
static void run(bool test_flat, bool test_orig, bool test_deg, bool test_lin, bool test_block, bool symmetric, bool mkl)
Definition: TestHost.cpp:60