mirror of
https://github.com/boostorg/mpi.git
synced 2026-02-25 16:32:22 +00:00
Refactor mpi_datatype_cache to fix problems on VC9
[SVN r44160]
This commit is contained in:
@@ -182,7 +182,7 @@ struct is_mpi_datatype
|
||||
template<typename T> MPI_Datatype get_mpi_datatype(const T& x)
|
||||
{
|
||||
BOOST_MPL_ASSERT((is_mpi_datatype<T>));
|
||||
return detail::mpi_datatype_cache.datatype(x);
|
||||
return detail::mpi_datatype_cache().datatype(x);
|
||||
}
|
||||
|
||||
// Don't parse this part when we're generating Doxygen documentation.
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <map>
|
||||
#include <typeinfo>
|
||||
|
||||
// The std::type_info::before function in Visual C++ 8.0 (and probably earlier)
|
||||
@@ -47,21 +46,15 @@ struct type_info_compare
|
||||
///
|
||||
///
|
||||
class BOOST_MPI_DECL mpi_datatype_map
|
||||
: private std::map<std::type_info const*,MPI_Datatype,type_info_compare>,
|
||||
public boost::noncopyable
|
||||
: public boost::noncopyable
|
||||
{
|
||||
public:
|
||||
mpi_datatype_map()
|
||||
{}
|
||||
struct implementation;
|
||||
|
||||
~mpi_datatype_map()
|
||||
{
|
||||
// do not free after call to MPI_FInalize
|
||||
int finalized=0;
|
||||
BOOST_MPI_CHECK_RESULT(MPI_Finalized,(&finalized));
|
||||
if (!finalized)
|
||||
free();
|
||||
}
|
||||
implementation *impl;
|
||||
|
||||
public:
|
||||
mpi_datatype_map();
|
||||
~mpi_datatype_map();
|
||||
|
||||
template <class T>
|
||||
MPI_Datatype datatype(const T& x = T(), typename boost::enable_if<is_mpi_builtin_datatype<T> >::type* =0)
|
||||
@@ -76,30 +69,24 @@ public:
|
||||
|
||||
// check whether the type already exists
|
||||
std::type_info const* t = &typeid(T);
|
||||
const_iterator it = find(t);
|
||||
if(it ==end())
|
||||
{
|
||||
MPI_Datatype datatype = get(t);
|
||||
if (datatype == MPI_DATATYPE_NULL) {
|
||||
// need to create a type
|
||||
mpi_datatype_oarchive ar(x);
|
||||
insert(std::make_pair(t,ar.get_mpi_datatype()));
|
||||
it = find(t);
|
||||
datatype = ar.get_mpi_datatype();
|
||||
set(t, datatype);
|
||||
}
|
||||
|
||||
return it->second;
|
||||
return datatype;
|
||||
}
|
||||
|
||||
private:
|
||||
// free all MPI data types
|
||||
void free()
|
||||
{
|
||||
// ignore errors in the destructor
|
||||
for (iterator it=begin(); it !=end(); ++it)
|
||||
MPI_Type_free(&(it->second));
|
||||
}
|
||||
|
||||
MPI_Datatype get(const std::type_info* t);
|
||||
void set(const std::type_info* t, MPI_Datatype datatype);
|
||||
};
|
||||
|
||||
extern mpi_datatype_map mpi_datatype_cache;
|
||||
/// Retrieve the MPI datatype cache
|
||||
mpi_datatype_map& mpi_datatype_cache();
|
||||
|
||||
} } } // end namespace boost::mpi::detail
|
||||
|
||||
|
||||
Reference in New Issue
Block a user