/**
 * vsg_packed_msg_isend:
 * @pm: a #VsgPackedMsg.
 * @dst: the destination task id.
 * @tag: an integer message tag.
 * @request: the corresponding request object
 *
 * Sends stored message to the specified destination with the specified tag in
 * a non blocking mode. @request is provided for output.
 */
void vsg_packed_msg_isend (VsgPackedMsg *pm, gint dst, gint tag,
                           MPI_Request *request)
{
  gint ierr;

  _trace_write_msg_send (pm, "isend", dst, tag);

  ierr = MPI_Isend (pm->buffer, pm->position, MPI_PACKED, dst, tag,
                    pm->communicator, request);

  if (ierr != MPI_SUCCESS) vsg_mpi_error_output (ierr);
}
Exemple #2
0
/**
 * vsg_packed_msg_ssend:
 * @pm: a #VsgPackedMsg.
 * @dst: the destination task id.
 * @tag: an integer message tag.
 *
 * Sends stored message to the specified destination with the specified tag.
 */
void vsg_packed_msg_ssend (VsgPackedMsg *pm, gint dst, gint tag)
{
  gint ierr;

  _trace_write_msg_send (pm, "ssend", dst, tag);

  _send_count ++;
  _send_size += pm->position;

  ierr = MPI_Ssend (pm->buffer, pm->position, MPI_PACKED, dst, tag,
                    pm->communicator);

  if (ierr != MPI_SUCCESS) vsg_mpi_error_output (ierr);
}
Exemple #3
0
/**
 * vsg_packed_msg_send_append:
 * @pm: a #VsgPackedMsg.
 * @buf: pointer to the beginning of data to be stored.
 * @count: number of @type data to store.
 * @type: type of the data to be stored.
 *
 * Appends @count instances of @type data to the message buffer.
 */
void vsg_packed_msg_send_append (VsgPackedMsg *pm, gpointer buf,
                                 gint count, MPI_Datatype type)
{
  gint pos, size, addsize;
  gint ierr;

  g_return_if_fail (pm != NULL);

  g_assert (pm->own_buffer == TRUE);

#ifdef VSG_PACKED_MSG_TRACE
  /* init msg id */
  if (pm->position == 0)
    {
      if (pm->buffer == NULL) pm->buffer = g_malloc0 (_PM_ID_SIZE);
      pm->size = MAX (pm->size, _PM_ID_SIZE);
      pm->allocated = pm->size;
      pm->position = _PM_BEGIN_POS;
    }
#endif

  pos = pm->position;
  size = pm->size;

  /* compute size of this new message part */
  MPI_Pack_size (count, type, pm->communicator, &addsize);

  /* allocate enough memory in message msg to store this message */
  if ((addsize + pos) > size)
    {
      size = MAX (size + 1024, addsize+pos);

      pm->buffer = g_realloc (pm->buffer, size * sizeof (char));

      pm->size = size;
      pm->allocated = pm->size;
    }

  ierr = MPI_Pack (buf, count, type, pm->buffer, size,
		   &pm->position, pm->communicator);

  if (ierr != MPI_SUCCESS) vsg_mpi_error_output (ierr);

}
Exemple #4
0
/**
 * vsg_packed_msg_recv_read:
 * @pm: a #VsgPackedMsg.
 * @buf: pointer to the beginning of data to be read.
 * @count: number of @type data to read.
 * @type: type of the data to be read.
 *
 * Reads @count instance of @type data from the current position in the buffer.
 * The position then is updated to the first byte after read data.
 */
void vsg_packed_msg_recv_read (VsgPackedMsg *pm, gpointer buf,
                               gint count, MPI_Datatype type)
{
  gint size;
  gint ierr;

  g_return_if_fail (pm != NULL);

  size = pm->size;

/*   { */
/*     gint mytid; */
/*     MPI_Comm_rank (pm->communicator, &mytid); */
/*     g_printerr ("%d: unpacking %d data at %d\n", mytid, count, pm->position); */
/*   } */

  ierr = MPI_Unpack (pm->buffer, size, &pm->position, 
		     buf, count, type,  pm->communicator);
  
  if (ierr != MPI_SUCCESS) vsg_mpi_error_output (ierr);

}
/**
 * vsg_packed_msg_bcast:
 * @pm: a #VsgPackedMsg.
 * @src: the source task id. Can be %MPI_ANY_SOURCE.
 * @tag: an integer message tag. Can be %MPI_ANY_TAG.
 *
 * Performs a MPI_Bcast on @pm. @pm must be of the same size across
 * all processes (ie. similar calls to vsg_packed_msg_send_append()
 * must have been previously issued on every processor).
 */
void vsg_packed_msg_bcast (VsgPackedMsg *pm, gint src)
{
  gint ierr;
  gint rk;

  g_assert (pm->own_buffer == TRUE);

  MPI_Comm_rank (pm->communicator, &rk);

  if (rk == src)
    _trace_write_msg_send (pm, "bcast-send", src, -1);

  ierr = MPI_Bcast (pm->buffer, pm->position, MPI_PACKED, src,
                    pm->communicator);

  if (rk != src)
    _trace_write_msg_recv (pm, "bcast-recv", src, -1);

  pm->position = _PM_BEGIN_POS;

  if (ierr != MPI_SUCCESS) vsg_mpi_error_output (ierr);
}
/**
 * vsg_packed_msg_recv:
 * @pm: a #VsgPackedMsg.
 * @src: the source task id. Can be %MPI_ANY_SOURCE.
 * @tag: an integer message tag. Can be %MPI_ANY_TAG.
 *
 * Receives a message from source @src with @tag message tag and stores it in
 * @pm. any previously stored data will be lost.
 */
void vsg_packed_msg_recv (VsgPackedMsg *pm, gint src, gint tag)
{
  MPI_Status status;
  gint ierr;
  gint rsize = 0;

  g_assert (pm->own_buffer == TRUE);

  MPI_Probe (src, tag, pm->communicator, &status);

  MPI_Get_count (&status, MPI_PACKED, &rsize);

  pm->buffer = g_realloc (pm->buffer, rsize);
  pm->size = rsize;

  ierr = MPI_Recv (pm->buffer, rsize, MPI_PACKED, src, tag,
                   pm->communicator, &status);

  _trace_write_msg_recv (pm, "recv", src, tag);

  pm->position = _PM_BEGIN_POS;

  if (ierr != MPI_SUCCESS) vsg_mpi_error_output (ierr);
}