From 7578a9d04b666cff3f02aa2d2c1b2cce8a3d3939 Mon Sep 17 00:00:00 2001 From: kartofen Date: Fri, 11 Nov 2022 00:24:24 +0200 Subject: add bigger stack fix --- src/main.c | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 8b412ca..e6974a0 100644 --- a/src/main.c +++ b/src/main.c @@ -1,33 +1,52 @@ -// ----------------- OPTIONS ----------------- // -#define FILE_PATH "files/in.txt" +#define WALK_LEN 200 +// #define FILE_PATH "files/in.txt" +#define FILE_PATH "files/shakespeare.txt" // #define FILE_PATH "files/south-park-the-aristocrats.txt" -#define WALK_LEN 100000 - -#define PRINT_CHAIN -#define PRINT_ITEM_FREQUENCY -// #define PRINT_ON_WALK -// #define SAVE_TO_FILE_ON_WALK "out.txt" -// --------------- END OPTIONS --------------- // +// #define PRINT_CHAIN +// #define PRINT_ITEM_FREQUENCY +#define PRINT_ON_WALK #include +#include #include -#define ITEM_CAP 1024 -int ITEMS = 0; +#define ITEM_CAP 4000 +#include "markov.h" +int ITEMS = 0; double chain[ITEM_CAP][ITEM_CAP] = {0}; char item_names[ITEM_CAP][64] = {0}; -#include "markov.h" +void set_stack(); int main(void) { + set_stack(); + srand(time(NULL)); generate_chain(); + take_walk(); #ifdef PRINT_CHAIN print_chain(); #endif - take_walk(); return 0; } + +// for stack +#include +void set_stack() +{ + const rlim_t kStackSize = 64L * 1024L * 1024L; // min stack size = 64 Mb + struct rlimit rl; + int result; + + if(getrlimit(RLIMIT_STACK, &rl) == 0) { + if (rl.rlim_cur < kStackSize) { + rl.rlim_cur = kStackSize; + + if((result = setrlimit(RLIMIT_STACK, &rl)) != 0) + fprintf(stderr, "setrlimit returned result = %d\n", result); + } + } +} -- cgit v1.2.3