LAM/MPI logo

LAM/MPI General User's Mailing List Archives

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

From: Márcia Marra (marciacmarra_at_[hidden])
Date: 2006-02-16 06:43:09


Hi, all!

I'm trying to send a collection of data, packed with the funcion
MPI::PACK and have not had any luck getting it to work. When I execute
the program, I receive the error "MPI_Pack_size: invalid datatype
argument: Invalid argument (rank 0, MPI_COMM_WORLD)". I think that the
problem is that I am not passing the datatype for the methods
MPI::Pack_size() and MPI::Pack() but I don't know how to to this. The
header of these methods are:

virtual int Pack_size(int intcount, const Comm& comm) const
virtual int Pack(const void* inbuf, int intcount, void *outbuf, int
outsize, int& position, const Comm& comm) const

How can I pass this information? Can anyone point me to the mistake I am
making?
 
Here is the portion of the code that deals with the pack and unpack:

int Classe1::sendPack() {

   int inteiro1, inteiro2, procs, i;
   int position = 0;

   char *message;
   int memberSize, maxSize;

   MPI::Datatype problemType;

   procs = MPI::COMM_WORLD.Get_size();

   memberSize = problemType.Pack_size(1, MPI::COMM_WORLD);
   maxSize = memberSize;

   memberSize = problemType.Pack_size(1, MPI::COMM_WORLD);
   maxSize = maxSize + memberSize;

   message = (char*)malloc(maxSize);

  for (i=0; i<procs-1; i++)
      MPI::COMM_WORLD.Send(&maxSize, 1, MPI::INT, i, 1 );

   for (i=0; i<procs-1; i++) {
      inteiro1 = 10;
      inteiro2 = i;

      problemType.Pack(&inteiro1, 1, message, maxSize, position,
MPI::COMM_WORLD);
      problemType.Pack(&inteiro2, 1, message, maxSize, position,
MPI::COMM_WORLD);

      MPI::COMM_WORLD.Send(&message, 1, MPI::PACKED, i, 2);
   }
   return 0;
}

int Classe1::receivePack() {

   int tamanhoMensagem;
   char *mensagem;
   int position = 0;
   int rank;
   int num1 = 0;
   int num2 = 0;

   int tamanhoMsg;

   MPI::Datatype tipo;
   MPI::Status status;

   MPI::COMM_WORLD.Recv(&tamanhoMensagem, 1, MPI::INT, 0, 1, status);
   mensagem = (char*)malloc(tamanhoMensagem);

   MPI::COMM_WORLD.Recv(&mensagem, 1, MPI::PACKED, 0, 2, status);

   tamanhoMsg = tipo.Get_size();

   tipo.Unpack(mensagem, tamanhoMsg, &num1, 1, position, MPI::COMM_WORLD);
   tipo.Unpack(mensagem, tamanhoMsg, &num2, 1, position, MPI::COMM_WORLD);

   rank = MPI::COMM_WORLD.Get_rank();

   cout << "I'm the slave " << rank << " and I have received the numbers
" << num1 << " and " << num2 << endl;

   return 0;
}

Thanks in advance,

Márcia.