+
+int smpi_mpi_pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm){
+ size_t size = smpi_datatype_size(type);
+ if (outcount - *position < incount*size)
+ return MPI_ERR_BUFFER;
+ smpi_datatype_copy(inbuf, incount, type,
+ (char*)outbuf + *position, outcount, MPI_CHAR);
+ *position += incount * size;
+ return MPI_SUCCESS;
+}
+
+int smpi_mpi_unpack(void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm){
+ size_t size = smpi_datatype_size(type);
+ if (outcount*size> insize)
+ return MPI_ERR_BUFFER;
+ smpi_datatype_copy((char*)inbuf + *position, insize, MPI_CHAR,
+ outbuf, outcount, type);
+ *position += outcount * size;
+ return MPI_SUCCESS;
+}
+