LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: michael_cm_at_[hidden]
Date: 2004-06-04 08:20:12


Hi,

For a parallel programming project I use MPI to send messages. Using MPI I
have to define the type of the data buffer contained in the message.
Something like:

MPI_Send(&myInt, 1, MPI_INT, ...)

where MPI_INT is denotes that myInt is of type int. I now have the problem
that I have templated classes and want to send some class members:

template<class MyType>
class MyClass ...
(...)
MyType a;
(...)
MPI_Send(&a, 1, ...)

Obviously there is not predefined MPI_Datatype like MPI_MyType... Therefore
I use Traits:

MPI_Send(&a, 1, MPITraits<MyType>::datatype(), ...)

The MPITraits definition looks as follows:

----
#ifndef __MPITraits_h
#define __MPITraits_h
#include "mpi.h"
#include "itkCovariantVector.h"
template < class T >
class MPITraits {
	public:
	static inline MPI_Datatype datatype();
};
template <>
class MPITraits< signed char > {
	public:
		static inline MPI_Datatype datatype() {
			return MPI_CHAR;
		}
};
template <>
class MPITraits< signed short int > {
	public:
	static inline MPI_Datatype datatype() {
		return MPI_SHORT;
	}
};
(...)
----
Now I have some more difficult datatypes that just char, int and so on that
are templated as well. I have, for example 
template < >
class MPITraits< itk::CovariantVector<double, 2> > {
	public:
		static inline MPI_Datatype datatype() {
			MPI_Datatype covariant_vector_type;
			MPI_Type_contiguous(2, MPI_DOUBLE, &covariant_vector_type);
			MPI_Type_commit(&covariant_vector_type);
			return covariant_vector_type;
		}
};
Obviously it is not nice to write a new MPITraits entry for each combination
of <anothertype, dimension> of CovariantVector. I would like to be able to
somehow replace the MPI_Type_contiguous line with something like:
MPI_Type_contiguous(dimension, MPITraits<anothertype>::datatype(),
&covariant_vector_type);
Is there a way to do this (or something similar)?
Or is there a way to give a user a chance to define exactly the Traits
entries that are used in his application when the MPI_Send commands are in a
class within a library?
Thanks,
Michael
-- 
+++ Jetzt WLAN-Router für alle DSL-Einsteiger und Wechsler +++
GMX DSL-Powertarife zudem 3 Monate gratis* http://www.gmx.net/dsl