Line data Source code
1 : // The libMesh Finite Element Library. 2 : // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 3 : 4 : // This library is free software; you can redistribute it and/or 5 : // modify it under the terms of the GNU Lesser General Public 6 : // License as published by the Free Software Foundation; either 7 : // version 2.1 of the License, or (at your option) any later version. 8 : 9 : // This library is distributed in the hope that it will be useful, 10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 : // Lesser General Public License for more details. 13 : 14 : // You should have received a copy of the GNU Lesser General Public 15 : // License along with this library; if not, write to the Free Software 16 : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 : 18 : 19 : 20 : // Local includes 21 : #include "libmesh/remote_elem.h" 22 : #include "libmesh/libmesh_singleton.h" 23 : #include "libmesh/threads.h" 24 : 25 : 26 : 27 : namespace 28 : { 29 : using namespace libMesh; 30 : 31 : // Class to be dispatched by Singleton::setup() 32 : // to create the \p RemoteElem singleton. 33 : // While this actual object has file-level static 34 : // scope and will be initialized before main(), 35 : // importantly the setup() method will not be invoked 36 : // until after main(). 37 : class RemoteElemSetup : public Singleton::Setup 38 : { 39 16381 : void setup () 40 : { 41 16381 : RemoteElem::create(); 42 16381 : } 43 : } remote_elem_setup; 44 : 45 : } 46 : 47 : 48 : 49 : namespace libMesh 50 : { 51 : 52 : // Pointer to singleton RemoteElem. As an extern variable with static 53 : // storage duration, its initial value is nullptr, however we also 54 : // explicitly initialize it to nullptr to avoid any possible 55 : // confusion. The actual remote_elem is constructed when 56 : // Singleton::setup() is called in the libMeshInit constructor. 57 : const RemoteElem * remote_elem = nullptr; 58 : 59 32762 : RemoteElem::~RemoteElem() 60 : { 61 16381 : remote_elem = nullptr; 62 : 63 : // Putting this somewhere to unconfuse Nvidia, which thinks an 64 : // object used solely to invoke its constructor is "never 65 : // referenced". 66 462 : libmesh_ignore(remote_elem_setup); 67 32762 : } 68 : 69 : 70 : 71 16381 : const Elem & RemoteElem::create () 72 : { 73 : // The RemoteElem constructor is private, and RemoteElem::create() 74 : // is a static member function, so this makes it difficult to use 75 : // std::make_unique<RemoteElem> here. Therefore we just resort to 76 : // using the traditional "new" in this instance. 77 16381 : if (remote_elem == nullptr) 78 16381 : remote_elem = new RemoteElem; 79 : 80 16381 : return *remote_elem; 81 : } 82 : 83 : 84 : } // namespace libMesh