Skip to content

Commit

Permalink
Update test_ckpt.c
Browse files Browse the repository at this point in the history
- Rename test_ckpt.C -> test_ckpt.cpp
- Update it so it can be easily used as C code as well.
- Allow it to take in an argument for checkpoint size in MB

These changes will help me with testing in #163.
  • Loading branch information
tonyhutter committed May 15, 2020
1 parent 7629135 commit afa51b9
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 77 deletions.
14 changes: 7 additions & 7 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LIST(APPEND example_files
test_api_multiple.c
test_interpose.c
test_interpose_multiple.c
test_ckpt.C
test_ckpt.cpp
test_ckpt.F
scr.moab
scr_interpose.moab
Expand Down Expand Up @@ -70,18 +70,18 @@ ADD_EXECUTABLE(test_interpose_multiple test_common.c test_interpose_multiple.c)
TARGET_LINK_LIBRARIES(test_interpose_multiple ${SCR_LINK_TO})
SCR_ADD_TEST(test_interpose_multiple "" "../examplesrank*.ckpt")

ADD_EXECUTABLE(test_ckpt_C test_ckpt.C)
ADD_EXECUTABLE(test_ckpt test_ckpt.cpp)
IF(MPI_CXX_FOUND)
TARGET_INCLUDE_DIRECTORIES(test_ckpt_C PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${MPI_CXX_INCLUDE_PATH})
TARGET_LINK_LIBRARIES(test_ckpt_C ${SCR_LINK_TO} ${MPI_CXX_LIBRARIES})
TARGET_INCLUDE_DIRECTORIES(test_ckpt PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${MPI_CXX_INCLUDE_PATH})
TARGET_LINK_LIBRARIES(test_ckpt ${SCR_LINK_TO} ${MPI_CXX_LIBRARIES})
ELSE(MPI_CXX_FOUND)
TARGET_LINK_LIBRARIES(test_ckpt_C ${SCR_LINK_TO})
TARGET_LINK_LIBRARIES(test_ckpt ${SCR_LINK_TO})
ENDIF(MPI_CXX_FOUND)
SCR_ADD_TEST(test_ckpt_C "" "rank_0.ckpt")
SCR_ADD_TEST(test_ckpt "" "rank_0.ckpt")

IF(ENABLE_FORTRAN)
SET_SOURCE_FILES_PROPERTIES(test_ckpt.F PROPERTIES LANGUAGE Fortran)
ADD_EXECUTABLE(test_ckpt_F test_ckpt.F)
ADD_EXECUTABLE(test_ckpt_F test_ckpt.F)
SET_TARGET_PROPERTIES(test_ckpt_F PROPERTIES LINKER_LANGUAGE Fortran)

IF(SCR_LINK_STATIC)
Expand Down
70 changes: 0 additions & 70 deletions examples/test_ckpt.C

This file was deleted.

90 changes: 90 additions & 0 deletions examples/test_ckpt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// mpig++ -g -O0 -I../src -o test_ckpt_C test_ckpt.C -L/usr/local/tools/scr-1.1/lib -lscr
/*
* Usage:
*
* ./test_ckpt [megabytes]
*
* Optionally pass the size of our checkpoint file to write, in megabytes.
*
* Note: This is compiled as C++ file to verify SCR works with C++. It only
* trivially uses C++ semantics, so that people can use it as example code for
* C as well.
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <assert.h>
#include <stdlib.h>
#include <iostream>
using namespace std;

#include "mpi.h"
#include "scr.h"
int checkpoint(int size_mb)
{
int rank;
char tmp[256];
char file[SCR_MAX_FILENAME];
char dir[SCR_MAX_FILENAME];
char dname;
int rc;

/* Get our rank */
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

/* Inform SCR that we are starting a new checkpoint */
SCR_Start_checkpoint();

/* Build the filename for our checkpoint file */
sprintf(tmp, "rank_%d", rank);
cout << "In: " << tmp << "\n";

/* Register our checkpoint file with SCR, and where to write it */
SCR_Route_file(tmp, file);

/* Write our checkpoint file */
sprintf(tmp, "truncate -s %dM %s", size_mb, file);
system(tmp);

cout << "Out: " << file << "\n";

/* Tell SCR whether this process wrote its checkpoint files successfully */
SCR_Complete_checkpoint(1);

return 0;
}

/*
* test_ckpt [megabytes]
*
* Optionally pass the size of our checkpoint file to write, in megabytes.
*/
int main(int argc, char **argv)
{
int size_mb = 1;

if (argc == 2) {
size_mb = atoi(argv[1]);
}

MPI_Init(NULL, NULL);

/* Initialize the SCR library */
SCR_Init();

/* Ask SCR whether we need to checkpoint */
int flag = 0;
SCR_Need_checkpoint(&flag);
if (flag) {
/* Execute the checkpoint code */
checkpoint(size_mb);
}

/* Shut down the SCR library */
SCR_Finalize();

MPI_Finalize();

return 0;
}

0 comments on commit afa51b9

Please sign in to comment.