From 9b6c9e39fab1bea8e9ee2031a583826914acc655 Mon Sep 17 00:00:00 2001 From: "Peter W. Draper" <p.w.draper@durham.ac.uk> Date: Wed, 11 Mar 2020 13:10:46 +0000 Subject: [PATCH] Use the rank to fill the data, not some random pattern --- swiftmpiproxies.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/swiftmpiproxies.c b/swiftmpiproxies.c index 5dcecdf..cda7f73 100644 --- a/swiftmpiproxies.c +++ b/swiftmpiproxies.c @@ -60,13 +60,11 @@ int nr_recv_pcells = 0; /** * @brief fill a data area with a pattern that can be checked for changes. * - * @param offset use offset bit pattern 01010101 otherwise 10101010. + * @param fill value used in fill, note data type. * @param size size of data in bytes. * @param data the data to fill. */ -static void datacheck_fill(int offset, size_t size, void *data) { - unsigned char fill = 170; - if (offset) fill = fill >> 1; +static void datacheck_fill(unsigned char fill, size_t size, void *data) { unsigned char *p = (unsigned char *)data; for (size_t i = 0; i < size; i++) { p[i] = fill; @@ -74,23 +72,21 @@ static void datacheck_fill(int offset, size_t size, void *data) { } /** - * @brief test a filled data area for our pattern. + * @brief test a filled data area for the given value. Returns 0 if not found + * in all elements of data. * - * @param offset check for offset bit pattern 01010101 otherwise 10101010. + * @param fill value used in fill, note data type. * @param size size of data in bytes. * @param data the data to fill. * * @result 1 on success, 0 otherwise. */ -static int datacheck_test(int offset, size_t size, void *data) { - unsigned char fill = 170; - if (offset) fill = fill >> 1; - +static int datacheck_test(unsigned char fill, size_t size, void *data) { unsigned char *p = (unsigned char *)data; for (size_t i = 0; i < size; i++) { if (p[i] != fill) { if (verbose) { - message("%d: %d != %d", offset, p[i], fill); + message("%d != %d", p[i], fill); fflush(stdout); } return 0; @@ -271,10 +267,9 @@ int main(int argc, char *argv[]) { &req_send_counts[k]); if (res != MPI_SUCCESS) error("Counts MPI_Isend failed."); - /* Start Isend of pcells, filling the data with a pattern for checking - * on arrival. */ + /* Start Isend of pcells, fill with our rank value. */ log->data = calloc(log->size, 1); - datacheck_fill(0, log->size, log->data); + datacheck_fill(myrank, log->size, log->data); res = MPI_Isend(log->data, log->size, MPI_BYTE, log->otherrank, basetag + proxy_tag_cells, MPI_COMM_WORLD, @@ -309,8 +304,8 @@ int main(int argc, char *argv[]) { pcells_in[pid] = calloc(pcells_size[pid], 1); - /* Fill data with a pattern for checking when overwritten. */ - datacheck_fill(1, pcells_size[pid], pcells_in[pid]); + /* Fill data with our rank. */ + datacheck_fill(myrank, pcells_size[pid], pcells_in[pid]); res = MPI_Irecv(pcells_in[pid], pcells_size[pid], MPI_BYTE, log->otherrank, basetag + proxy_tag_cells, MPI_COMM_WORLD, @@ -335,8 +330,10 @@ int main(int argc, char *argv[]) { if (res != MPI_SUCCESS || pid == MPI_UNDEFINED) error("MPI_Waitany failed."); - /* Check the data received is correct. */ - if (!datacheck_test(0, pcells_size[pid], pcells_in[pid])) { + /* Check the data received is correct. Should be filled with + * rank of sender. */ + if (!datacheck_test(status.MPI_SOURCE, pcells_size[pid], + pcells_in[pid])) { message("Received data is not correct"); /* Report the tag and source of the request. */ @@ -347,7 +344,9 @@ int main(int argc, char *argv[]) { status.MPI_ERROR); datacheck_fulltest(pcells_size[pid], pcells_in[pid]); - if (datacheck_test(1, pcells_size[pid], pcells_in[pid])) { + fflush(stdout); + + if (datacheck_test(myrank, pcells_size[pid], pcells_in[pid])) { error("Received data is not modified on receive"); } else { error("Received data is corrupt"); @@ -368,7 +367,7 @@ int main(int argc, char *argv[]) { /* Check data is unmodified while being offloaded. */ for (int k = 0; k < nr_send_pcells; k++) { struct mpiuse_log_entry *log = send_pcells[k]; - if (!datacheck_test(0, log->size, log->data)) { + if (!datacheck_test(myrank, log->size, log->data)) { datacheck_fulltest(log->size, log->data); error("Sent data has been corrupted"); } else { -- GitLab