|
| 1 | +//This example demonstrates the simulator using the ADSim API directly, and using a real outlier algorithm |
| 2 | +#include<mpi.h> |
| 3 | +#include<sim.hpp> |
| 4 | +#include<random> |
| 5 | + |
| 6 | +using namespace chimbuko_sim; |
| 7 | + |
| 8 | +int main(int argc, char **argv){ |
| 9 | + MPI_Init(&argc, &argv); |
| 10 | + |
| 11 | + int window_size = 5; //number of events to record around an anomaly in the provenance data |
| 12 | + int pid = 0; //program index |
| 13 | + unsigned long program_start = 100; |
| 14 | + unsigned long step_freq = 1000; |
| 15 | + |
| 16 | + //Set the AD algorithm *before instantiating the simulator! |
| 17 | + ADalgParams & alg = adAlgorithmParams(); |
| 18 | + alg.algorithm = "sstd"; |
| 19 | + alg.sstd_sigma = 12.0; |
| 20 | + |
| 21 | + //Setup the "AD" instances |
| 22 | + int n_ranks = 1; |
| 23 | + std::vector<ADsim> ad; |
| 24 | + for(int r=0;r<n_ranks;r++) |
| 25 | + ad.push_back(ADsim(window_size, pid, r, program_start, step_freq)); |
| 26 | + |
| 27 | + //Setup some functions |
| 28 | + registerFunc("main"); |
| 29 | + registerFunc("child"); |
| 30 | + |
| 31 | + //Setup some systems |
| 32 | + std::vector<int> cpu_threads(4); for(int i=0;i<4;i++) cpu_threads[i] = i; |
| 33 | + |
| 34 | + int gpus = 2; |
| 35 | + std::vector<int> gpu_threads(gpus); //assign virtual thread indices to gpus and register |
| 36 | + for(int g=0;g<gpus;g++){ |
| 37 | + gpu_threads[g] = cpu_threads.size() + g; //GPU virtual index should not correspond with a CPU core thread index |
| 38 | + ad[0].registerGPUthread(gpu_threads[g]); |
| 39 | + } |
| 40 | + |
| 41 | + std::default_random_engine gen; |
| 42 | + std::normal_distribution<double> dist(100,20); //normal std.dev = 20 |
| 43 | + |
| 44 | + unsigned long child_start = 200; |
| 45 | + int nexec = 500; |
| 46 | + std::vector<int> starts(nexec); |
| 47 | + std::vector<int> runtimes(nexec); |
| 48 | + for(int i=0;i<nexec;i++){ |
| 49 | + if(i==0) starts[i] = child_start; |
| 50 | + else starts[i] = starts[i-1] + runtimes[i-1] + 1; |
| 51 | + runtimes[i] = int( dist(gen) ); |
| 52 | + } |
| 53 | + //Add an anomaly |
| 54 | + starts.push_back( starts.back() + runtimes.back() + 1 ); |
| 55 | + runtimes.push_back( 400 ); |
| 56 | + nexec++; |
| 57 | + |
| 58 | + int program_end = starts.back() + runtimes.back() + 50; |
| 59 | + |
| 60 | + auto main = ad[0].addExec(0, "main", program_start, program_end - program_start); |
| 61 | + for(int i=0;i<nexec;i++){ |
| 62 | + CallListIterator_t child = ad[0].addExec(0, "child", starts[i], runtimes[i]); |
| 63 | + ad[0].bindParentChild(main, child); |
| 64 | + } |
| 65 | + |
| 66 | + //Run the simulation |
| 67 | + int nstep = ad[0].largest_step() + 1; |
| 68 | + std::cout << "Got data for " << nstep << " steps" << std::endl; |
| 69 | + |
| 70 | + for(int i=0;i<nstep;i++){ |
| 71 | + std::cout << "Step " << i << " contains " << ad[0].nStepExecs(i) << " execs" << std::endl; |
| 72 | + ad[0].step(i); |
| 73 | + } |
| 74 | + |
| 75 | + MPI_Finalize(); |
| 76 | + return 0; |
| 77 | +} |
0 commit comments