| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Trilinos: An Object-Oriented Solver Framework |
| 4 |
// |
| 5 |
// Copyright 2001-2024 NTESS and the Trilinos contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#include <Kokkos_Core.hpp> |
| 11 |
|
| 12 |
#include <fenl.hpp> |
| 13 |
#include <fenl_impl.hpp> |
| 14 |
#include <fenl_utils.hpp> |
| 15 |
|
| 16 |
//---------------------------------------------------------------------------- |
| 17 |
|
| 18 |
#include <Tpetra_Version.hpp> |
| 19 |
#include <Teuchos_Comm.hpp> |
| 20 |
#include <Teuchos_DefaultComm.hpp> |
| 21 |
#include <Teuchos_GlobalMPISession.hpp> |
| 22 |
#include <Teuchos_oblackholestream.hpp> |
| 23 |
#include <Teuchos_StandardCatchMacros.hpp> |
| 24 |
|
| 25 |
//---------------------------------------------------------------------------- |
| 26 |
|
| 27 |
template< class Device > |
| 28 |
bool run( const Teuchos::RCP<const Teuchos::Comm<int> > & comm , |
| 29 |
const CMD & cmd ) |
| 30 |
{ |
| 31 |
bool success = true; |
| 32 |
try { |
| 33 |
|
| 34 |
const int comm_rank = comm->getRank(); |
| 35 |
|
| 36 |
// Print output headers |
| 37 |
const std::vector< size_t > widths = |
| 38 |
print_headers( std::cout , cmd , comm_rank ); |
| 39 |
|
| 40 |
using Kokkos::Example::FENL::ElementComputationLinearCoefficient; |
| 41 |
using Kokkos::Example::BoxElemPart; |
| 42 |
using Kokkos::Example::FENL::fenl; |
| 43 |
using Kokkos::Example::FENL::Perf; |
| 44 |
|
| 45 |
const double bc_lower_value = 1 ; |
| 46 |
const double bc_upper_value = 2 ; |
| 47 |
|
| 48 |
ElementComputationLinearCoefficient |
| 49 |
linear_diffusion_coefficient( cmd.USE_DIFF_COEFF_LINEAR , |
| 50 |
cmd.USE_DIFF_COEFF_CONSTANT ); |
| 51 |
|
| 52 |
int nelem[3] = { cmd.USE_FIXTURE_X , |
| 53 |
cmd.USE_FIXTURE_Y , |
| 54 |
cmd.USE_FIXTURE_Z }; |
| 55 |
|
| 56 |
Perf perf; |
| 57 |
double response = 0; |
| 58 |
Teuchos::Array<double> response_gradient; |
| 59 |
if ( cmd.USE_FIXTURE_QUADRATIC ) { |
| 60 |
perf = fenl< double , Device , BoxElemPart::ElemQuadratic > |
| 61 |
( comm , cmd.USE_FENL_XML_FILE , |
| 62 |
cmd.PRINT , cmd.USE_TRIALS , |
| 63 |
cmd.USE_ATOMIC , cmd.USE_BELOS , cmd.USE_MUELU , |
| 64 |
cmd.USE_MEANBASED , |
| 65 |
nelem , linear_diffusion_coefficient, cmd.USE_ISOTROPIC , cmd.USE_COEFF_SRC , |
| 66 |
cmd.USE_COEFF_ADV , bc_lower_value , bc_upper_value , |
| 67 |
response , response_gradient ); |
| 68 |
} |
| 69 |
else { |
| 70 |
perf = fenl< double , Device , BoxElemPart::ElemLinear > |
| 71 |
( comm , cmd.USE_FENL_XML_FILE , |
| 72 |
cmd.PRINT , cmd.USE_TRIALS , |
| 73 |
cmd.USE_ATOMIC , cmd.USE_BELOS , cmd.USE_MUELU , |
| 74 |
cmd.USE_MEANBASED , |
| 75 |
nelem , linear_diffusion_coefficient, cmd.USE_ISOTROPIC , cmd.USE_COEFF_SRC , |
| 76 |
cmd.USE_COEFF_ADV , bc_lower_value , bc_upper_value , |
| 77 |
response , response_gradient ); |
| 78 |
} |
| 79 |
|
| 80 |
perf.response_mean = response; |
| 81 |
perf.response_std_dev = 0.0; |
| 82 |
|
| 83 |
if ( 0 == comm_rank ) { |
| 84 |
print_perf_value( std::cout , cmd , widths , perf ); |
| 85 |
} |
| 86 |
|
| 87 |
if ( cmd.SUMMARIZE ) { |
| 88 |
Teuchos::TimeMonitor::report (comm.ptr (), std::cout); |
| 89 |
print_memory_usage(std::cout, *comm); |
| 90 |
} |
| 91 |
|
| 92 |
} |
| 93 |
TEUCHOS_STANDARD_CATCH_STATEMENTS(true, std::cerr, success); |
| 94 |
|
| 95 |
return success; |
| 96 |
} |
| 97 |
|
| 98 |
//---------------------------------------------------------------------------- |
| 99 |
//---------------------------------------------------------------------------- |
| 100 |
|
| 101 |
int main( int argc , char ** argv ) |
| 102 |
{ |
| 103 |
Teuchos::oblackholestream blackHole; |
| 104 |
Teuchos::GlobalMPISession mpiSession (&argc, &argv, &blackHole); |
| 105 |
|
| 106 |
Teuchos::RCP<const Teuchos::Comm<int> > comm = |
| 107 |
Teuchos::DefaultComm<int>::getComm(); |
| 108 |
|
| 109 |
//-------------------------------------------------------------------------- |
| 110 |
CMD cmdline; |
| 111 |
clp_return_type rv = parse_cmdline( argc, argv, cmdline, *comm, false ); |
| 112 |
if (rv==CLP_HELP) |
| 113 |
return(EXIT_SUCCESS); |
| 114 |
else if (rv==CLP_ERROR) |
| 115 |
return(EXIT_FAILURE); |
| 116 |
|
| 117 |
{ |
| 118 |
Kokkos::initialize(argc, argv); |
| 119 |
|
| 120 |
if ( cmdline.VTUNE ) { |
| 121 |
connect_vtune(comm->getRank()); |
| 122 |
} |
| 123 |
|
| 124 |
if ( ! cmdline.ERROR && ! cmdline.ECHO ) { |
| 125 |
|
| 126 |
#if defined( HAVE_TPETRA_SERIAL ) |
| 127 |
if ( cmdline.USE_SERIAL ) { |
| 128 |
run< Kokkos::Serial >( comm , cmdline ); |
| 129 |
} |
| 130 |
#endif |
| 131 |
|
| 132 |
#if defined( HAVE_TPETRA_PTHREAD ) |
| 133 |
if ( cmdline.USE_THREADS ) { |
| 134 |
run< Kokkos::Threads >( comm , cmdline ); |
| 135 |
} |
| 136 |
#endif |
| 137 |
|
| 138 |
#if defined( HAVE_TPETRA_OPENMP ) |
| 139 |
if ( cmdline.USE_OPENMP ) { |
| 140 |
run< Kokkos::OpenMP >( comm , cmdline ); |
| 141 |
} |
| 142 |
#endif |
| 143 |
|
| 144 |
#if defined( HAVE_TPETRA_CUDA ) |
| 145 |
if ( cmdline.USE_CUDA ) { |
| 146 |
run< Kokkos::Cuda >( comm , cmdline ); |
| 147 |
} |
| 148 |
#endif |
| 149 |
|
| 150 |
} |
| 151 |
|
| 152 |
} |
| 153 |
Kokkos::finalize(); |
| 154 |
|
| 155 |
//-------------------------------------------------------------------------- |
| 156 |
|
| 157 |
return cmdline.ERROR ? -1 : 0 ; |
| 158 |
} |