Skip to content
Snippets Groups Projects
Commit 454a9cf8 authored by Thomas Jahns's avatar Thomas Jahns :cartwheel:
Browse files

Add test for further MPICH fail.

parent b6882523
No related branches found
No related tags found
No related merge requests found
test_mpi_pack_external_1.txt
\ No newline at end of file
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mpi.h>
static const char datarep[] = "external32";
enum { hdr_words = 2, dta_words = 12 };
#ifdef NO_DETECT_TRAILING_CORRUPTION
/* used to investigate with valgrind */
enum { trailing_size = 0 };
#else
enum { trailing_size = 8 };
#endif
int main(int argc, char **argv)
{
unsigned header[hdr_words];
const double dbl_canary = 0.356789;
size_t dta_words_extra = trailing_size > 0;
double *data;
size_t data_chars = sizeof data[0] * (dta_words + dta_words_extra);
data = malloc(data_chars);
if (!data) {
fprintf(stderr, "memory allocation for %zu bytes failed!\n", data_chars);
MPI_Abort(MPI_COMM_WORLD, 1);
}
MPI_Aint header_size, data_size;
MPI_Init(&argc, &argv);
header[0] = 2;
header[1] = 3;
MPI_Pack_external_size(datarep, hdr_words, MPI_UNSIGNED, &header_size);
MPI_Pack_external_size(datarep, dta_words, MPI_DOUBLE, &data_size);
MPI_Aint buf_size = header_size + data_size;
for (size_t i = 0; i < dta_words; ++i)
data[i] = (double)i * 1.25;
unsigned char *buf = malloc((size_t)buf_size + trailing_size);
if (!buf) {
fprintf(stderr, "memory allocation for %zu bytes failed!\n",
(size_t)buf_size + trailing_size);
MPI_Abort(MPI_COMM_WORLD, 1);
}
for (size_t i = 0; i < trailing_size; ++i)
buf[buf_size+i] = (unsigned char)i;
{
MPI_Aint pos_pack = 0;
MPI_Pack_external(datarep, header, hdr_words, MPI_UNSIGNED,
buf, buf_size, &pos_pack);
MPI_Pack_external(datarep, data, dta_words, MPI_DOUBLE,
buf, buf_size, &pos_pack);
}
for (size_t i = 0; i < dta_words_extra; ++i)
data[dta_words+i] = dbl_canary;
bool mismatch = false;
for (size_t i = 0; i < trailing_size; ++i)
mismatch |= buf[buf_size+i] != (unsigned char)i;
if (mismatch) {
fputs("data corruption after external32 packing detected\n", stderr);
MPI_Abort(MPI_COMM_WORLD, 1);
}
{
MPI_Aint pos_unpack = 0;
MPI_Unpack_external(datarep, buf, 104, &pos_unpack,
header, hdr_words, MPI_UNSIGNED);
MPI_Unpack_external(datarep, buf, 104, &pos_unpack,
data, dta_words, MPI_DOUBLE);
}
mismatch = (header[0] != 2 || header[1] != 3);
for (size_t i = 0; i < dta_words; ++i)
mismatch |= (data[i] != (double)i * 1.25);
for (size_t i = 0; i < dta_words_extra; ++i)
{
fprintf(stderr, "data[%zu]=%f\n", dta_words+i, data[dta_words+i]);
mismatch |= (data[dta_words+i] != dbl_canary);
}
if (mismatch) {
fputs("data corruption after external32 unpacking detected\n", stderr);
MPI_Abort(MPI_COMM_WORLD, 1);
}
free(buf);
MPI_Finalize();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment