mehrdad
mehrdad

Reputation: 193

how to know a c program's stack overflows?

i am simulating a problem(3d Ising Model) in c but when the problem size gets larger the program stop and the below error appears :

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

in the program I have a recursive function that does all the works, i suspect that the error is because of stack overflow(in the recursive function) but i do not know how to be sure.

and if it is because of stack overflow, is there any way to solve this problem without changing program design?

i am using Clion IDE.

/*
 * recursive function to form Wolff Cluster(= WC)
 */
void grow_Wolff_cluster(lattic* l, Wolff* wolff, site *seed){

    /*a neighbor of site seed*/
    site* neighbor;

    /*go through all neighbors of seed*/
    for (int i = 0 ; i < neighbors ; ++i) {


        neighbor = seed->neighbors[i];

        /*add to WC according to the Wolff Algorithm*/
        if(neighbor->spin == seed->spin && neighbor->WC == -1 && ((double)rand() / RAND_MAX) < add_probability)
        {
            wolff->Wolff_cluster[wolff->WC_pos] = neighbor;
            wolff->WC_pos++;                  // the number of sites that is added to WC
            neighbor->WC = 1;          // for avoiding of multiple addition of site
            neighbor->X = 0;


            ///controller_site_added_to_WC();


            /*continue growing Wolff cluster(recursion)*/
            grow_Wolff_cluster(l, wolff, neighbor);
        }
    }
}

Upvotes: 1

Views: 173

Answers (1)

QuesterDesura
QuesterDesura

Reputation: 415

Use the GDB Debugger and look at the Call Stack.

gdb main
r
bt

Upvotes: 3

Related Questions