|
| 1 | +/* |
| 2 | +//@HEADER |
| 3 | +// ************************************************************************ |
| 4 | +// |
| 5 | +// |
| 6 | +// _|_|_|_| _|_|_|_| _| _| _|_|_| _| _| |
| 7 | +// _| _| _|_| _| _| _| _| |
| 8 | +// _|_|_| _|_|_| _| _| _| _| _| |
| 9 | +// _| _| _| _|_| _| _| _| |
| 10 | +// _| _|_|_|_| _| _| _|_|_| _| _| |
| 11 | +// |
| 12 | +// |
| 13 | +// |
| 14 | +// |
| 15 | +// Copyright (C) 2016 Rutgers University and Sandia Corporation |
| 16 | +// |
| 17 | +// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, |
| 18 | +// the U.S. Government retains certain rights in this software. |
| 19 | +// |
| 20 | +// Redistribution and use in source and binary forms, with or without |
| 21 | +// modification, are permitted provided that the following conditions are |
| 22 | +// met: |
| 23 | +// |
| 24 | +// 1. Redistributions of source code must retain the above copyright |
| 25 | +// notice, this list of conditions and the following disclaimer. |
| 26 | +// |
| 27 | +// 2. Redistributions in binary form must reproduce the above copyright |
| 28 | +// notice, this list of conditions and the following disclaimer in the |
| 29 | +// documentation and/or other materials provided with the distribution. |
| 30 | +// |
| 31 | +// 3. Neither the name of the Corporation nor the names of the |
| 32 | +// contributors may be used to endorse or promote products derived from |
| 33 | +// this software without specific prior written permission. |
| 34 | +// |
| 35 | +// THIS SOFTWARE IS PROVIDED BY RUTGERS UNIVERSITY and SANDIA CORPORATION |
| 36 | +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 37 | +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 38 | +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RUTGERS |
| 39 | +// UNIVERISY, SANDIA CORPORATION OR THE CONTRIBUTORS BE LIABLE FOR ANY |
| 40 | +// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 41 | +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 42 | +// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 43 | +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
| 44 | +// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 45 | +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 46 | +// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 47 | +// |
| 48 | +// Author Marc Gamell, Eric Valenzuela, Keita Teranishi, Manish Parashar, |
| 49 | +// Michael Heroux, and Matthew Whitlock |
| 50 | +// |
| 51 | +// Questions? Contact Keita Teranishi (knteran@sandia.gov) and |
| 52 | +// Marc Gamell (mgamell@cac.rutgers.edu) |
| 53 | +// |
| 54 | +// ************************************************************************ |
| 55 | +//@HEADER |
| 56 | +*/ |
| 57 | + |
| 58 | +#include <fenix.hpp> |
| 59 | +#include <mpi.h> |
| 60 | +#include <stdio.h> |
| 61 | +#include <stdlib.h> |
| 62 | +#include <signal.h> |
| 63 | +#include <sys/types.h> |
| 64 | +#include <unistd.h> |
| 65 | +#include <vector> |
| 66 | + |
| 67 | +constexpr int kKillID = 2; |
| 68 | +constexpr int my_group = 0; |
| 69 | +constexpr int my_member = 0; |
| 70 | +constexpr int start_timestamp = 0; |
| 71 | +constexpr int group_depth = 1; |
| 72 | +int errflag; |
| 73 | + |
| 74 | +using Fenix::DataSubset; |
| 75 | +using namespace Fenix::Data; |
| 76 | + |
| 77 | +int main(int argc, char **argv) { |
| 78 | + MPI_Init(&argc, &argv); |
| 79 | + |
| 80 | + MPI_Comm res_comm; |
| 81 | + Fenix::init({.out_comm = &res_comm, .spares = 1}); |
| 82 | + |
| 83 | + int num_ranks, rank; |
| 84 | + MPI_Comm_size(res_comm, &num_ranks); |
| 85 | + MPI_Comm_rank(res_comm, &rank); |
| 86 | + |
| 87 | + std::vector<int> data; |
| 88 | + |
| 89 | + bool should_throw = Fenix_get_role() == FENIX_ROLE_RECOVERED_RANK; |
| 90 | + while(true) try { |
| 91 | + if(should_throw){ |
| 92 | + should_throw = false; |
| 93 | + Fenix::throw_exception(); |
| 94 | + } |
| 95 | + |
| 96 | + //Initial work and commits |
| 97 | + if(Fenix_get_role() == FENIX_ROLE_INITIAL_RANK){ |
| 98 | + Fenix_Data_group_create( |
| 99 | + my_group, res_comm, start_timestamp, group_depth, FENIX_DATA_POLICY_IMR, |
| 100 | + NULL, &errflag |
| 101 | + ); |
| 102 | + Fenix_Data_member_create( |
| 103 | + my_group, my_member, data.data(), FENIX_RESIZEABLE, MPI_INT |
| 104 | + ); |
| 105 | + |
| 106 | + data.resize(100); |
| 107 | + for(int& i : data) i = -1; |
| 108 | + |
| 109 | + |
| 110 | + //Store the whole array first. We need to keep our buffer pointer updated |
| 111 | + //since resizing an array can change it |
| 112 | + Fenix_Data_member_attr_set( |
| 113 | + my_group, my_member, FENIX_DATA_MEMBER_ATTRIBUTE_BUFFER, data.data(), |
| 114 | + &errflag |
| 115 | + ); |
| 116 | + member_store(my_group, my_member, {{0, data.size()-1}}); |
| 117 | + Fenix_Data_commit_barrier(my_group, NULL); |
| 118 | + |
| 119 | + |
| 120 | + //Now commit a smaller portion with different data. |
| 121 | + data.resize(50); |
| 122 | + int val = 1; |
| 123 | + for(int& i : data) i = val++; |
| 124 | + |
| 125 | + Fenix_Data_member_attr_set( |
| 126 | + my_group, my_member, FENIX_DATA_MEMBER_ATTRIBUTE_BUFFER, data.data(), |
| 127 | + &errflag |
| 128 | + ); |
| 129 | + member_store(my_group, my_member, {{0, data.size()-1}}); |
| 130 | + Fenix_Data_commit_barrier(my_group, NULL); |
| 131 | + |
| 132 | + |
| 133 | + if(rank == kKillID){ |
| 134 | + fprintf(stderr, "Doing kill on node %d\n", rank); |
| 135 | + raise(SIGTERM); |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + Fenix_Finalize(); |
| 140 | + |
| 141 | + |
| 142 | + break; |
| 143 | + } catch (const Fenix::CommException& e) { |
| 144 | + const Fenix::CommException* err = &e; |
| 145 | + while(true) try { |
| 146 | + //We've had a failure! Time to recover data. |
| 147 | + fprintf(stderr, "Starting data recovery on rank %d\n", rank); |
| 148 | + if(err->fenix_err != FENIX_SUCCESS){ |
| 149 | + fprintf(stderr, "FAILURE on Fenix Init (%d). Exiting.\n", err->fenix_err); |
| 150 | + exit(1); |
| 151 | + } |
| 152 | + |
| 153 | + Fenix_Data_group_create( |
| 154 | + my_group, res_comm, start_timestamp, group_depth, FENIX_DATA_POLICY_IMR, |
| 155 | + NULL, &errflag |
| 156 | + ); |
| 157 | + |
| 158 | + //Do a null restore to get information about the stored subset |
| 159 | + DataSubset stored_subset; |
| 160 | + int ret = member_restore( |
| 161 | + my_group, my_member, nullptr, 0, FENIX_TIME_STAMP_MAX, stored_subset |
| 162 | + ); |
| 163 | + if(ret != FENIX_SUCCESS) { |
| 164 | + fprintf(stderr, "Rank %d restore failure w/ code %d\n", rank, ret); |
| 165 | + MPI_Abort(MPI_COMM_WORLD, 1); |
| 166 | + } |
| 167 | + |
| 168 | + //Resize data to fit all stored data |
| 169 | + data.resize(stored_subset.end()+1); |
| 170 | + |
| 171 | + //Set all data to a value that was never stored, just for testing |
| 172 | + for(int& i : data) i = -2; |
| 173 | + |
| 174 | + //Now do an lrestore to get the recovered data. |
| 175 | + ret = member_lrestore( |
| 176 | + my_group, my_member, data.data(), data.size(), FENIX_TIME_STAMP_MAX, |
| 177 | + stored_subset |
| 178 | + ); |
| 179 | + |
| 180 | + break; |
| 181 | + } catch (const Fenix::CommException& nested){ |
| 182 | + err = &nested; |
| 183 | + } |
| 184 | + } |
| 185 | + |
| 186 | + //Ensure data is correct after execution and recovery |
| 187 | + bool successful = data.size() == 50; |
| 188 | + if(!successful) printf("Rank %d expected data size 50, but got %d\n", rank, data.size()); |
| 189 | + |
| 190 | + for(int i = 0; i < data.size() && successful; i++){ |
| 191 | + successful &= data[i] == i+1; |
| 192 | + if(!successful) printf("Rank %d data[%d]=%d, but should be %d!\n", rank, i, data[i], i+1); |
| 193 | + } |
| 194 | + |
| 195 | + if(successful){ |
| 196 | + printf("Rank %d successfully recovered\n", rank); |
| 197 | + } else { |
| 198 | + printf("FAILURE on rank %d\n", rank); |
| 199 | + } |
| 200 | + |
| 201 | + MPI_Finalize(); |
| 202 | + return !successful; //return error status |
| 203 | +} |
0 commit comments