I would like to resize the stack so that a project with many non-recursive functions runs on big data. To do this, I tried to set OCAMLRUNPARAM="l=xxx" for different xxx values ââ(in the range from 0 to 10G), but this had no effect. Is OCAMLRUNPARAM even the right approach?
In case it matters: the project that interests me is built using OCamlMakefile, target native-code .
Here is a minimal example where just a large list is created without tail recursion. To quickly check if the OCAMLRUNPARAM effect has an effect, I compiled the stacktest.ml program:
let rec create l = match l with | 0 -> [] | _ -> "00"::(create (l-1)) let l = create (int_of_string (Sys.argv.(1))) let _ = print_endline("List of size " ^ string_of_int (List.length l) ^ " created.")
using the command
ocamlbuild stacktest.native
and found out roughly how long the list overflows the stack overflow (more or less) a binary search with the following bash script foo.sh :
#!/bin/bash export OCAMLRUNPARAM="l=$1" increment=1000000 length=1 while [[ $increment > 0 ]] ; do while [[ $(./stacktest.native $length) ]]; do length=$(($length+$increment)) done length=$(($length-$increment)) increment=$(($increment/2)) length=$(($length+$increment)) done length=$(($length-$increment)) echo "Largest list without overflow: $length" echo $OCAMLRUNPARAM
The results vary between runs of this script (and the intermediate results are not even consistent for one run, but let them ignore it at the moment), but they are similar, regardless of whether I call
bash foo.sh 1
or
bash foo.sh 1G
i.e. whether the stack size is set to 1 or 2 ^ 30 words.
source share