Commit 041f7129 authored by Ben Hazelwood's avatar Ben Hazelwood
Browse files

Move rank modification to separate class

parent 26a6923e
......@@ -2,8 +2,8 @@ CC=mpiicpc
CFLAGS += -fPIC -g -Wall -std=c++11
LDFLAGS += -shared
SRC = Rank.cpp Timing.cpp Wrapper.cpp
DEP = Rank.h Timing.h Wrapper.h Logging.h
SRC = Rank.cpp RankControl.cpp Timing.cpp Wrapper.cpp
DEP = Rank.h RankControl.h Timing.h Wrapper.h Logging.h
OBJECTS = $(SRC:.cpp=.o)
TARGET = libtmpi.so
......
......@@ -10,13 +10,13 @@
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <csignal>
#include <unistd.h>
#include "RankControl.h"
#include "Logging.h"
#include "Timing.h"
static int worldRank;
static int worldSize;
static int teamRank;
......@@ -26,15 +26,11 @@ static int numTeams;
static MPI_Comm TMPI_COMM_TEAM;
static MPI_Comm TMPI_COMM_DUP;
static bool shouldCorruptData;
int initialiseTMPI() {
/**
* The application should have no knowledge of the world_size or world_rank
*/
signal(SIGUSR1, pauseThisRankSignalHandler);
signal(SIGUSR2, corruptThisRankSignalHandler);
shouldCorruptData = false;
registerSignalHandler();
setEnvironment();
PMPI_Comm_size(MPI_COMM_WORLD, &worldSize);
......@@ -152,28 +148,6 @@ void setEnvironment() {
numTeams = env.empty() ? 2 : std::stoi(env);
}
void pauseThisRankSignalHandler( int signum ) {
const int startValue = 1e4;
const int multiplier = 2;
static int sleepLength = startValue;
logInfo( "Signal received: sleep for " << (double)sleepLength / 1e6 << "s");
usleep(sleepLength);
sleepLength *= multiplier;
}
void corruptThisRankSignalHandler( int signum ) {
logInfo("Signal received: corrupt this rank");
shouldCorruptData = true;
}
bool getShouldCorruptData() {
return shouldCorruptData;
}
void setShouldCorruptData(bool toggle) {
shouldCorruptData = toggle;
}
int mapRankToTeamNumber(int rank) {
return rank / getTeamSize();
}
......
......@@ -59,10 +59,6 @@ void outputEnvironment();
void outputTiming();
void pauseThisRankSignalHandler(int signum);
void corruptThisRankSignalHandler(int signum);
bool getShouldCorruptData();
void setShouldCorruptData(bool toggle);
......
/*
* RankOperations.cpp
*
* Created on: 2 Jul 2018
* Author: Ben Hazelwood
*/
#include <csignal>
#include <unistd.h>
#include "RankControl.h"
#include "Logging.h"
static bool shouldCorruptData;
void registerSignalHandler() {
#ifdef PAUSE_RANK
signal(SIGUSR1, pauseThisRankSignalHandler);
#endif
#ifdef CORRUPT_RANK
signal(SIGUSR2, corruptThisRankSignalHandler);
#endif
shouldCorruptData = false;
}
void pauseThisRankSignalHandler( int signum ) {
const int startValue = 1e4;
#if SLEEP_MULT != 0
const int multiplier = SLEEP_MULT;
#else
const int multiplier = ((double) rand() / (RAND_MAX)) + 1;
#endif
static int sleepLength = startValue;
logInfo( "Signal received: sleep for " << (double)sleepLength / 1e6 << "s");
usleep(sleepLength);
sleepLength *= multiplier;
}
void corruptThisRankSignalHandler( int signum ) {
logInfo("Signal received: corrupt this rank");
shouldCorruptData = true;
}
bool getShouldCorruptData() {
return shouldCorruptData;
}
void setShouldCorruptData(bool toggle) {
shouldCorruptData = toggle;
}
\ No newline at end of file
/*
* RankControl.h
*
* Created on: 2 Jul 2018
* Author: Ben Hazelwood
*/
#ifndef RANKCONTROL_H_
#define RANKCONTROL_H_
void registerSignalHandler();
void pauseThisRankSignalHandler(int signum);
void corruptThisRankSignalHandler(int signum);
bool getShouldCorruptData();
void setShouldCorruptData(bool toggle);
#endif
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment