Skip to content

Instantly share code, notes, and snippets.

@jdherman
Last active January 3, 2016 09:29
Show Gist options
  • Save jdherman/8443416 to your computer and use it in GitHub Desktop.
Save jdherman/8443416 to your computer and use it in GitHub Desktop.
Boilerplate for running parallel Borg (C)
// Optional settings:
// BORG_Debug_on();
// BORG_Algorithm_ms_max_time(0.008);
// BORG_Algorithm_output_aerovis();
char runtime[256];
char outputFilename[256];
FILE* outputFile = NULL;
BORG_Algorithm_ms_startup(&argc, &argv);
BORG_Algorithm_ms_max_evaluations(100000);
BORG_Problem problem = BORG_Problem_create(num_decisions, num_objectives, num_constraints, my_eval_function);
// Define filenames for runtime and end-of-run output
sprintf(runtime, "./output/runtime_seed_%d.txt",seed);
sprintf(outputFilename, "./output/my_results_seed_%d.set", seed);
// Turn on the runtime output (pass in the filename), and define the printing frequency
BORG_Algorithm_output_runtime(runtime);
BORG_Algorithm_output_frequency(5000);
BORG_Random_seed(seed);
BORG_Archive result = BORG_Algorithm_ms_run(problem);
// If this is the master node, print out the final archive
if (result != NULL) {
outputFile = fopen(outputFilename, "w");
if (!outputFile) {
BORG_Debug("Unable to open final output file\n");
}
BORG_Archive_print(result, outputFile);
BORG_Archive_destroy(result);
fclose(outputFile);
}
BORG_Algorithm_ms_shutdown();
BORG_Problem_destroy(problem);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment