Line data Source code
1 : // The libMesh Finite Element Library. 2 : // Copyright (C) 2002-2026 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 : #ifndef LIBMESH_LIBMESH_BASE_H 21 : #define LIBMESH_LIBMESH_BASE_H 22 : 23 : #include "libmesh/id_types.h" 24 : 25 : namespace libMesh { 26 : 27 : /** 28 : * \returns The number of processors libMesh was initialized with. 29 : */ 30 : processor_id_type global_n_processors(); 31 : 32 : /** 33 : * \returns The index of the local processor with respect to the 34 : * original MPI pool libMesh was initialized with. 35 : */ 36 : processor_id_type global_processor_id(); 37 : 38 : /** 39 : * \returns The maximum number of threads used in the simulation. 40 : */ 41 : unsigned int n_threads(); 42 : 43 : /** 44 : * \returns The default grain size (work unit, chunk size), typically 45 : * measured in nodes or elements or vector indices, below which work 46 : * will not be split between additional threads. 47 : */ 48 : unsigned int default_grainsize(); 49 : 50 : /** 51 : * Namespaces don't provide private data, 52 : * so let's take the data we would like 53 : * private and put it in an obnoxious 54 : * namespace. At least that way it is a 55 : * pain to use, thus discouraging errors. 56 : */ 57 : namespace libMeshPrivateData { 58 : #ifdef LIBMESH_HAVE_MPI 59 : /** 60 : * Total number of processors used. 61 : */ 62 : extern processor_id_type _n_processors; 63 : 64 : /** 65 : * The local processor id. 66 : */ 67 : extern processor_id_type _processor_id; 68 : #endif 69 : 70 : /** 71 : * Total number of threads possible. 72 : */ 73 : extern int _n_threads; 74 : 75 : /** 76 : * Minimum number of elements/nodes/indices per thread above which we 77 : * can split work onto more threads. 78 : */ 79 : extern unsigned int _default_grainsize; 80 : } 81 : } 82 : 83 : 84 : 85 : // ------------------------------------------------------------ 86 : // libMesh inline member functions 87 : inline 88 953 : libMesh::processor_id_type libMesh::global_n_processors() 89 : { 90 : #ifdef LIBMESH_HAVE_MPI 91 7124 : return libMeshPrivateData::_n_processors; 92 : #else 93 : return 1; 94 : #endif 95 : } 96 : 97 : inline 98 874 : libMesh::processor_id_type libMesh::global_processor_id() 99 : { 100 : #ifdef LIBMESH_HAVE_MPI 101 1479304 : return libMeshPrivateData::_processor_id; 102 : #else 103 : return 0; 104 : #endif 105 : } 106 : 107 : 108 : inline 109 83744 : unsigned int libMesh::n_threads() 110 : { 111 9435203 : return static_cast<unsigned int>(libMeshPrivateData::_n_threads); 112 : } 113 : 114 : 115 : 116 : inline 117 22001 : unsigned int libMesh::default_grainsize() 118 : { 119 5380202 : return libMeshPrivateData::_default_grainsize; 120 : } 121 : 122 : 123 : 124 : // We now put everything we can into a separate libMesh namespace; 125 : // code which forward declares libMesh classes or which specializes 126 : // libMesh templates may want to know whether it is compiling under 127 : // such conditions, to be backward compatible with older libMesh 128 : // versions: 129 : #define LIBMESH_USE_SEPARATE_NAMESPACE 1 130 : 131 : 132 : // Unless configured otherwise, we import all of namespace libMesh, 133 : // for backwards compatibility with pre-namespaced codes. 134 : 135 : #ifndef LIBMESH_REQUIRE_SEPARATE_NAMESPACE 136 : using namespace libMesh; 137 : #endif 138 : 139 : 140 : #endif // LIBMESH_LIBMESH_BASE_H