Skip to content

Commit

Permalink
1.0.2 (#67)
Browse files Browse the repository at this point in the history
* Changed the control flow in main to allow a try/catch of a bad_alloc exception.

* Adjusted memory allocation behavior (larger models will use slightly less memory)
  • Loading branch information
DanielOlson authored Sep 13, 2024
1 parent c0fdff8 commit 39f5421
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,14 @@ void Settings::assign_settings() {
this->window_size = 100 * this->max_period;
}

// medium models use less than 1 GB per thread
else if (period_memory <= 4000000) {
this->window_size = 50 * this->max_period;
}

// Large models use less than 4 GB per thread
else {
this->window_size = 50 * this->max_period;
this->window_size = 25 * this->max_period;
}

}
Expand Down Expand Up @@ -670,7 +675,7 @@ void Settings::print_memory_usage() {
dp_size *= (unsigned long long)(this->window_size + (2 * this->overlap));
printf("----------------------------\n");
printf("Maximum repeat period: %llu\n", this->max_period);
printf("Number of states: %i\n", num_states);
printf("Number of model states: %i\n", num_states);
printf("Total sequence window size: %lli\n",
(this->window_size + 2 * this->overlap));
printf("DP matrix cells: %llu\n", dp_size);
Expand All @@ -689,6 +694,7 @@ void Settings::print_memory_usage() {

printf("*Actual memory usage will be slightly greater due to "
"output repeat queue and repeat split matrices\n");
printf("============================\n");
}

// This could be done in less code with templates. Yikcy wicky yucky wucky.
Expand Down
2 changes: 1 addition & 1 deletion src/cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef ULTRA_CLI_HPP
#define ULTRA_CLI_HPP

#define ULTRA_VERSION_STRING "1.0.0"
#define ULTRA_VERSION_STRING "1.0.2"


#include "../lib/CLI11.hpp"
Expand Down
32 changes: 30 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#include "mask.hpp"
#include "ultra.hpp"
#include <string>
#include <new> // for std::bad_alloc

int main(int argc, const char *argv[]) {

int main_wrapper(int argc, const char * argv[]) {
// Prepare settings
Settings *settings = new Settings();
settings->prepare_settings();
Expand All @@ -13,8 +14,8 @@ int main(int argc, const char *argv[]) {
}

settings->assign_settings();
settings->print_memory_usage();
if (settings->show_memory) {
settings->print_memory_usage();
exit(0);
}

Expand Down Expand Up @@ -172,3 +173,30 @@ int main(int argc, const char *argv[]) {

return 0;
}


int main(int argc, const char *argv[]) {

char *reserve_memory = (char *)malloc(65536);
try {
int r = main_wrapper(argc, argv);
return r;
}
catch (const std::bad_alloc& e) {
// This block is executed if memory allocation fails
free(reserve_memory); // May be necessary in order to print
std::cerr << "Memory allocation failed: " << e.what() << std::endl;
std::cerr << "Your model may be too large to fit in memory" << std::endl;
std::cerr << "Try running: ultra --mem <your arguments> to see expected memory usage" << std::endl;
}
catch (const std::exception& e) {
// This block is executed for any other standard exceptions
std::cerr << "Standard exception caught: " << e.what() << std::endl;
}
catch (...) {
// This block catches any other non-standard exceptions
std::cerr << "Unknown exception caught!" << std::endl;
}

return -1;
}

0 comments on commit 39f5421

Please sign in to comment.