$extrastylesheet
parallel_object.h
Go to the documentation of this file.
00001 // The libMesh Finite Element Library.
00002 // Copyright (C) 2002-2013 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
00003 
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2.1 of the License, or (at your option) any later version.
00008 
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 
00014 // You should have received a copy of the GNU Lesser General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 
00019 
00020 #ifndef LIBMESH_PARALLEL_OBJECT_H
00021 #define LIBMESH_PARALLEL_OBJECT_H
00022 
00023 
00024 // Local includes
00025 #include "libmesh/parallel.h"
00026 
00027 // Macro to identify and debug functions which should only be called in
00028 // parallel on every processor at once
00029 #undef parallel_object_only
00030 #ifndef NDEBUG
00031 #define parallel_object_only() libmesh_parallel_only(this->comm())
00032 #else
00033 #define parallel_object_only()  ((void) 0)
00034 #endif
00035 
00036 
00037 namespace libMesh
00038 {
00047 class ParallelObject
00048 {
00049 public:
00050 
00055   ParallelObject (const Parallel::Communicator &comm_in) :
00056     _communicator(comm_in)
00057   {}
00058 
00062   ParallelObject (const ParallelObject &other) :
00063     _communicator(other._communicator)
00064   {}
00065 
00071   ParallelObject & operator= (const ParallelObject & libmesh_dbg_var(other))
00072   {
00073     libmesh_assert_equal_to (&_communicator, &other._communicator);
00074     return *this;
00075   }
00076 
00080   virtual ~ParallelObject () {}
00081 
00086   const Parallel::Communicator & comm () const
00087   { return _communicator; }
00088 
00092   processor_id_type n_processors () const
00093   { return cast_int<processor_id_type>(_communicator.size()); }
00094 
00098   processor_id_type processor_id () const
00099   { return cast_int<processor_id_type>(_communicator.rank()); }
00100 
00101 
00102 protected:
00103 
00104   const Parallel::Communicator &_communicator;
00105 };
00106 } // namespace libMesh
00107 
00108 #endif // LIBMESH_PARALLEL_OBJECT_H