Skip to content

Commit 39f5421

Browse files
authored
1.0.2 (#67)
* 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)
1 parent c0fdff8 commit 39f5421

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

src/cli.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,14 @@ void Settings::assign_settings() {
634634
this->window_size = 100 * this->max_period;
635635
}
636636

637+
// medium models use less than 1 GB per thread
638+
else if (period_memory <= 4000000) {
639+
this->window_size = 50 * this->max_period;
640+
}
641+
637642
// Large models use less than 4 GB per thread
638643
else {
639-
this->window_size = 50 * this->max_period;
644+
this->window_size = 25 * this->max_period;
640645
}
641646

642647
}
@@ -670,7 +675,7 @@ void Settings::print_memory_usage() {
670675
dp_size *= (unsigned long long)(this->window_size + (2 * this->overlap));
671676
printf("----------------------------\n");
672677
printf("Maximum repeat period: %llu\n", this->max_period);
673-
printf("Number of states: %i\n", num_states);
678+
printf("Number of model states: %i\n", num_states);
674679
printf("Total sequence window size: %lli\n",
675680
(this->window_size + 2 * this->overlap));
676681
printf("DP matrix cells: %llu\n", dp_size);
@@ -689,6 +694,7 @@ void Settings::print_memory_usage() {
689694

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

694700
// This could be done in less code with templates. Yikcy wicky yucky wucky.

src/cli.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#ifndef ULTRA_CLI_HPP
66
#define ULTRA_CLI_HPP
77

8-
#define ULTRA_VERSION_STRING "1.0.0"
8+
#define ULTRA_VERSION_STRING "1.0.2"
99

1010

1111
#include "../lib/CLI11.hpp"

src/main.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
#include "mask.hpp"
33
#include "ultra.hpp"
44
#include <string>
5+
#include <new> // for std::bad_alloc
56

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

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

1516
settings->assign_settings();
17+
settings->print_memory_usage();
1618
if (settings->show_memory) {
17-
settings->print_memory_usage();
1819
exit(0);
1920
}
2021

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

173174
return 0;
174175
}
176+
177+
178+
int main(int argc, const char *argv[]) {
179+
180+
char *reserve_memory = (char *)malloc(65536);
181+
try {
182+
int r = main_wrapper(argc, argv);
183+
return r;
184+
}
185+
catch (const std::bad_alloc& e) {
186+
// This block is executed if memory allocation fails
187+
free(reserve_memory); // May be necessary in order to print
188+
std::cerr << "Memory allocation failed: " << e.what() << std::endl;
189+
std::cerr << "Your model may be too large to fit in memory" << std::endl;
190+
std::cerr << "Try running: ultra --mem <your arguments> to see expected memory usage" << std::endl;
191+
}
192+
catch (const std::exception& e) {
193+
// This block is executed for any other standard exceptions
194+
std::cerr << "Standard exception caught: " << e.what() << std::endl;
195+
}
196+
catch (...) {
197+
// This block catches any other non-standard exceptions
198+
std::cerr << "Unknown exception caught!" << std::endl;
199+
}
200+
201+
return -1;
202+
}

0 commit comments

Comments
 (0)