에서
감사하지 당신은 STL 벡터 대신 자신의 배열 클래스를 사용합니다. STL- 벡터의 직렬화는 이미 부스트/직렬화/vector.hpp에서 빌드됩니다. 당신이 할 수 당신이 뭔가 같이 복잡한 숫자의 배열을 보내려면 :
#include <vector>
#include <boost/mpi/environment.hpp>
#include <boost/mpi/communicator.hpp>
#include <boost/serialization/complex.hpp>
#include <boost/serialization/vector.hpp>
using namespace std;
namespace mpi=boost::mpi;
int main (int argc, char *argv[])
{
mpi::environment env(argc, argv);
mpi::communicator world;
int myid=world.rank();
int NN=world.size();
int N=10;
vector< complex<double> >A(N);
if (myid==0)
{
for (int i=0; i!=N; i++)
{
A[i]=complex<double>(i, i);
}
world.send(1, 0, A);
}
if (myid==1)
{
world.recv(0, 0, A);
cout << "###" << endl;
for (int i=0; i!=N; i++)
{
cout << A[i] << "\t" ;
}
cout << endl;
cout << "###" << endl;
}
}
그렇지 않다면, 당신은 당신의 벡터의 내용이 직렬화되는 데이터 유형을 확인해야합니다. 해당 데이터 유형의 직렬화가 부스트 직렬화 라이브러리에 포함되어 있지 않으면 직접 직렬화를 작성해야합니다.
namespace boost
{
namespace serialization
{
template<class Archive>
void serialize(Archive & ar, complex & c, const unsigned int version)
{
ar & c.real_imag;
}
}
}
을하지만, 내가 말한대로 STL의 복잡한 유형은 이미 부스트 직렬화에 구축되어이 트릭을 할해야처럼 somethink 위에서 복잡한 구조체에 대한 예를 들어 (테스트하지).
'class Array'와'struct complex'의 연결은 무엇입니까? –
내가 배열을 보내고 싶다고 말한대로. 따라서 클래스 complex는 배열 클래스의 템플릿 매개 변수입니다. –