Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
Tpetra_Details_initializeKokkos.cpp
1// @HEADER
2// *****************************************************************************
3// Tpetra: Templated Linear Algebra Services Package
4//
5// Copyright 2008 NTESS and the Tpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
11#include "Teuchos_GlobalMPISession.hpp"
12#include "Kokkos_Core.hpp"
13#include "Tpetra_Details_checkLaunchBlocking.hpp"
15#include <cstdlib> // std::atexit
16#include <string>
17#include <vector>
18
19namespace Tpetra {
20namespace Details {
21
22void finalizeKokkosIfNeeded() {
23 if(!Kokkos::is_finalized()) {
24 Kokkos::finalize();
25 }
26}
27
28void
30{
31 if (! Kokkos::is_initialized ()) {
32 std::vector<std::string> args = Teuchos::GlobalMPISession::getArgv ();
33 int narg = static_cast<int> (args.size ()); // must be nonconst
34
35 std::vector<char*> args_c;
36 std::vector<std::unique_ptr<char[]>> args_;
37 for (auto const& x : args) {
38 args_.emplace_back(new char[x.size() + 1]);
39 char* ptr = args_.back().get();
40 strcpy(ptr, x.c_str());
41 args_c.push_back(ptr);
42 }
43 args_c.push_back(nullptr);
44
45 Kokkos::initialize (narg, narg == 0 ? nullptr : args_c.data ());
46 checkOldCudaLaunchBlocking();
47
48 std::atexit (finalizeKokkosIfNeeded);
49
50 }
51 // Add Kokkos calls to the TimeMonitor if the environment says so
52 Tpetra::Details::AddKokkosDeepCopyToTimeMonitor();
53 Tpetra::Details::AddKokkosFenceToTimeMonitor();
54 Tpetra::Details::AddKokkosFunctionsToTimeMonitor();
55}
56
57} // namespace Details
58} // namespace Tpetra
59
Declaration functions that use Kokkos' profiling library to add deep copies between memory spaces,...
Declaration of Tpetra::Details::initializeKokkos.
Nonmember function that computes a residual Computes R = B - A * X.
void initializeKokkos()
Initialize Kokkos, using command-line arguments (if any) given to Teuchos::GlobalMPISession.
Namespace Tpetra contains the class and methods constituting the Tpetra library.