static void end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending phase %d, ok is %d\n", phase, ok); if (NULL != proc) { if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); } GNUNET_OS_process_wait (proc); GNUNET_OS_process_destroy (proc); proc = NULL; } if (NULL != read_task) { GNUNET_SCHEDULER_cancel (read_task); read_task = NULL; } GNUNET_DISK_pipe_close (pipe_stdout); if (ok == 1) { if (phase < 9) { phase += 1; runone (); } else ok = 0; } else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "failing\n"); }
int main(int argc, char* argv[]) { if (argc == 1) { std::cerr << "Usage: euler all OR euler n n n\n"; return 1; } if (argc == 2 && strcmp(argv[1], "all") == 0) { runall(); return 0; } // Otherwise, make a mapping, and run them individually. std::map<int, euler::Problem> pmap; for (auto prob : euler::problems) { pmap[prob.number] = prob; } for (auto arg = argv + 1; *arg != nullptr; ++arg) { const int num = std::stoi(*arg); auto prob = pmap.find(num); if (prob == pmap.end()) { std::cout << "Unknown problem: " << num << '\n'; } else { runone(prob->second); } } return 0; }
static void task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { phase = 0; runone (); }
int main(int argc, char **argv) { int c, result, exit_code; size_t i, nruns = 25; struct pipe *p; struct timespec ts, te, t; while ((c = getopt(argc, argv, "a:n:r:w:")) != -1) { switch (c) { case 'a': nactive = (size_t)atoi(optarg); break; case 'n': npipes = (size_t)atoi(optarg); break; case 'r': nruns = (size_t)atoi(optarg); break; case 'w': nwrites = (size_t)atoi(optarg); break; default: errx(EXIT_FAILURE, "illegal argument `%c'", c); } } if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) err(EXIT_FAILURE, "clock_gettime"); if ((e = eloop_new()) == NULL) err(EXIT_FAILURE, "eloop_init"); if (nactive > npipes) nactive = npipes; pipes = calloc(npipes, sizeof(*p)); if (pipes == NULL) err(EXIT_FAILURE, "malloc"); for (i = 0, p = pipes; i < npipes; i++, p++) { if (pipe2(p->fd, O_CLOEXEC | O_NONBLOCK) == -1) err(EXIT_FAILURE, "pipe"); if (eloop_event_add(e, p->fd[0], read_cb, p) == -1) err(EXIT_FAILURE, "eloop_event_add"); } printf("active = %zu, pipes = %zu, runs = %zu, writes = %zu\n", nactive, npipes, nruns, nwrites); exit_code = EXIT_SUCCESS; for (i = 0; i < nruns; i++) { result = runone(&t); if (result != EXIT_SUCCESS) exit_code = result; printf("run %zu took %lld.%.9ld seconds, result %d\n", i + 1, (long long)t.tv_sec, t.tv_nsec, result); } eloop_free(e); free(pipes); if (clock_gettime(CLOCK_MONOTONIC, &te) == -1) err(EXIT_FAILURE, "clock_gettime"); timespecsub(&te, &ts, &t); printf("total %lld.%.9ld seconds, result %d\n", (long long)t.tv_sec, t.tv_nsec, exit_code); exit(exit_code); }
void runall() { for (auto& prob : euler::problems) { runone(prob); } }