Yes, it works! Thank you, Philipp. I changed all the SC_THREADs to SC_METHODS and now I can run a size as large as 32768. When N=65536, the 8GB memory on my computer runs out, but there are no errors any more. For SC_METHODS, I cannot change the stack size. So for the next step, probably I need to improve the algorithm.
Anyway, this problem is solved. Thanks again!