pack.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "mpiP.h"
  2. /*
  3. *
  4. */
  5. FC_FUNC( mpi_pack , MPI_PACK )
  6. ( void *inbuf, int *incount, int *datatype,
  7. void *outbuf, int *outsize, int *position, int *comm, int *ierror)
  8. {
  9. *ierror=MPI_Pack(inbuf, *incount,* datatype,
  10. outbuf, *outsize, position, *comm);
  11. }
  12. int MPI_Pack( void *inbuf, int incount, MPI_Datatype datatype,
  13. void *outbuf, int outsize, int *position, MPI_Comm comm)
  14. {
  15. int size;
  16. size=datatype*incount;
  17. if ( (*position)+size > outsize)
  18. {
  19. fprintf(stderr,"MPI_Pack: ran out of space in outbuf\n");
  20. abort();
  21. }
  22. memcpy( (char *)outbuf+(*position), inbuf, size);
  23. (*position)+=size;
  24. return(MPI_SUCCESS);
  25. }
  26. /*
  27. *
  28. */
  29. FC_FUNC( mpi_unpack , MPI_UNPACK )
  30. ( void *inbuf, int *insize, int *position,
  31. void *outbuf, int *outcount, int *datatype,
  32. int *comm, int *ierror )
  33. {
  34. *ierror=MPI_Unpack( inbuf, *insize, position,
  35. outbuf, *outcount, *datatype, *comm);
  36. }
  37. int MPI_Unpack( void *inbuf, int insize, int *position,
  38. void *outbuf, int outcount, MPI_Datatype datatype,
  39. MPI_Comm comm )
  40. {
  41. int size;
  42. size=datatype*outcount;
  43. if ( (*position)+size > insize )
  44. {
  45. fprintf(stderr,"MPI_Unpack: ran out of data in inbuf\n");
  46. abort();
  47. }
  48. memcpy(outbuf, (char *)inbuf+(*position) , size);
  49. (*position)+=size;
  50. return(MPI_SUCCESS);
  51. }