Sacado Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
advection_const_basis/driver.cpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Sacado Package
5// Copyright (2006) Sandia Corporation
6//
7// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8// the U.S. Government retains certain rights in this software.
9//
10// This library is free software; you can redistribute it and/or modify
11// it under the terms of the GNU Lesser General Public License as
12// published by the Free Software Foundation; either version 2.1 of the
13// License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23// USA
24// Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25// (etphipp@sandia.gov).
26//
27// ***********************************************************************
28// @HEADER
29
30// A performance test that computes the derivative of a simple Kokkos kernel
31// using various Fad classes
32
33#include "Sacado.hpp"
34
35#include "advection.hpp"
38#include "common.hpp"
39
40#include "Teuchos_CommandLineProcessor.hpp"
41#include "Teuchos_StandardCatchMacros.hpp"
42
43template <typename ExecSpace>
44void run(const int cell_begin, const int cell_end, const int cell_step,
45 const int nbasis, const int npoint, const int ntrial, const bool check)
46{
47 const int ndim = 3;
48 printf("ncell %12s %12s %12s %12s %12s %12s %12s %12s %12s %12s %12s\n", "flat sfad", "flat slfad", "flat dfad", "dfad sc", "analytic", "const", "team", "hier sfad", "hier slfad", "hier dfad", "h dfad sc");
49 for(int i=cell_begin; i<=cell_end; i+=cell_step) {
50 double sfad_flat = time_fad_flat<SFadType,fad_dim,ExecSpace>(
51 i,nbasis,npoint,ndim,ntrial,check);
52 double slfad_flat = time_fad_flat<SLFadType,fad_dim,ExecSpace>(
53 i,nbasis,npoint,ndim,ntrial,check);
54 double dfad_flat = time_fad_flat<DFadType,fad_dim,ExecSpace>(
55 i,nbasis,npoint,ndim,ntrial,check);
56 double dfad_scratch = time_fad_scratch<DFadType,fad_dim,ExecSpace>(
57 i,nbasis,npoint,ndim,ntrial,check);
58 double analytic = time_analytic_flat<fad_dim,ExecSpace>(
59 i,nbasis,npoint,ndim,ntrial,check);
60 double analytic_const = time_analytic_const<fad_dim,ExecSpace>(
61 i,nbasis,npoint,ndim,ntrial,check);
62 double analytic_team = time_analytic_team<fad_dim,ExecSpace>(
63 i,nbasis,npoint,ndim,ntrial,check);
64 double sfad_hierarchical = time_fad_hierarchical_team<SFadType,fad_dim,ExecSpace>(
65 i,nbasis,npoint,ndim,ntrial,check);
66 double slfad_hierarchical = time_fad_hierarchical_team<SLFadType,fad_dim,ExecSpace>(
67 i,nbasis,npoint,ndim,ntrial,check);
68 double dfad_hierarchical = time_dfad_hierarchical_team<fad_dim,ExecSpace>(
69 i,nbasis,npoint,ndim,ntrial,check);
70 double dfad_hierarchical_scratch =
71 time_dfad_hierarchical_team_scratch<fad_dim,ExecSpace>(
72 i,nbasis,npoint,ndim,ntrial,check);
73 printf("%5d %12.3e %12.3e %12.3e %12.3e %12.3e %12.3e %12.3e %12.3e %12.3e %12.3e %12.3e\n",i,sfad_flat,slfad_flat,dfad_flat,dfad_scratch,analytic,analytic_const,analytic_team,sfad_hierarchical,slfad_hierarchical,dfad_hierarchical,dfad_hierarchical_scratch);
74 }
75}
76
77int main(int argc, char* argv[]) {
78 Kokkos::initialize(argc,argv);
79
80 bool success = true;
81 try {
82
83 // Set up command line options
84 Teuchos::CommandLineProcessor clp(false);
85 clp.setDocString("This program tests the speed of various forward mode AD implementations for simple Kokkos kernel");
86#ifdef KOKKOS_ENABLE_SERIAL
87 bool serial = 0;
88 clp.setOption("serial", "no-serial", &serial, "Whether to run Serial");
89#endif
90#ifdef KOKKOS_ENABLE_OPENMP
91 bool openmp = 0;
92 clp.setOption("openmp", "no-openmp", &openmp, "Whether to run OpenMP");
93#endif
94#ifdef KOKKOS_ENABLE_THREADS
95 bool threads = 0;
96 clp.setOption("threads", "no-threads", &threads, "Whether to run Threads");
97#endif
98#ifdef KOKKOS_ENABLE_CUDA
99 bool cuda = 0;
100 clp.setOption("cuda", "no-cuda", &cuda, "Whether to run CUDA");
101#endif
102 bool print_config = false;
103 clp.setOption("print-config", "no-print-config", &print_config,
104 "Whether to print Kokkos device configuration");
105 int cell_begin = 100;
106 clp.setOption("begin", &cell_begin, "Starting number of cells");
107 int cell_end = 8000;
108 clp.setOption("end", &cell_end, "Ending number of cells");
109 int cell_step = 100;
110 clp.setOption("step", &cell_step, "Cell increment");
111 int nbasis = 8;
112 clp.setOption("basis", &nbasis, "Number of basis functions");
113 int npoint = 8;
114 clp.setOption("point", &npoint, "Number of integration points");
115 int ntrial = 5;
116 clp.setOption("trial", &ntrial, "Number of trials");
117 bool check = false;
118 clp.setOption("check", "no-check", &check,
119 "Check correctness of results");
120
121 // Parse options
122 switch (clp.parse(argc, argv)) {
123 case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED:
124 return 0;
125 case Teuchos::CommandLineProcessor::PARSE_ERROR:
126 case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION:
127 return 1;
128 case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL:
129 break;
130 }
131
132 if (print_config)
133 Kokkos::print_configuration(std::cout, true);
134
135#ifdef KOKKOS_ENABLE_SERIAL
136 if (serial) {
137 using Kokkos::Serial;
138 run<Serial>(cell_begin, cell_end, cell_step, nbasis, npoint, ntrial, check);
139 }
140#endif
141
142#ifdef KOKKOS_ENABLE_OPENMP
143 if (openmp) {
144 using Kokkos::OpenMP;
145 run<OpenMP>(cell_begin, cell_end, cell_step, nbasis, npoint, ntrial, check);
146 }
147#endif
148
149#ifdef KOKKOS_ENABLE_THREADS
150 if (threads) {
151 using Kokkos::Threads;
152 run<Threads>(cell_begin, cell_end, cell_step, nbasis, npoint, ntrial, check);
153 }
154#endif
155
156#ifdef KOKKOS_ENABLE_CUDA
157 if (cuda) {
158 using Kokkos::Cuda;
159 run<Cuda>(cell_begin, cell_end, cell_step, nbasis, npoint, ntrial, check);
160 }
161#endif
162 }
163 TEUCHOS_STANDARD_CATCH_STATEMENTS(true, std::cerr, success);
164
165 Kokkos::finalize();
166
167 return !success;
168}
int main()
void run(const int cell_begin, const int cell_end, const int cell_step, const int nbasis, const int npoint, const int ntrial, const bool check)
int check(Epetra_CrsGraph &A, int NumMyRows1, int NumGlobalRows1, int NumMyNonzeros1, int NumGlobalNonzeros1, int *MyGlobalElements, bool verbose)