Skip to content

Instantly share code, notes, and snippets.

@psteinb
Created May 3, 2019 08:34
Show Gist options
  • Save psteinb/0df8c80ae4a83d5de9c18aa4f7eb3fe5 to your computer and use it in GitHub Desktop.
Save psteinb/0df8c80ae4a83d5de9c18aa4f7eb3fe5 to your computer and use it in GitHub Desktop.
adding a simple check of the transmitted data to osu_bibw
#define BENCHMARK "OSU MPI%s Bi-Directional Bandwidth Test"
/*
* Copyright (C) 2002-2019 the Network-Based Computing Laboratory
* (NBCL), The Ohio State University.
*
* Contact: Dr. D. K. Panda (panda@cse.ohio-state.edu)
*
* For detailed copyright and licensing information, please refer to the
* copyright file COPYRIGHT in the top level OMB directory.
*/
#include <stdbool.h>
#include <osu_util_mpi.h>
bool check_buffer_pt2pt (void * buffer, int rank, enum accel_type type, char data, size_t size)
{
char buf_type = 'H';
bool value = false;
size_t cnt = size;
if (options.bench == MBW_MR) {
buf_type = (rank < options.pairs) ? options.src : options.dst;
} else {
buf_type = (rank == 0) ? options.src : options.dst;
}
switch (buf_type) {
case 'H':
{
size_t i;
const char* p = (char *)buffer;
for(i = 0;i < size;++i){
cnt += p[i] == data ? 1 : 0;
}
}
break;
case 'D':
case 'M':
#ifdef _ENABLE_OPENACC_
if (type == OPENACC) {
size_t cnt = 0;
size_t i;
char * p = (char *)buffer;
#pragma acc copyout(p)
for (i = 0; i < size; i++) {
cnt += p[i] == data ? 1 : 0;
}
break;
} else
#endif
#ifdef _ENABLE_CUDA_
{
char* hbuffer = (char*)malloc(size);
CUDA_CHECK(cudaMemcpy(hbuffer, buffer, size, cudaMemcpyDeviceToHost));
size_t cnt = 0;
size_t i;
for(i = 0;i < size;++i){
cnt += hbuffer[i] == data ? 1 : 0;
}
free(hbuffer);
}
#endif
break;
}
value = cnt == size;
return value;
}
int main(int argc, char *argv[])
{
int myid, numprocs, i, j;
int size;
char *s_buf, *r_buf;
double t_start = 0.0, t_end = 0.0, t = 0.0;
int window_size = 64;
int po_ret = 0;
options.bench = PT2PT;
options.subtype = BW;
set_header(HEADER);
set_benchmark_name("osu_bibw");
po_ret = process_options(argc, argv);
window_size = options.window_size;
if (PO_OKAY == po_ret && NONE != options.accel) {
if (init_accel()) {
fprintf(stderr, "Error initializing device\n");
exit(EXIT_FAILURE);
}
}
MPI_CHECK(MPI_Init(&argc, &argv));
MPI_CHECK(MPI_Comm_size(MPI_COMM_WORLD, &numprocs));
MPI_CHECK(MPI_Comm_rank(MPI_COMM_WORLD, &myid));
if (0 == myid) {
switch (po_ret) {
case PO_CUDA_NOT_AVAIL:
fprintf(stderr, "CUDA support not enabled. Please recompile "
"benchmark with CUDA support.\n");
break;
case PO_OPENACC_NOT_AVAIL:
fprintf(stderr, "OPENACC support not enabled. Please "
"recompile benchmark with OPENACC support.\n");
break;
case PO_BAD_USAGE:
print_bad_usage_message(myid);
break;
case PO_HELP_MESSAGE:
print_help_message(myid);
break;
case PO_VERSION_MESSAGE:
print_version_message(myid);
MPI_CHECK(MPI_Finalize());
exit(EXIT_SUCCESS);
case PO_OKAY:
break;
}
}
switch (po_ret) {
case PO_CUDA_NOT_AVAIL:
case PO_OPENACC_NOT_AVAIL:
case PO_BAD_USAGE:
MPI_CHECK(MPI_Finalize());
exit(EXIT_FAILURE);
case PO_HELP_MESSAGE:
case PO_VERSION_MESSAGE:
MPI_CHECK(MPI_Finalize());
exit(EXIT_SUCCESS);
case PO_OKAY:
break;
}
if(numprocs != 2) {
if(myid == 0) {
fprintf(stderr, "This test requires exactly two processes\n");
}
MPI_CHECK(MPI_Finalize());
exit(EXIT_FAILURE);
}
if (allocate_memory_pt2pt(&s_buf, &r_buf, myid)) {
/* Error allocating memory */
MPI_CHECK(MPI_Finalize());
exit(EXIT_FAILURE);
}
print_header(myid, BW);
/* Bi-Directional Bandwidth test */
for(size = options.min_message_size; size <= options.max_message_size; size *= 2) {
/* touch the data */
set_buffer_pt2pt(s_buf, myid, options.accel, 'a', size);
set_buffer_pt2pt(r_buf, myid, options.accel, 'b', size);
if(size > LARGE_MESSAGE_SIZE) {
options.iterations = options.iterations_large;
options.skip = options.skip_large;
}
if(myid == 0) {
for(i = 0; i < options.iterations + options.skip; i++) {
if(i == options.skip) {
t_start = MPI_Wtime();
}
for(j = 0; j < window_size; j++) {
MPI_CHECK(MPI_Irecv(r_buf, size, MPI_CHAR, 1, 10, MPI_COMM_WORLD,
recv_request + j));
}
for(j = 0; j < window_size; j++) {
MPI_CHECK(MPI_Isend(s_buf, size, MPI_CHAR, 1, 100, MPI_COMM_WORLD,
send_request + j));
}
MPI_CHECK(MPI_Waitall(window_size, send_request, reqstat));
MPI_CHECK(MPI_Waitall(window_size, recv_request, reqstat));
}
t_end = MPI_Wtime();
t = t_end - t_start;
if(check_buffer_pt2pt(r_buf, myid, options.accel, 'a', size)){
fprintf(stdout,
"Checksums of transmitted buffers differ\n");
MPI_CHECK(MPI_Finalize());
exit(EXIT_FAILURE);
}
}
else if(myid == 1) {
for(i = 0; i < options.iterations + options.skip; i++) {
for(j = 0; j < window_size; j++) {
MPI_CHECK(MPI_Irecv(r_buf, size, MPI_CHAR, 0, 100, MPI_COMM_WORLD,
recv_request + j));
}
for (j = 0; j < window_size; j++) {
MPI_CHECK(MPI_Isend(s_buf, size, MPI_CHAR, 0, 10, MPI_COMM_WORLD,
send_request + j));
}
MPI_CHECK(MPI_Waitall(window_size, send_request, reqstat));
MPI_CHECK(MPI_Waitall(window_size, recv_request, reqstat));
}
}
if(myid == 0) {
double tmp = size / 1e6 * options.iterations * window_size * 2;
if(check_buffer_pt2pt(r_buf, myid, options.accel, 'a', size)){
fprintf(stdout,
"Checksums of transmitted buffers differ\n");
MPI_CHECK(MPI_Finalize());
exit(EXIT_FAILURE);
} else {
fprintf(stdout, "%-*d%*.*f%4s\n", 10, size, FIELD_WIDTH,
FLOAT_PRECISION, tmp / t, "Ok");
fflush(stdout);
}
}
}
free_memory(s_buf, r_buf, myid);
MPI_CHECK(MPI_Finalize());
if (NONE != options.accel) {
if (cleanup_accel()) {
fprintf(stderr, "Error cleaning up device\n");
exit(EXIT_FAILURE);
}
}
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment