title: Segmentation Fault when using OpenMP when creating an array
body: <p>I'm having a Segmentation Fault when accessing an array inside a for loop.
  What I'm trying to do is to generate all subsequences of a DNA string.</p>
  
  <p>It was happening when I created the array inside the for. After reading for a while, I found out that the openmp limits the stack size, so it would be safer to use the heap instead. So I change the code to use malloc, but the problem persists.</p>
  
  <p>This is the full code:</p>
  
  <pre><code>#include &lt;limits.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;math.h&gt;
  #include &lt;omp.h&gt;
  
  #define DNA_SIZE 26 
  #define DNA "AGTC"
  
  static char** powerset(int argc, char* argv)
  {
      unsigned int i, j, bits, i_max = 1U &lt;&lt; argc;
  
      if (argc &gt;= sizeof(i) * CHAR_BIT) {
          fprintf(stderr, "Error: set too large\n");
          exit(1);
      }
      omp_set_num_threads(2);
      char** subsequences = malloc(i_max*sizeof(char*));
  
      #pragma omp parallel for shared(subsequences, argv) 
      for (i = 0; i &lt; i_max ; ++i) {
          //printf("{");
          int characters = 0;
          for (bits=i; bits ; bits&gt;&gt;=1)
              if (bits &amp; 1)
                  ++characters;
  
          //This is the line where the error is happening. 
          char *ss = malloc(characters+1 * sizeof(char)*16);//the *16 is just to save the cache lin       
  
          int ssindex = 0;
  
          for (bits = i, j=0; bits; bits &gt;&gt;= 1, ++j) {
              if (bits &amp; 1) {
                  //char a = argv[j];
                  ss[ssindex++] = argv[j] ;
              } 
          }
          ss[ssindex] = '\0';
          subsequences[i] = ss;       
      }
      return subsequences;
  }
  
  char* getdna()
  {
      int i;
  
      char *dna = (char *)malloc((DNA_SIZE+1) * sizeof(char));
  
      for(i = 0; i &lt; DNA_SIZE; i++)
      {
          int randomDNA = rand() % 4;
          dna[i] = DNA[randomDNA];
      }
  
      dna[DNA_SIZE] = '\0';
  
      return dna;
  }
  
  void printResult(char** ss, int size)
  {
      //PRINTING THE SUBSEQUENCES
      printf("SUBSEQUENCES FOUND:\r\n");
      int i;
      for(i = 0; i &lt; size; i++)
      {
          printf("%i.\t{ %s } \r\n",i+1 , ss[i]);
          free(ss[i]);
      }
      free(ss);
  }
  
  int main(int argc, char* argv[])
  {
      srand(time(NULL));
      double starttime, stoptime;
      starttime = omp_get_wtime();
      char* a = getdna();
      printf("%s\r\n", a);
      int size = pow(2, DNA_SIZE);
      printf("number of subsequences: %i\r\n", size);
  
      char** subsequences = powerset(DNA_SIZE, a);    
      //todo: make it optional printing to the stdout or saving to a file
      //printResult(subsequences, size);
      stoptime = omp_get_wtime();
  
      printf("Tempo de execucao: %3.2f segundos\n\n", stoptime-starttime);
      printf("Numero de sequencias geradas: %i\n\n", size);
      free(a);
      return 0;
  }
  </code></pre>
  
  <p>I also tried to make the malloc line critical with the <code>#pragma omp critical</code> which didn't help.
  Also I tried to compile with -mstackrealign which also didn't work.</p>
  
  <p>Appreciate all the help.</p>