Created
April 28, 2017 14:16
-
-
Save planetA/a4465558bfd0e16c52b686320676b0cd to your computer and use it in GitHub Desktop.
Minimal example for race condition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
#include <string.h> | |
#include <dmtcp.h> | |
#define CRASH(format, ...) ({ \ | |
fprintf(stderr, "DMTCPTESTEND:DMTCPCRASH:%s:%d " format, \ | |
__FILE__, __LINE__, ##__VA_ARGS__); \ | |
exit(EXIT_FAILURE); \ | |
}) | |
#define OK(format, ...) ({ \ | |
fprintf(stderr, "DMTCPTESTEND:DMTCPOK:%s:%d " format, \ | |
__FILE__, __LINE__, ##__VA_ARGS__); \ | |
exit(EXIT_SUCCESS); \ | |
}) | |
/* By default assume that we are the only process */ | |
int rank = 0; | |
void parse_args(int argc, char ** argv) | |
{ | |
char *rank_str = getenv(MPIRANK); | |
if (rank_str != NULL) { | |
rank = atoi(rank_str); | |
assert(rank >= 0); | |
} | |
} | |
int main(int argc, char **argv) | |
{ | |
if (dmtcp_is_enabled() == 0) { | |
CRASH("dmtcpcheckpoint: DMTCP not enabled.\n"); | |
} | |
parse_args(argc, argv); | |
printf("My rank is %d\n", rank); | |
for (int i = 0; i < 3; i++) { | |
printf("Going sleep\n"); | |
sleep(1); | |
printf("Woke up. Making checkpoint.\n"); | |
fflush(stdout); | |
if (!rank) | |
break; | |
if (dmtcp_checkpoint() == DMTCP_NOT_PRESENT) { | |
CRASH("DMTCP not present.\n"); | |
} | |
} | |
sleep(2); | |
sleep(2); | |
sleep(2); | |
sleep(2); | |
sleep(2); | |
OK("Normal exit\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@planetA: Here are the modifications I made to test this locally.
Your example works after these changes.