Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
main.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 <string>
43#include <iostream>
44#include <cstdlib>
45
46#include "Kokkos_Core.hpp"
47
48#include "Stokhos_ConfigDefs.h"
49
50template <typename scalar, typename device>
51int mainHost(bool test_flat, bool test_orig, bool test_deg, bool test_lin,
52 bool test_block, bool symmetric, bool mkl);
53
54template <typename scalar>
55int mainCuda(bool test_flat, bool test_orig, bool test_lin,
56 bool test_block, bool symmetric, int device_id);
57
58int main(int argc, char *argv[])
59{
60 // Defaults
61 bool test_host = true;
62#ifdef KOKKOS_ENABLE_CUDA
63 bool test_cuda = true;
64 int device = 0;
65#endif
66 bool test_block = true;
67 bool test_flat = true;
68 bool test_orig = true;
69 bool test_deg = false;
70 bool test_lin = false;
71 bool symmetric = true;
72 bool single = false;
73 bool mkl = false;
74#ifdef KOKKOS_ENABLE_SERIAL
75 bool serial = true;
76#endif
77#ifdef KOKKOS_ENABLE_OPENMP
78 bool omp = true;
79#endif
80#ifdef KOKKOS_ENABLE_THREADS
81 bool threads = true;
82#endif
83
84 // Parse command line arguments
85 bool print_usage = false;
86 int i=1;
87 while (i<argc) {
88 std::string s(argv[i]);
89 if (s == "host")
90 test_host = true;
91 else if (s == "no-host")
92 test_host = false;
93#ifdef KOKKOS_ENABLE_CUDA
94 else if (s == "cuda")
95 test_cuda = true;
96 else if (s == "no-cuda")
97 test_cuda = false;
98 else if (s == "device") {
99 ++i;
100 device = std::atoi(argv[i]);
101 }
102#endif
103 else if (s == "block")
104 test_block = true;
105 else if (s == "no-block")
106 test_block = false;
107 else if (s == "flat")
108 test_flat = true;
109 else if (s == "no-flat")
110 test_flat = false;
111 else if (s == "orig")
112 test_orig = true;
113 else if (s == "no-orig")
114 test_orig = false;
115 else if (s == "deg")
116 test_deg = true;
117 else if (s == "no-deg")
118 test_deg = false;
119 else if (s == "linear")
120 test_lin = true;
121 else if (s == "no-linear")
122 test_lin = false;
123 else if (s == "symmetric")
124 symmetric = true;
125 else if (s == "no-symmetric")
126 symmetric = false;
127 else if (s == "mkl")
128 mkl = true;
129 else if (s == "no-mkl")
130 mkl = false;
131 else if (s == "single")
132 single = true;
133 else if (s == "double")
134 single = false;
135#ifdef KOKKOS_ENABLE_SERIAL
136 else if (s == "serial")
137 serial = true;
138 else if (s == "no-serial")
139 serial = false;
140#endif
141#ifdef KOKKOS_ENABLE_OPENMP
142 else if (s == "omp")
143 omp = true;
144 else if (s == "no-omp")
145 omp = false;
146#endif
147#ifdef KOKKOS_ENABLE_THREADS
148 else if (s == "threads")
149 threads = true;
150 else if (s == "no-threads")
151 threads = false;
152#endif
153 else if (s == "-h" || s == "--help")
154 print_usage = true;
155 else {
156 std::cout << "Invalid argument: " << s << std::endl;
157 print_usage = true;
158 }
159 ++i;
160 }
161 if (print_usage) {
162 std::cout << "Usage:" << std::endl
163 << "\t" << argv[0]
164 << " [no-][cuda|host|serial|omp|threads|block|flat|orig|deg|linear|symmetric] [single|double] [device device_id]"
165 << std::endl << "Defaults are all enabled." << std::endl;
166 return -1;
167 }
168
169 if (test_host) {
170
171#ifdef KOKKOS_ENABLE_SERIAL
172 if (serial) {
173 if (single)
174 mainHost<float,Kokkos::Serial>(
175 test_flat, test_orig, test_deg, test_lin, test_block, symmetric, mkl);
176 else
177 mainHost<double,Kokkos::Serial>(
178 test_flat, test_orig, test_deg, test_lin, test_block, symmetric, mkl);
179 }
180#endif
181
182#ifdef KOKKOS_ENABLE_THREADS
183 if (threads) {
184 if (single)
185 mainHost<float,Kokkos::Threads>(
186 test_flat, test_orig, test_deg, test_lin, test_block, symmetric, mkl);
187 else
188 mainHost<double,Kokkos::Threads>(
189 test_flat, test_orig, test_deg, test_lin, test_block, symmetric, mkl);
190 }
191#endif
192
193#ifdef KOKKOS_ENABLE_OPENMP
194 if (omp) {
195 if (single)
196 mainHost<float,Kokkos::OpenMP>(
197 test_flat, test_orig, test_deg, test_lin, test_block, symmetric, mkl);
198 else
199 mainHost<double,Kokkos::OpenMP>(
200 test_flat, test_orig, test_deg, test_lin, test_block, symmetric, mkl);
201 }
202#endif
203
204 }
205
206#ifdef KOKKOS_ENABLE_CUDA
207 if (test_cuda) {
208 if (single)
209 mainCuda<float>(test_flat, test_orig, test_lin, test_block, symmetric, device);
210 else
211 mainCuda<double>(test_flat, test_orig, test_lin, test_block, symmetric, device);
212 }
213#endif
214
215 return 0 ;
216}
Kokkos::DefaultExecutionSpace device
template int mainCuda< double >(bool, bool, bool, bool, bool, int)
template int mainCuda< float >(bool, bool, bool, bool, bool, int)
int main(int argc, char *argv[])
Definition: main.cpp:58
int mainCuda(bool test_flat, bool test_orig, bool test_lin, bool test_block, bool symmetric, int device_id)
Definition: TestCuda.cpp:92
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