Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
main.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include <string>
11 #include <iostream>
12 #include <cstdlib>
13 
14 #include "Kokkos_Core.hpp"
15 
16 #include "Stokhos_ConfigDefs.h"
17 
18 template <typename scalar, typename device>
19 int mainHost(bool test_flat, bool test_orig, bool test_deg, bool test_lin,
20  bool test_block, bool symmetric, bool mkl);
21 
22 template <typename scalar>
23 int mainCuda(bool test_flat, bool test_orig, bool test_lin,
24  bool test_block, bool symmetric, int device_id);
25 
26 int main(int argc, char *argv[])
27 {
28  // Defaults
29  bool test_host = true;
30 #ifdef KOKKOS_ENABLE_CUDA
31  bool test_cuda = true;
32  int device = 0;
33 #endif
34  bool test_block = true;
35  bool test_flat = true;
36  bool test_orig = true;
37  bool test_deg = false;
38  bool test_lin = false;
39  bool symmetric = true;
40  bool single = false;
41  bool mkl = false;
42 #ifdef KOKKOS_ENABLE_SERIAL
43  bool serial = true;
44 #endif
45 #ifdef KOKKOS_ENABLE_OPENMP
46  bool omp = true;
47 #endif
48 #ifdef KOKKOS_ENABLE_THREADS
49  bool threads = true;
50 #endif
51 
52  // Parse command line arguments
53  bool print_usage = false;
54  int i=1;
55  while (i<argc) {
56  std::string s(argv[i]);
57  if (s == "host")
58  test_host = true;
59  else if (s == "no-host")
60  test_host = false;
61 #ifdef KOKKOS_ENABLE_CUDA
62  else if (s == "cuda")
63  test_cuda = true;
64  else if (s == "no-cuda")
65  test_cuda = false;
66  else if (s == "device") {
67  ++i;
68  device = std::atoi(argv[i]);
69  }
70 #endif
71  else if (s == "block")
72  test_block = true;
73  else if (s == "no-block")
74  test_block = false;
75  else if (s == "flat")
76  test_flat = true;
77  else if (s == "no-flat")
78  test_flat = false;
79  else if (s == "orig")
80  test_orig = true;
81  else if (s == "no-orig")
82  test_orig = false;
83  else if (s == "deg")
84  test_deg = true;
85  else if (s == "no-deg")
86  test_deg = false;
87  else if (s == "linear")
88  test_lin = true;
89  else if (s == "no-linear")
90  test_lin = false;
91  else if (s == "symmetric")
92  symmetric = true;
93  else if (s == "no-symmetric")
94  symmetric = false;
95  else if (s == "mkl")
96  mkl = true;
97  else if (s == "no-mkl")
98  mkl = false;
99  else if (s == "single")
100  single = true;
101  else if (s == "double")
102  single = false;
103 #ifdef KOKKOS_ENABLE_SERIAL
104  else if (s == "serial")
105  serial = true;
106  else if (s == "no-serial")
107  serial = false;
108 #endif
109 #ifdef KOKKOS_ENABLE_OPENMP
110  else if (s == "omp")
111  omp = true;
112  else if (s == "no-omp")
113  omp = false;
114 #endif
115 #ifdef KOKKOS_ENABLE_THREADS
116  else if (s == "threads")
117  threads = true;
118  else if (s == "no-threads")
119  threads = false;
120 #endif
121  else if (s == "-h" || s == "--help")
122  print_usage = true;
123  else {
124  std::cout << "Invalid argument: " << s << std::endl;
125  print_usage = true;
126  }
127  ++i;
128  }
129  if (print_usage) {
130  std::cout << "Usage:" << std::endl
131  << "\t" << argv[0]
132  << " [no-][cuda|host|serial|omp|threads|block|flat|orig|deg|linear|symmetric] [single|double] [device device_id]"
133  << std::endl << "Defaults are all enabled." << std::endl;
134  return -1;
135  }
136 
137  if (test_host) {
138 
139 #ifdef KOKKOS_ENABLE_SERIAL
140  if (serial) {
141  if (single)
142  mainHost<float,Kokkos::Serial>(
143  test_flat, test_orig, test_deg, test_lin, test_block, symmetric, mkl);
144  else
145  mainHost<double,Kokkos::Serial>(
146  test_flat, test_orig, test_deg, test_lin, test_block, symmetric, mkl);
147  }
148 #endif
149 
150 #ifdef KOKKOS_ENABLE_THREADS
151  if (threads) {
152  if (single)
153  mainHost<float,Kokkos::Threads>(
154  test_flat, test_orig, test_deg, test_lin, test_block, symmetric, mkl);
155  else
156  mainHost<double,Kokkos::Threads>(
157  test_flat, test_orig, test_deg, test_lin, test_block, symmetric, mkl);
158  }
159 #endif
160 
161 #ifdef KOKKOS_ENABLE_OPENMP
162  if (omp) {
163  if (single)
164  mainHost<float,Kokkos::OpenMP>(
165  test_flat, test_orig, test_deg, test_lin, test_block, symmetric, mkl);
166  else
167  mainHost<double,Kokkos::OpenMP>(
168  test_flat, test_orig, test_deg, test_lin, test_block, symmetric, mkl);
169  }
170 #endif
171 
172  }
173 
174 #ifdef KOKKOS_ENABLE_CUDA
175  if (test_cuda) {
176  if (single)
177  mainCuda<float>(test_flat, test_orig, test_lin, test_block, symmetric, device);
178  else
179  mainCuda<double>(test_flat, test_orig, test_lin, test_block, symmetric, device);
180  }
181 #endif
182 
183  return 0 ;
184 }
void mainHost(const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const int use_print, const int use_trials, const int use_nodes[], const bool check, Kokkos::Example::FENL::DeviceConfig dev_config)
void mainCuda(const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const int use_print, const int use_trials, const int use_nodes[], const bool check, Kokkos::Example::FENL::DeviceConfig dev_config)
Kokkos::DefaultExecutionSpace device
int main(int argc, char **argv)
template int mainCuda< double >(bool, bool, bool, bool, bool, int)
template int mainCuda< float >(bool, bool, bool, bool, bool, int)