NimbleSM
NimbleSM is a solid mechanics simulation code for dynamic systems
Loading...
Searching...
No Matches
nimble_vector_communicator.h
Go to the documentation of this file.
1/*
2//@HEADER
3// ************************************************************************
4//
5// NimbleSM
6// Copyright 2018
7// National Technology & Engineering Solutions of Sandia, LLC (NTESS)
8//
9// Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government
10// retains certain rights in this software.
11//
12// Redistribution and use in source and binary forms, with or without
13// modification, are permitted provided that the following conditions are
14// met:
15//
16// 1. Redistributions of source code must retain the above copyright
17// notice, this list of conditions and the following disclaimer.
18//
19// 2. Redistributions in binary form must reproduce the above copyright
20// notice, this list of conditions and the following disclaimer in the
21// documentation and/or other materials provided with the distribution.
22//
23// 3. Neither the name of the Corporation nor the names of the
24// contributors may be used to endorse or promote products derived from
25// this software without specific prior written permission.
26//
27// THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY EXPRESS OR IMPLIED
28// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
29// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
30// NO EVENT SHALL NTESS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
32// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact David Littlewood (djlittl@sandia.gov)
39//
40// ************************************************************************
41//@HEADER
42*/
43
44#ifndef NIMBLE_VECTOR_COMMUNICATOR_H
45#define NIMBLE_VECTOR_COMMUNICATOR_H
46
47#include <algorithm>
48#include <exception>
49#include <iostream>
50#include <memory>
51#include <string>
52#include <tuple>
53#include <vector>
54
55#ifdef NIMBLE_HAVE_MPI
56#include <mpi.h>
57
59#endif
60
61#ifdef NIMBLE_HAVE_TRILINOS
62#include "nimble_tpetra_utils.h"
63#endif
64
65#ifdef NIMBLE_HAVE_TRILINOS
66typedef Teuchos::RCP<const Teuchos::Comm<int>> comm_type;
67#else
68typedef int comm_type;
69#endif
70
71namespace nimble {
72
74{
75 int dim_ = 3;
76 unsigned int num_nodes_ = 0;
77#ifdef NIMBLE_HAVE_TRILINOS
78 comm_type comm_;
79#else
80 comm_type comm_ = 0;
81#endif
82
83#ifdef NIMBLE_HAVE_MPI
84 std::unique_ptr<reduction::ReductionInfo> MeshReductionInfo = nullptr;
85#endif
86
87#ifdef NIMBLE_HAVE_TRILINOS
88 std::unique_ptr<nimble::TpetraContainer> TpetraReductionInfo = nullptr;
89#endif
90
91 public:
92 VectorCommunicator() = default;
93
94 VectorCommunicator(int d, unsigned int n, comm_type comm) : dim_(d), num_nodes_(n), comm_(comm) {}
95
97
98 // The goal of this function is to set up all the bookkeeping so that the
99 // VectorReduction() function can be performed as quickly as possible We'll
100 // need, for example, a list of the nodes that are shared and the rank(s) that
101 // they're shared with Then, in VectorReduction, we'll send arrays of data
102 // to/from ranks that share nodes To start with, each rank has a list of its
103 // global nodes (this is passed in as global_node_ids)
104 void
105 Initialize(std::vector<int> const& global_node_ids)
106 {
107#ifdef NIMBLE_HAVE_TRILINOS
108 if (comm_) {
109 auto tpetra_container = new nimble::TpetraContainer();
110 TpetraReductionInfo.reset(tpetra_container);
111 TpetraReductionInfo->Initialize(dim_, num_nodes_, comm_, global_node_ids);
112 }
113#endif
114
115#ifdef NIMBLE_HAVE_MPI
116 {
117 MPI_Comm duplicate_of_world;
118 MPI_Comm_dup(MPI_COMM_WORLD, &duplicate_of_world);
119 mpicontext context{duplicate_of_world};
120 reduction::ReductionInfo* reduction_info = reduction::GenerateReductionInfo(global_node_ids, context);
121 MeshReductionInfo.reset(reduction_info);
122 }
123#endif
124 }
125
126 /// \brief
127 ///
128 /// \param node_local_ids
129 /// \param min_rank_containing_node
130 void
131 GetPartitionBoundaryNodeLocalIds(std::vector<int>& node_local_ids, std::vector<int>& min_rank_containing_node)
132 {
133#ifdef NIMBLE_HAVE_MPI
134 MeshReductionInfo->GetAllIndices(node_local_ids, min_rank_containing_node);
135#else
136 min_rank_containing_node.push_back(0);
137#endif
138 }
139
140 /// \brief
141 ///
142 /// \param data_dimension
143 /// \param data
144 void
145 VectorReduction(int data_dimension, double* data)
146 {
147#ifdef NIMBLE_HAVE_TRILINOS
148 if (TpetraReductionInfo) {
149 TpetraReductionInfo->VectorReduction(data_dimension, data);
150 return;
151 }
152#endif
153
154#ifdef NIMBLE_HAVE_MPI
155 MeshReductionInfo->PerformReduction(data, data_dimension);
156#endif
157 }
158
159 /// \brief
160 ///
161 /// \tparam Lookup
162 /// \param data_dimension
163 /// \param lookup
164 template <class Lookup>
165 void
166 VectorReduction(int data_dimension, Lookup&& lookup)
167 {
168#ifdef NIMBLE_HAVE_MPI
169 MeshReductionInfo->PerformReduction(lookup, data_dimension);
170#endif
171 }
172};
173} // namespace nimble
174
175#endif // NIMBLE_MPI_UTILS_H
Definition nimble_tpetra_utils.h:119
void GetPartitionBoundaryNodeLocalIds(std::vector< int > &node_local_ids, std::vector< int > &min_rank_containing_node)
Definition nimble_vector_communicator.h:131
void VectorReduction(int data_dimension, Lookup &&lookup)
Definition nimble_vector_communicator.h:166
VectorCommunicator(int d, unsigned int n, comm_type comm)
Definition nimble_vector_communicator.h:94
void VectorReduction(int data_dimension, double *data)
Definition nimble_vector_communicator.h:145
void Initialize(std::vector< int > const &global_node_ids)
Definition nimble_vector_communicator.h:105
Definition nimble.mpi.mpicontext.h:63
Definition kokkos_contact_manager.h:49
int comm_type
Definition nimble_tpetra_utils.h:75