本文整理汇总了C++中MPI_Pack函数的典型用法代码示例。如果您正苦于以下问题:C++ MPI_Pack函数的具体用法?C++ MPI_Pack怎么用?C++ MPI_Pack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MPI_Pack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: send_struct
//number of atoms, types and backbone atoms
void send_struct(int *nback, int iproc, int nprocs, int *nat, int *ntypes, MPI_Status astatus)
{
int buffer_size, position,i;
char buffer[buffer_max];
buffer_size = 3*sizeof(int);
if(buffer_size>buffer_max)
{
fprintf(stderr,"Buffer too small\n");
MPI_Finalize();
exit(1);
}
if(iproc==0)
{
position = 0;
MPI_Pack(nat,1,MPI_INT,buffer,buffer_size,&position,MPI_COMM_WORLD);
MPI_Pack(ntypes,1,MPI_INT,buffer,buffer_size,&position,MPI_COMM_WORLD);
MPI_Pack(nback,1,MPI_INT,buffer,buffer_size,&position,MPI_COMM_WORLD);
for(i=1;i<nprocs;i++) MPI_Send(buffer,position,MPI_PACKED,i, 200+i, MPI_COMM_WORLD);
}
if(iproc!=0)
{
MPI_Recv(buffer,buffer_size,MPI_PACKED,0, 200+iproc, MPI_COMM_WORLD, &astatus);
position=0;
MPI_Unpack(buffer,buffer_size,&position,nat,1,MPI_INT,MPI_COMM_WORLD);
MPI_Unpack(buffer,buffer_size,&position,ntypes,1,MPI_INT,MPI_COMM_WORLD);
MPI_Unpack(buffer,buffer_size,&position,nback,1,MPI_INT,MPI_COMM_WORLD);
}
return;
}
示例2: pack_solution
void pack_solution(void* buff, int buff_size, int* pos, solution_vector vec, float score,
MPI_Comm comm, void* problem_data) {
color_assignment* cassign = (color_assignment*) vec;
MPI_Pack(&score, 1, MPI_FLOAT, buff, buff_size, pos, comm);
MPI_Pack(&cassign->curr_length, 1, MPI_INT, buff, buff_size, pos, comm);
MPI_Pack(cassign->vertex_colors, cassign->max_length, MPI_INT, buff, buff_size, pos, comm);
}
示例3: DCellPack
// Pack DCell into buffer: [x, y, size, coorX, coorY]
void DCellPack(DCell cell, void *buffer, int bufSize, int *pos, MPI_Comm comm ) {
MPI_Pack(&cell->x,1,MPI_DOUBLE,buffer,bufSize,pos,comm);
MPI_Pack(&cell->y,1,MPI_DOUBLE,buffer,bufSize,pos,comm);
MPI_Pack(&cell->size,1,MPI_INT,buffer,bufSize,pos,comm);
MPI_Pack(cell->coorX,cell->size,MPI_DOUBLE,buffer,bufSize,pos,comm);
MPI_Pack(cell->coorY,cell->size,MPI_DOUBLE,buffer,bufSize,pos,comm);
//TODO: Record the size of 'pos' to figure out the typical size of the pack buffer
}
示例4: COM_Send
/* non-blocking send */
int COM_Send (void *pattern)
{
COMPATTERN *cp = pattern;
int *rankmap = cp->rankmap,
*send_position = cp->send_position,
(*send_sizes) [3] = cp->send_sizes,
*send_rank = cp->send_rank,
*recv_rank = cp->recv_rank,
(*recv_sizes) [3] = cp->recv_sizes,
send_count = cp->send_count,
recv_count = cp->recv_count,
tag = cp->tag,
nsend = cp->nsend,
i, j;
char **send_data = cp->send_data,
**recv_data = cp->recv_data;
MPI_Request *send_req = cp->send_req,
*recv_req = cp->recv_req;
MPI_Comm comm = cp->comm;
COMDATA *cd;
for (i = 0; i < send_count; i ++)
send_position [i] = 0;
/* pack ints */
for (i = 0, cd = cp->send; i < nsend; i ++, cd ++)
{
if (cd->ints)
{
j = rankmap [cd->rank];
MPI_Pack (cd->i, cd->ints, MPI_INT, send_data [j], send_sizes [j][2], &send_position [j], comm);
}
}
/* pack doubles */
for (i = 0, cd = cp->send; i < nsend; i ++, cd ++)
{
if (cd->doubles)
{
j = rankmap [cd->rank];
MPI_Pack (cd->d, cd->doubles, MPI_DOUBLE, send_data [j], send_sizes [j][2], &send_position [j], comm);
}
}
/* send data */
for (i = 0; i < send_count; i ++)
{
MPI_Isend (send_data [i], send_sizes [i][2], MPI_PACKED, send_rank [i], tag, comm, &send_req [i]);
}
/* receive data */
for (i = 0; i < recv_count; i ++)
{
MPI_Irecv (recv_data [i], recv_sizes [i][2], MPI_PACKED, recv_rank [i], tag, comm, &recv_req [i]);
}
return cp->send_size;
}
示例5: RequestPrimalSol
/* ------------------------------------------------------------------------- */
void RequestPrimalSol(char best_sol,
char *stop,
int probab,
int *var_x,
PrimalType *PrimalSol,
MPI_Comm communicator)
{
void *values = NULL;
int method = REQUEST_SOLUTION,
sizeOfBuffer = 0,
position = 0;
char *buffer;
sizeOfBuffer = ((sizeof(int)) + (sizeof(char)) +
(sizeof(int)));
buffer = malloc(sizeOfBuffer);
MPI_Pack(&method, 1, MPI_INT, buffer, sizeOfBuffer, &position, communicator);
MPI_Pack(&best_sol, 1, MPI_CHAR, buffer, sizeOfBuffer, &position, communicator);
MPI_Pack(&probab, 1, MPI_INT, buffer, sizeOfBuffer, &position, communicator);
MPI_Send(buffer, position, MPI_PACKED, 0, 1, communicator);
free(buffer);
MPI_Status status;
int positionRecv = 0;
int sizeOfMessage = 0;
MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, communicator, &status);
MPI_Get_count(&status, MPI_PACKED, &sizeOfMessage);
buffer = malloc(sizeOfMessage);
MPI_Recv(buffer, sizeOfMessage, MPI_PACKED, MPI_ANY_SOURCE, MPI_ANY_TAG, communicator, &status);
MPI_Unpack(buffer, sizeOfMessage, &positionRecv, stop, 1, MPI_CHAR, communicator);
if (!*stop)
{ MPI_Unpack(buffer, sizeOfMessage, &positionRecv, PrimalSol->agent, TotalAgents, MPI_CHAR, communicator);
MPI_Unpack(buffer, sizeOfMessage, &positionRecv, var_x, nb_col, MPI_INT, communicator);
PrimalSol->var_x = var_x;
MPI_Unpack(buffer, sizeOfMessage, &positionRecv, &PrimalSol->proc_time, 1, MPI_INT, communicator);
MPI_Unpack(buffer, sizeOfMessage, &positionRecv, &PrimalSol->value, 1, MPI_DOUBLE, communicator);
MPI_Unpack(buffer, sizeOfMessage, &positionRecv, &PrimalSol->agent_ID, 1, MPI_UNSIGNED, communicator);
}
free(buffer);
//printf("\n\n === Fim o empacotamento em agentrot RequestPrimal \n\n");
}
示例6: mpi_worker
/* mpi_worker()
* The main control for an MPI worker process.
*/
static void
mpi_worker(ESL_GETOPTS *go, struct cfg_s *cfg)
{
int xstatus = eslOK;
int status;
P7_HMM *hmm = NULL;
char *wbuf = NULL;
double *xv = NULL; /* result: array of N scores */
int *av = NULL; /* optional result: array of N alignment lengths */
int wn = 0;
char errbuf[eslERRBUFSIZE];
int pos;
/* Worker initializes */
if ((status = minimum_mpi_working_buffer(go, cfg->N, &wn)) != eslOK) xstatus = status;
ESL_ALLOC(wbuf, wn * sizeof(char));
ESL_ALLOC(xv, cfg->N * sizeof(double) + 2);
if (esl_opt_GetBoolean(go, "-a"))
ESL_ALLOC(av, cfg->N * sizeof(int));
/* Main worker loop */
while (p7_hmm_mpi_Recv(0, 0, MPI_COMM_WORLD, &wbuf, &wn, &(cfg->abc), &hmm) == eslOK)
{
if (esl_opt_GetBoolean(go, "--recal")) {
if (( status = recalibrate_model(go, cfg, errbuf, hmm)) != eslOK) goto CLEANERROR;
}
if ((status = process_workunit(go, cfg, errbuf, hmm, xv, av)) != eslOK) goto CLEANERROR;
pos = 0;
MPI_Pack(&status, 1, MPI_INT, wbuf, wn, &pos, MPI_COMM_WORLD);
MPI_Pack(xv, cfg->N, MPI_DOUBLE, wbuf, wn, &pos, MPI_COMM_WORLD);
if (esl_opt_GetBoolean(go, "-a"))
MPI_Pack(av, cfg->N, MPI_INT, wbuf, wn, &pos, MPI_COMM_WORLD);
MPI_Send(wbuf, pos, MPI_PACKED, 0, 0, MPI_COMM_WORLD);
p7_hmm_Destroy(hmm);
}
free(wbuf);
free(xv);
if (av != NULL) free(av);
return;
CLEANERROR:
pos = 0;
MPI_Pack(&status, 1, MPI_INT, wbuf, wn, &pos, MPI_COMM_WORLD);
MPI_Pack(errbuf, eslERRBUFSIZE, MPI_CHAR, wbuf, wn, &pos, MPI_COMM_WORLD);
MPI_Send(wbuf, pos, MPI_PACKED, 0, 0, MPI_COMM_WORLD);
if (wbuf != NULL) free(wbuf);
if (hmm != NULL) p7_hmm_Destroy(hmm);
if (xv != NULL) free(xv);
if (av != NULL) free(av);
return;
ERROR:
p7_Fail("Allocation error in mpi_worker");
}
示例7: main
/* -------------------------------------------------------------------------
O unico parametro a ser passado para esse agente e' o numero do processa-
dor em que esta executando o 'ns'.
------------------------------------------------------------------------- */
main(int argc,char *argv[])
{
MPI_Init(&argc, &argv);
int method = 0,
flagConnectMD = 1,
flagConnectMP = 1,
position = 0;
char portMD[MPI_MAX_PORT_NAME],
portMP[MPI_MAX_PORT_NAME],
bufferMD[100],
bufferMP[100];
MPI_Comm commServerMD;
MPI_Comm commServerMP;
flagConnectMD = MPI_Lookup_name("ServerMD", MPI_INFO_NULL, portMD);
flagConnectMP = MPI_Lookup_name("ServerMP", MPI_INFO_NULL, portMP);
method = DUMP_MEMORY;
int i = 0;
int message = 1224;
if (!flagConnectMD)
{
MPI_Comm_connect(portMD, MPI_INFO_NULL, 0, MPI_COMM_SELF, &commServerMD);
MPI_Pack(&method, 1, MPI_INT, bufferMD, 100, &position, commServerMD);
MPI_Send(bufferMD, position, MPI_PACKED, 0, 1, commServerMD);
MPI_Send(&message, 1, MPI_INT, 0, 1, commServerMD);
MPI_Comm_disconnect(&commServerMD);
}
else
printf("\n\n* Memoria de solucoes duais nao iniciada *\n\n");
position = 0;
if (!flagConnectMP)
{
MPI_Comm_connect(portMP, MPI_INFO_NULL, 0, MPI_COMM_SELF, &commServerMP);
MPI_Pack(&method, 1, MPI_INT, bufferMP, 100, &position, commServerMP);
MPI_Send(bufferMP, position, MPI_PACKED, 0, 1, commServerMP);
MPI_Send(&message, 1, MPI_INT, 0, 1, commServerMP);
MPI_Comm_disconnect(&commServerMP);
}
else
printf("\n\n* Memoria de solucoes primais nao iniciada *\n\n");
if ((flagConnectMD) && (flagConnectMP)){
printf("\n\n* Nenhum dos servidores de memoria do ATeam esta ativo *\n");fflush(stdout);
}else
printf("\n* A escrita do conteudo das memorias ativas foi realizada *\n");
MPI_Finalize();
}
示例8: main
int main(int argc, char** argv) {
int rank, numprocs;
int intA;
double doubleB;
unsigned long ulongC;
int packsize, position;
char packbuf[100];
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
do {
if(rank == 0) {
fprintf(stdout, "Please input an int, a double, and a ull:\n");
scanf_s("%d%lf%lu", &intA, &doubleB, &ulongC);
packsize = 0;
MPI_Pack(&intA, 1, MPI_INT, packbuf, 100, &packsize, MPI_COMM_WORLD);
printf("packsize = %d\t", packsize);
printf("size(int) = %d\n", sizeof(int));
MPI_Pack(&doubleB, 1, MPI_DOUBLE, packbuf, 100, &packsize, MPI_COMM_WORLD);
printf("packsize = %d\t", packsize);
printf("size(double) = %d\n", sizeof(double));
MPI_Pack(&ulongC, 1, MPI_UNSIGNED_LONG, packbuf, 100, &packsize, MPI_COMM_WORLD);
printf("packsize = %d\t", packsize);
printf("size(unsigned long) = %d\n", sizeof(unsigned long));
}
MPI_Bcast(&packsize, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Bcast(packbuf, packsize, MPI_PACKED, 0, MPI_COMM_WORLD);
if(rank != 0) {
position = 0;
MPI_Unpack(packbuf, packsize, &position, &intA, 1, MPI_INT, MPI_COMM_WORLD);
printf("postion= %d\t", position);
MPI_Unpack(packbuf, packsize, &position, &doubleB, 1, MPI_DOUBLE, MPI_COMM_WORLD);
printf("postion= %d\t", position);
MPI_Unpack(packbuf, packsize, &position, &ulongC, 1, MPI_UNSIGNED_LONG, MPI_COMM_WORLD);
printf("postion= %d\n", position);
printf("rank %d got int %d, double %lf, and ull %lu\n", rank, intA, doubleB, ulongC);
}
MPI_Barrier(MPI_COMM_WORLD);
} while (intA >= 0);
printf("myid = %d, %d, %lf\n", rank, intA, doubleB);
MPI_Finalize();
return 0;
}
示例9: sendFinishedJobNotification
void sendFinishedJobNotification (finishedJobNotification *fjn) {
char *buff = malloc(sizeof(finishedJobNotification));
int pos = 0;
MPI_Pack(&(fjn->category), 1, MPI_INT, buff, sizeof(finishedJobNotification), &pos, MPI_COMM_WORLD);
MPI_Pack(&(fjn->ranAtPU), 1, MPI_INT, buff, sizeof(finishedJobNotification), &pos, MPI_COMM_WORLD);
MPI_Pack(&(fjn->succeeded), 1, MPI_BYTE, buff, sizeof(finishedJobNotification), &pos, MPI_COMM_WORLD);
MPI_Pack(&(fjn->overheads), 1, MPI_DOUBLE, buff, sizeof(finishedJobNotification), &pos, MPI_COMM_WORLD);
MPI_Pack(&(fjn->executionTime), 1, MPI_DOUBLE, buff, sizeof(finishedJobNotification), &pos, MPI_COMM_WORLD);
sendMsg(buff, pos, MPI_PACKED, defaultSchedID, COMM_TAG_PUSTATUS, MPI_STATUS_IGNORE);
free(buff);
}
示例10: COMALL_Repeat
/* communicate integers and doubles accodring
* to the pattern computed by COMALL_Pattern */
int COMALL_Repeat (void *pattern)
{
COMALLPATTERN *pp = pattern;
COMDATA *cd;
int i;
for (i = 0; i < pp->ncpu; i ++) pp->send_position [i] = pp->recv_position [i] = 0;
/* pack ints */
for (i = 0, cd = pp->send; i < pp->nsend; i ++, cd ++)
{
if (cd->ints)
{
MPI_Pack (cd->i, cd->ints, MPI_INT, &pp->send_data [pp->send_disps [cd->rank]], pp->send_counts [cd->rank], &pp->send_position [cd->rank], pp->comm);
}
}
/* pack doubles */
for (i = 0, cd = pp->send; i < pp->nsend; i ++, cd ++)
{
if (cd->doubles)
{
MPI_Pack (cd->d, cd->doubles, MPI_DOUBLE, &pp->send_data [pp->send_disps [cd->rank]], pp->send_counts [cd->rank], &pp->send_position [cd->rank], pp->comm);
}
}
#if DEBUG
for (i = 0; i < pp->ncpu; i ++)
{
ASSERT_DEBUG (pp->send_position [i] <= pp->send_counts [i], "Incorrect packing");
}
#endif
/* all to all send and receive */
MPI_Alltoallv (pp->send_data, pp->send_counts, pp->send_disps, MPI_PACKED, pp->recv_data, pp->recv_counts, pp->recv_disps, MPI_PACKED, pp->comm);
if (pp->recv_size)
{
/* unpack data */
for (i = 0; i < pp->ncpu; i ++)
{
MPI_Unpack (&pp->recv_data [pp->recv_disps [i]], pp->recv_counts [i], &pp->recv_position [i], pp->recv [i].i, pp->recv [i].ints, MPI_INT, pp->comm);
MPI_Unpack (&pp->recv_data [pp->recv_disps [i]], pp->recv_counts [i], &pp->recv_position [i], pp->recv [i].d, pp->recv [i].doubles, MPI_DOUBLE, pp->comm);
}
}
return pp->send_size;
}
示例11: serializeSolution
void serializeSolution(char* buffer, int& position, vector<Move>& _solution) {
int data = _solution.size();
MPI_Pack(&data, 1, MPI_INT, buffer, BUFFER_SIZE, &position, MPI_COMM_WORLD);
for (vector<Move>::const_iterator it = _solution.begin(); it < _solution.end(); ++it) {
it->serialize(buffer, position);
}
}
示例12: p7_hmm_mpi_Send
/* Function: p7_hmm_mpi_Send()
* Synopsis: Send an HMM as an MPI work unit.
*
* Purpose: Sends an HMM <hmm> as a work unit to MPI process
* <dest> (where <dest> ranges from 0..<nproc-1>), tagged
* with MPI tag <tag>, for MPI communicator <comm>, as
* the sole workunit or result.
*
* Work units are prefixed by a status code indicating the
* number of HMMs sent. If <hmm> is <NULL>, this code is 0,
* and <_Recv()> interprets such a unit as an EOD
* (end-of-data) signal, a signal to cleanly shut down
* worker processes.
*
* In order to minimize alloc/free cycles in this routine,
* caller passes a pointer to a working buffer <*buf> of
* size <*nalloc> characters. If necessary (i.e. if <hmm> is
* too big to fit), <*buf> will be reallocated and <*nalloc>
* increased to the new size. As a special case, if <*buf>
* is <NULL> and <*nalloc> is 0, the buffer will be
* allocated appropriately, but the caller is still
* responsible for free'ing it.
*
* Returns: <eslOK> on success; <*buf> may have been reallocated and
* <*nalloc> may have been increased.
*
* Throws: <eslESYS> if an MPI call fails; <eslEMEM> if a malloc/realloc
* fails. In either case, <*buf> and <*nalloc> remain valid and useful
* memory (though the contents of <*buf> are undefined).
*
* Note: Compare to p7_hmmfile_WriteBinary(). The two operations (sending
* an HMM via MPI, or saving it as a binary file to disk) are
* similar.
*/
int
p7_hmm_mpi_Send(const P7_HMM *hmm, int dest, int tag, MPI_Comm comm, char **buf, int *nalloc)
{
int n = 0;
int code;
int sz, pos;
int status;
/* Figure out size. We always send at least a status code (0=EOD=nothing sent) */
if ( MPI_Pack_size(1, MPI_INT, comm, &sz) != MPI_SUCCESS) ESL_EXCEPTION(eslESYS, "mpi pack size failed"); n += sz;
if ((status = p7_hmm_mpi_PackSize(hmm, comm, &sz)) != eslOK) return status; n += sz;
/* Make sure the buffer is allocated appropriately */
if (*buf == NULL || n > *nalloc)
{
ESL_REALLOC(*buf, sizeof(char) * n);
*nalloc = n;
}
/* Pack the status code and HMM into the buffer */
/* The status code is the # of HMMs being sent as one MPI message; here 1 or 0 */
pos = 0;
code = (hmm ? 1 : 0);
if (MPI_Pack(&code, 1, MPI_INT, *buf, n, &pos, comm) != MPI_SUCCESS) ESL_EXCEPTION(eslESYS, "mpi pack failed");
if (hmm && (status = p7_hmm_mpi_Pack(hmm, *buf, n, &pos, comm)) != eslOK) return status;
/* Send the packed HMM to the destination. */
if (MPI_Send(*buf, n, MPI_PACKED, dest, tag, comm) != MPI_SUCCESS) ESL_EXCEPTION(eslESYS, "mpi send failed");
return eslOK;
ERROR:
return status;
}
示例13: PackUnpack
/* Extract the source array into the dest array using the DARRAY datatype.
"count" integers are returned in destArray */
int PackUnpack( MPI_Datatype darraytype, const int srcArray[], int destArray[],
int count )
{
int packsize, position;
int *packArray;
MPI_Type_commit( &darraytype );
MPI_Pack_size( 1, darraytype, MPI_COMM_SELF, &packsize );
packArray = (int *)malloc( packsize );
if (!packArray) {
fprintf( stderr, "Unable to allocate pack array of size %d\n",
packsize );
MPI_Abort( MPI_COMM_WORLD, 1 );
exit(1);
}
position = 0;
MPI_Pack( (int*)srcArray, 1, darraytype, packArray, packsize, &position,
MPI_COMM_SELF );
packsize = position;
position = 0;
MPI_Unpack( packArray, packsize, &position, destArray, count, MPI_INT,
MPI_COMM_SELF );
free( packArray );
return 0;
}
示例14: main
int main(int argc, char** argv) {
char* mpi_inbuf;
char* mpi_outbuf;
char* farc_inbuf;
char* farc_outbuf;
MPI_Init(&argc, &argv);
test_start("pack(1, hvector[[int], count=2, blklen=2, stride=-5*sizeof(int)])");
init_buffers(20*sizeof(int), &mpi_inbuf, &farc_inbuf, &mpi_outbuf, &farc_outbuf);
farc::DDT_Init();
farc::Datatype* t1 = new farc::PrimitiveDatatype(farc::PrimitiveDatatype::INT);
farc::Datatype* t2 = new farc::HVectorDatatype(2, 2, -5*sizeof(int), t1);
farc::DDT_Commit(t2);
farc::DDT_Pack(farc_inbuf+10*sizeof(int), farc_outbuf, t2, 1);
MPI_Datatype newtype;
MPI_Type_hvector(2, 2, -5*sizeof(int), MPI_INT, &newtype);
MPI_Type_commit(&newtype);
int position = 0;
MPI_Pack(mpi_inbuf+10*sizeof(int), 1, newtype, mpi_outbuf, 20*sizeof(int), &position, MPI_COMM_WORLD);
int res = compare_ddt_info(newtype, t2);
res = compare_buffers(20*sizeof(int), &mpi_inbuf, &farc_inbuf, &mpi_outbuf, &farc_outbuf);
// inspect_buffers(20*sizeof(int), &mpi_inbuf, &farc_inbuf, &mpi_outbuf, &farc_outbuf);
free_buffers(&mpi_inbuf, &farc_inbuf, &mpi_outbuf, &farc_outbuf);
test_result(res);
MPI_Finalize();
return 0;
}
示例15: FC_FUNC
FC_FUNC( mpi_pack , MPI_PACK )
( void *inbuf, int *incount, int *datatype,
void *outbuf, int *outsize, int *position, int *comm, int *ierror)
{
*ierror=MPI_Pack(inbuf, *incount,* datatype,
outbuf, *outsize, position, *comm);
}