static int encode_plist(hid_t plist_id, int little_endian, const char *filename_le, const char *filename_be) { int fd = 0; /* file descriptor */ herr_t ret = 0; void *temp_buf = NULL; size_t temp_size = 0; ssize_t write_size; /* first call to encode returns only the size of the buffer needed */ if((ret = H5Pencode(plist_id, NULL, &temp_size)) < 0) assert(ret > 0); temp_buf = (void *)HDmalloc(temp_size); assert(temp_buf); if((ret = H5Pencode(plist_id, temp_buf, &temp_size)) < 0) assert(ret > 0); if(little_endian) fd = HDopen(filename_le, O_RDWR | O_CREAT | O_TRUNC, 0666); else fd = HDopen(filename_be, O_RDWR | O_CREAT | O_TRUNC, 0666); assert(fd > 0); write_size = HDwrite(fd, temp_buf, temp_size); assert(write_size == (ssize_t)temp_size); HDclose(fd); HDfree(temp_buf); return 1; }
static int test_encode_decode(hid_t orig_pl, int mpi_rank, int recv_proc) { MPI_Request req[2]; MPI_Status status; hid_t pl; /* Decoded property list */ size_t buf_size = 0; void *sbuf = NULL; herr_t ret; /* Generic return value */ if(mpi_rank == 0) { int send_size = 0; /* first call to encode returns only the size of the buffer needed */ ret = H5Pencode(orig_pl, NULL, &buf_size); VRFY((ret >= 0), "H5Pencode succeeded"); sbuf = (uint8_t *)HDmalloc(buf_size); ret = H5Pencode(orig_pl, sbuf, &buf_size); VRFY((ret >= 0), "H5Pencode succeeded"); /* this is a temp fix to send this size_t */ send_size = (int)buf_size; MPI_Isend(&send_size, 1, MPI_INT, recv_proc, 123, MPI_COMM_WORLD, &req[0]); MPI_Isend(sbuf, send_size, MPI_BYTE, recv_proc, 124, MPI_COMM_WORLD, &req[1]); } /* end if */ if(mpi_rank == recv_proc) { int recv_size; void *rbuf; MPI_Recv(&recv_size, 1, MPI_INT, 0, 123, MPI_COMM_WORLD, &status); buf_size = recv_size; rbuf = (uint8_t *)HDmalloc(buf_size); MPI_Recv(rbuf, recv_size, MPI_BYTE, 0, 124, MPI_COMM_WORLD, &status); pl = H5Pdecode(rbuf); VRFY((pl >= 0), "H5Pdecode succeeded"); VRFY(H5Pequal(orig_pl, pl), "Property List Equal Succeeded"); ret = H5Pclose(pl); VRFY((ret >= 0), "H5Pclose succeeded"); if(NULL != rbuf) HDfree(rbuf); } /* end if */ if(0 == mpi_rank) MPI_Waitall(2, req, MPI_STATUSES_IGNORE); if(NULL != sbuf) HDfree(sbuf); MPI_Barrier(MPI_COMM_WORLD); return(0); }
static int encode_plist(hid_t plist_id, int little_endian, int word_length, const char *filename_prefix) { int fd = 0; /* file descriptor */ herr_t ret = 0; void *temp_buf = NULL; size_t temp_size = 0; ssize_t write_size; char filename[1024]; /* Generate filename */ if((ret = HDsnprintf(filename, sizeof(filename), "%s%d%s", filename_prefix, word_length, little_endian ? "le" : "be")) < 0) HDassert(ret > 0); /* first call to encode returns only the size of the buffer needed */ if((ret = H5Pencode(plist_id, NULL, &temp_size)) < 0) HDassert(ret > 0); temp_buf = (void *)HDmalloc(temp_size); HDassert(temp_buf); if((ret = H5Pencode(plist_id, temp_buf, &temp_size)) < 0) HDassert(ret > 0); fd = HDopen(filename, O_RDWR | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_RW); HDassert(fd > 0); write_size = HDwrite(fd, temp_buf, temp_size); HDassert(write_size == (ssize_t)temp_size); HDclose(fd); HDfree(temp_buf); return 1; }