int MPIU_write_external32_conversion_fn (const void *userbuf, MPI_Datatype datatype, int count, void *filebuf) { int position_i = 0; MPI_Aint position = 0; MPI_Aint bytes = 0; int mpi_errno = MPI_SUCCESS; int is_contig = 0; ADIOI_Datatype_iscontig(datatype, &is_contig); mpi_errno = MPI_Pack_external_size("external32", count, datatype, &bytes); if (mpi_errno != MPI_SUCCESS) goto fn_exit; if (is_contig) { mpi_errno = MPI_Pack_external("external32", userbuf, count, datatype, filebuf, bytes, &position); if (mpi_errno != MPI_SUCCESS) goto fn_exit; } else { void *tmp_buf = NULL; tmp_buf = ADIOI_Malloc(bytes); if (!tmp_buf) { mpi_errno = MPI_ERR_NO_MEM; goto fn_exit; } mpi_errno = MPI_Pack_external("external32", userbuf, count, datatype, tmp_buf, bytes, &position); if (mpi_errno != MPI_SUCCESS) { ADIOI_Free(tmp_buf); goto fn_exit; } mpi_errno = MPI_Unpack(tmp_buf, bytes, &position_i, filebuf, count, datatype, MPI_COMM_WORLD); if (mpi_errno != MPI_SUCCESS) { ADIOI_Free(tmp_buf); goto fn_exit; } ADIOI_Free(tmp_buf); } fn_exit: return mpi_errno; }
int tormpi_Issend(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, tormpi_Request *request){ MPI_Aint position=0,size; int sendres,esize; void *pbuf, *atn_buf; unsigned int linkId,chId,offset=0,sz,err; /* Use the lut only for non optimised nearest-neighbors-only communications */ if( tormpi_neigh_comm_only==0) { dest=tormpi_lut[dest]; } /* rank of dest is non-neg when dest is not reachabe via atn */ if (dest >= 0){ (*request).flag=0; sendres=MPI_Issend(buf, count, datatype, dest, tag, comm, &((*request).mpir)); return(sendres); }else { (*request).flag=2; chId=tormpi_vc[-dest]; linkId=-dest-1; MPI_Pack_external_size("external32",count,datatype,&size); sz=(unsigned int)ceil(size/TORMPI_MINPACKF); esize=sz*TORMPI_MINPACK; if(posix_memalign(&atn_buf,(size_t)TORMPI_BUFALIGN,(size_t)esize) !=0) return(-700); MPI_Pack_external("external32",buf,count,datatype,atn_buf,size,&position); pbuf=atn_buf; if(sz <= tormpi_maxbuff){ #ifdef WITHPROXYBIP atnCredit(linkId,chId,0,1,0); atnPoll(linkId,chId,0,1,&tormpi_bip,0); #endif ATNSEND(linkId,chId,pbuf,0,sz); } else { fprintf(stderr,"tormpi_isend ERROR: packet too large (%d>%d). Please use _isendrecv.\n",sz,tormpi_maxbuff); exit(-751); } free(atn_buf); return(MPI_SUCCESS); } }
int main(int argc, char *argv[]) { /* Variable declarations */ MPI_Datatype oneslice, twoslice, threeslice; int errs = 0; MPI_Aint sizeofint, bufsize, position; void *buffer; int i, j, k; /* Initialize a to some known values. */ for (i = 0; i < 100; i++) { for (j = 0; j < 100; j++) { for (k = 0; k < 100; k++) { a[i][j][k] = i * 1000000 + j * 1000 + k; } } } /* Initialize MPI */ MPI_Init(&argc, &argv); MPI_Type_extent(MPI_INT, &sizeofint); parse_args(argc, argv); /* Create data types. */ /* NOTE: This differs from the way that it's done on the sheet. */ /* On the sheet, the slice is a[0, 2, 4, ..., 16][2-10][1-9]. */ /* Below, the slice is a[0-8][2-10][1, 3, 5, ..., 17]. */ MPI_Type_vector(9, 1, 2, MPI_INT, &oneslice); MPI_Type_hvector(9, 1, 100 * sizeofint, oneslice, &twoslice); MPI_Type_hvector(9, 1, 100 * 100 * sizeofint, twoslice, &threeslice); MPI_Type_commit(&threeslice); /* Pack it into a buffer. */ position = 0; /* MPI_Pack_size(1, threeslice, MPI_COMM_WORLD, &bufsize); */ MPI_Pack_external_size((char *) "external32", 1, threeslice, &bufsize); if (bufsize != 2916) { fprintf(stderr, " Error on pack size! Got %d; expecting %d\n", (int) bufsize, 2916); } buffer = (void *) malloc((unsigned) bufsize); /* -1 to indices on sheet to compensate for Fortran --> C */ MPI_Pack_external((char *) "external32", &(a[0][2][1]), 1, threeslice, buffer, bufsize, &position); /* Unpack the buffer into e. */ position = 0; MPI_Unpack_external((char *) "external32", buffer, bufsize, &position, e, 9 * 9 * 9, MPI_INT); /* Display errors, if any. */ for (i = 0; i < 9; i++) { for (j = 0; j < 9; j++) { for (k = 0; k < 9; k++) { /* The truncation in integer division makes this safe. */ if (e[i][j][k] != a[i][j + 2][k * 2 + 1]) { errs++; if (verbose) { printf("Error in location %d x %d x %d: %d, should be %d.\n", i, j, k, e[i][j][k], a[i][j + 2][k * 2 + 1]); } } } } } /* Release memory. */ free(buffer); if (errs) { fprintf(stderr, "Found %d errors\n", errs); } else { printf(" No Errors\n"); } MPI_Type_free(&oneslice); MPI_Type_free(&twoslice); MPI_Type_free(&threeslice); MPI_Finalize(); return 0; }