Skip to content
Snippets Groups Projects
Commit 56bbc3c0 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Formatting

parent 5222090f
No related branches found
No related tags found
No related merge requests found
...@@ -4,18 +4,18 @@ ...@@ -4,18 +4,18 @@
extern int myrank; extern int myrank;
/* Exit in error macro. */ /* Exit in error macro. */
#define error(s, ...) \ #define error(s, ...) \
({ \ ({ \
fflush(stdout); \ fflush(stdout); \
fprintf(stderr, "[%03i] %s %s:%s():%i: " s "\n", myrank, \ fprintf(stderr, "[%03i] %s %s:%s():%i: " s "\n", myrank, \
clocks_get_timesincestart(), \ clocks_get_timesincestart(), __FILE__, __FUNCTION__, __LINE__, \
__FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ ##__VA_ARGS__); \
MPI_Abort(MPI_COMM_WORLD, -1); \ MPI_Abort(MPI_COMM_WORLD, -1); \
}) })
/* Print a message */ /* Print a message */
#define message(s, ...) \ #define message(s, ...) \
({ \ ({ \
printf("[%04i] %s %s: " s "\n", myrank, \ printf("[%04i] %s %s: " s "\n", myrank, clocks_get_timesincestart(), \
clocks_get_timesincestart(),__FUNCTION__, ##__VA_ARGS__); \ __FUNCTION__, ##__VA_ARGS__); \
}) })
#include <stdio.h> #include <stdio.h>
/* Injection of MPI_Isends and MPI_Irecvs into the queues. */ /* Injection of MPI_Isends and MPI_Irecvs into the queues. */
void inject_one(void) { void inject_one(void) {}
}
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
* exchanges of various data sizes and continuously checks the requests for * exchanges of various data sizes and continuously checks the requests for
* completion. Also need timers to record the time taken by all this... * completion. Also need timers to record the time taken by all this...
*/ */
#include <stdio.h>
#include <mpi.h> #include <mpi.h>
#include <pthread.h> #include <pthread.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "atomic.h" #include "atomic.h"
...@@ -32,7 +32,7 @@ static const int task_type_send = 22; ...@@ -32,7 +32,7 @@ static const int task_type_send = 22;
static const int task_type_recv = 23; static const int task_type_recv = 23;
/* Global communicators for each of the subtypes. */ /* Global communicators for each of the subtypes. */
static const int task_subtype_count = 30; // Just some upper limit on subtype. static const int task_subtype_count = 30; // Just some upper limit on subtype.
static MPI_Comm subtypeMPI_comms[30]; static MPI_Comm subtypeMPI_comms[30];
/* The local queues. */ /* The local queues. */
...@@ -62,8 +62,7 @@ static double log_clocks_cpufreq = 2194844448.0; ...@@ -62,8 +62,7 @@ static double log_clocks_cpufreq = 2194844448.0;
*/ */
static void *inject_thread(void *arg) { static void *inject_thread(void *arg) {
if (verbose) if (verbose) message("%d: injection thread starts", *((int *)arg));
message("%d: injection thread starts", *((int *)arg));
ticks starttics = getticks(); ticks starttics = getticks();
/* Ticks of our last attempt and ticks the first loop takes (usetics == 1). */ /* Ticks of our last attempt and ticks the first loop takes (usetics == 1). */
...@@ -92,11 +91,11 @@ static void *inject_thread(void *arg) { ...@@ -92,11 +91,11 @@ static void *inject_thread(void *arg) {
* nanoseconds. */ * nanoseconds. */
double ns = (double)(dt - looptics) / log_clocks_cpufreq * 1.0e9; double ns = (double)(dt - looptics) / log_clocks_cpufreq * 1.0e9;
if (ns < 1.0e9) { if (ns < 1.0e9) {
sleep.tv_nsec = (long) ns; sleep.tv_nsec = (long)ns;
} else { } else {
/* Wait more than one second. Must be an error, but complain and /* Wait more than one second. Must be an error, but complain and
* continue. */ * continue. */
sleep.tv_nsec = (long) 1.0e9; sleep.tv_nsec = (long)1.0e9;
message("wait greater than one second"); message("wait greater than one second");
} }
nanosleep(&sleep, NULL); nanosleep(&sleep, NULL);
...@@ -106,8 +105,8 @@ static void *inject_thread(void *arg) { ...@@ -106,8 +105,8 @@ static void *inject_thread(void *arg) {
// Differences to SWIFT: MPI_BYTE might overflow, should use MPI_Type(?). // Differences to SWIFT: MPI_BYTE might overflow, should use MPI_Type(?).
int err = 0; int err = 0;
if (log->type == task_type_send) { if (log->type == task_type_send) {
err = MPI_Isend(log->data, log->size, MPI_BYTE, log->otherrank, err = MPI_Isend(log->data, log->size, MPI_BYTE, log->otherrank, log->tag,
log->tag, subtypeMPI_comms[log->subtype], &log->req); subtypeMPI_comms[log->subtype], &log->req);
/* Add a new send request. */ /* Add a new send request. */
int ind = atomic_inc(&nr_sends); int ind = atomic_inc(&nr_sends);
...@@ -115,8 +114,8 @@ static void *inject_thread(void *arg) { ...@@ -115,8 +114,8 @@ static void *inject_thread(void *arg) {
atomic_inc(&todo_send); atomic_inc(&todo_send);
} else { } else {
err = MPI_Irecv(log->data, log->size, MPI_BYTE, log->otherrank, err = MPI_Irecv(log->data, log->size, MPI_BYTE, log->otherrank, log->tag,
log->tag, subtypeMPI_comms[log->subtype], &log->req); subtypeMPI_comms[log->subtype], &log->req);
/* Add a new recv request. */ /* Add a new recv request. */
int ind = atomic_inc(&nr_recvs); int ind = atomic_inc(&nr_recvs);
...@@ -166,7 +165,7 @@ static void *inject_thread(void *arg) { ...@@ -166,7 +165,7 @@ static void *inject_thread(void *arg) {
*/ */
static void queue_runner(struct mpiuse_log_entry **logs, int volatile *nr_logs, static void queue_runner(struct mpiuse_log_entry **logs, int volatile *nr_logs,
int volatile *todos, double *sum, int *ncalls, int volatile *todos, double *sum, int *ncalls,
ticks *mint, ticks *maxt ) { ticks *mint, ticks *maxt) {
/* MPI_Test statistics. */ /* MPI_Test statistics. */
int lncalls = 0; int lncalls = 0;
...@@ -217,8 +216,7 @@ static void queue_runner(struct mpiuse_log_entry **logs, int volatile *nr_logs, ...@@ -217,8 +216,7 @@ static void queue_runner(struct mpiuse_log_entry **logs, int volatile *nr_logs,
*/ */
static void *send_thread(void *arg) { static void *send_thread(void *arg) {
if (verbose) if (verbose) message("%d: send thread starts (%d)", *((int *)arg), injecting);
message("%d: send thread starts (%d)", *((int *)arg), injecting);
ticks starttics = getticks(); ticks starttics = getticks();
int ncalls; int ncalls;
...@@ -227,9 +225,11 @@ static void *send_thread(void *arg) { ...@@ -227,9 +225,11 @@ static void *send_thread(void *arg) {
ticks maxt; ticks maxt;
queue_runner(sends_queue, &nr_sends, &todo_send, &sum, &ncalls, &mint, &maxt); queue_runner(sends_queue, &nr_sends, &todo_send, &sum, &ncalls, &mint, &maxt);
message("%d MPI_Test calls took: %.3f, mean time %.3f, min time %.3f, max time %.3f (%s)", message(
ncalls, clocks_from_ticks(sum), clocks_from_ticks(sum/ncalls), "%d MPI_Test calls took: %.3f, mean time %.3f, min time %.3f, max time "
clocks_from_ticks(mint), clocks_from_ticks(maxt), clocks_getunit()); "%.3f (%s)",
ncalls, clocks_from_ticks(sum), clocks_from_ticks(sum / ncalls),
clocks_from_ticks(mint), clocks_from_ticks(maxt), clocks_getunit());
message("took %.3f %s.", clocks_from_ticks(getticks() - starttics), message("took %.3f %s.", clocks_from_ticks(getticks() - starttics),
clocks_getunit()); clocks_getunit());
...@@ -242,8 +242,7 @@ static void *send_thread(void *arg) { ...@@ -242,8 +242,7 @@ static void *send_thread(void *arg) {
*/ */
static void *recv_thread(void *arg) { static void *recv_thread(void *arg) {
if (verbose) if (verbose) message("%d: recv thread starts", *((int *)arg));
message("%d: recv thread starts", *((int *)arg));
ticks starttics = getticks(); ticks starttics = getticks();
int ncalls; int ncalls;
...@@ -252,9 +251,11 @@ static void *recv_thread(void *arg) { ...@@ -252,9 +251,11 @@ static void *recv_thread(void *arg) {
ticks maxt; ticks maxt;
queue_runner(recvs_queue, &nr_recvs, &todo_recv, &sum, &ncalls, &mint, &maxt); queue_runner(recvs_queue, &nr_recvs, &todo_recv, &sum, &ncalls, &mint, &maxt);
message("%d MPI_Test calls took: %.3f, mean time %.3f, min time %.3f, max time %.3f (%s)", message(
ncalls, clocks_from_ticks(sum), clocks_from_ticks(sum/ncalls), "%d MPI_Test calls took: %.3f, mean time %.3f, min time %.3f, max time "
clocks_from_ticks(mint), clocks_from_ticks(maxt), clocks_getunit()); "%.3f (%s)",
ncalls, clocks_from_ticks(sum), clocks_from_ticks(sum / ncalls),
clocks_from_ticks(mint), clocks_from_ticks(maxt), clocks_getunit());
message("took %.3f %s.", clocks_from_ticks(getticks() - starttics), message("took %.3f %s.", clocks_from_ticks(getticks() - starttics),
clocks_getunit()); clocks_getunit());
...@@ -270,10 +271,8 @@ static int cmp_logs(const void *p1, const void *p2) { ...@@ -270,10 +271,8 @@ static int cmp_logs(const void *p1, const void *p2) {
struct mpiuse_log_entry *l2 = *(struct mpiuse_log_entry **)p2; struct mpiuse_log_entry *l2 = *(struct mpiuse_log_entry **)p2;
/* Large unsigned values, so take care. */ /* Large unsigned values, so take care. */
if (l1->tic > l2->tic) if (l1->tic > l2->tic) return 1;
return 1; if (l1->tic < l2->tic) return -1;
if (l1->tic < l2->tic)
return -1;
return 0; return 0;
} }
...@@ -286,14 +285,14 @@ static void pick_logs(void) { ...@@ -286,14 +285,14 @@ static void pick_logs(void) {
size_t nlogs = mpiuse_nr_logs(); size_t nlogs = mpiuse_nr_logs();
/* Duplicate of logs. */ /* Duplicate of logs. */
reqs_queue = (struct mpiuse_log_entry **) reqs_queue = (struct mpiuse_log_entry **)malloc(
malloc(sizeof(struct mpiuse_log_entry *) * nlogs); sizeof(struct mpiuse_log_entry *) * nlogs);
nr_reqs= 0; nr_reqs = 0;
sends_queue = (struct mpiuse_log_entry **) sends_queue = (struct mpiuse_log_entry **)malloc(
malloc(sizeof(struct mpiuse_log_entry *) * nlogs); sizeof(struct mpiuse_log_entry *) * nlogs);
nr_sends= 0; nr_sends = 0;
recvs_queue = (struct mpiuse_log_entry **) recvs_queue = (struct mpiuse_log_entry **)malloc(
malloc(sizeof(struct mpiuse_log_entry *) * nlogs); sizeof(struct mpiuse_log_entry *) * nlogs);
nr_recvs = 0; nr_recvs = 0;
for (int k = 0; k < nlogs; k++) { for (int k = 0; k < nlogs; k++) {
...@@ -318,7 +317,6 @@ static void pick_logs(void) { ...@@ -318,7 +317,6 @@ static void pick_logs(void) {
qsort(reqs_queue, nr_reqs, sizeof(struct mpiuse_log_entry *), cmp_logs); qsort(reqs_queue, nr_reqs, sizeof(struct mpiuse_log_entry *), cmp_logs);
} }
/** /**
* @brief main function. * @brief main function.
*/ */
...@@ -338,8 +336,7 @@ int main(int argc, char *argv[]) { ...@@ -338,8 +336,7 @@ int main(int argc, char *argv[]) {
int nr_nodes = 0; int nr_nodes = 0;
res = MPI_Comm_size(MPI_COMM_WORLD, &nr_nodes); res = MPI_Comm_size(MPI_COMM_WORLD, &nr_nodes);
if (res != MPI_SUCCESS) if (res != MPI_SUCCESS) error("MPI_Comm_size failed with error %i.", res);
error("MPI_Comm_size failed with error %i.", res);
/* This should match the expected size. */ /* This should match the expected size. */
if (nr_nodes != nranks) if (nr_nodes != nranks)
......
...@@ -141,8 +141,7 @@ void mpiuse_log_restore(const char *filename) { ...@@ -141,8 +141,7 @@ void mpiuse_log_restore(const char *filename) {
/* Open the input file. */ /* Open the input file. */
FILE *fd; FILE *fd;
if ((fd = fopen(filename, "r")) == NULL) { if ((fd = fopen(filename, "r")) == NULL) {
message("Failed to open the MPI use log file '%s'.", message("Failed to open the MPI use log file '%s'.", filename);
filename);
return; return;
} }
...@@ -155,9 +154,9 @@ void mpiuse_log_restore(const char *filename) { ...@@ -155,9 +154,9 @@ void mpiuse_log_restore(const char *filename) {
while (!feof(fd)) { while (!feof(fd)) {
if (fgets(line, 132, fd) != NULL) { if (fgets(line, 132, fd) != NULL) {
if (line[0] != '#') { if (line[0] != '#') {
sscanf(line, "%zd %zd %zd %d %d %d %s %d %s %d %d %d %zd %zd", sscanf(line, "%zd %zd %zd %d %d %d %s %d %s %d %d %d %zd %zd", &stic,
&stic, &etic, &dtic, &step, &rank, &otherrank, type, &itype, &etic, &dtic, &step, &rank, &otherrank, type, &itype, subtype,
subtype, &isubtype, &activation, &tag, &size, &sum); &isubtype, &activation, &tag, &size, &sum);
mpiuse_log_allocation(rank, step, stic, itype, isubtype, activation, mpiuse_log_allocation(rank, step, stic, itype, isubtype, activation,
size, otherrank, tag); size, otherrank, tag);
...@@ -172,18 +171,14 @@ void mpiuse_log_restore(const char *filename) { ...@@ -172,18 +171,14 @@ void mpiuse_log_restore(const char *filename) {
* *
* @result the number of log entries. * @result the number of log entries.
*/ */
int mpiuse_nr_logs(void) { int mpiuse_nr_logs(void) { return mpiuse_log_count; }
return mpiuse_log_count;
}
/** /**
* @brief return the number of ranks in log. * @brief return the number of ranks in log.
* *
* @result the number of ranks we've seen. * @result the number of ranks we've seen.
*/ */
int mpiuse_nr_ranks(void) { int mpiuse_nr_ranks(void) { return mpiuse_max_rank + 1; }
return mpiuse_max_rank + 1;
}
/** /**
* @brief get a log entry. * @brief get a log entry.
......
...@@ -58,7 +58,6 @@ struct mpiuse_log_entry { ...@@ -58,7 +58,6 @@ struct mpiuse_log_entry {
/* The request associated with the call. */ /* The request associated with the call. */
MPI_Request req; MPI_Request req;
}; };
/* API. */ /* API. */
......
#include <stdio.h> #include <stdio.h>
/** /**
* @brief read the output from a run of SWIFT with the MPI communication * @brief read the output from a run of SWIFT with the MPI communication
* logger enabled. * logger enabled.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment