title: Segmentation fault (core dumped) in SCHED_OTHER
body: <p>I am running this program but there is an issue which i cannot find.When i put dimensions 50x50x50 the program works fine but when i put for example 50x50x20 i show the error Segmentation fault (core dumped).I dont get it why its doing that.Anyone knows? Here is the code.I am trying to mul array A and B and i use the part to seperate the rows of array A to work equally to threads.Thanks in advance</p>
  <pre><code>    //SCHED_OTHER
  #include &lt;pthread.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;time.h&gt;
  #include &lt;sys/time.h&gt;
  #include &lt;sched.h&gt;
  int part,move=-1;
  int **A,**B,**C;
  int rows;
  int cols;
  int cols2;
  
  //AxB arrays
  //part used for seperate the work equally for threads
  void *mul(){
      int s=++move;
      struct timeval start, end;
      //printf(&quot;deadline thread started [%d]\n&quot;, gettid());
          struct sched_param params;
          //params.sched_priority =sched_get_priority_min(SCHED_RR);
          sched_setscheduler(0,SCHED_OTHER,&amp;params);
          gettimeofday(&amp;start,NULL);
          for(int k=s*part; k&lt;(s+1)*part; k++){
              for(int j=0; j&lt;cols; j++){
                  C[k][j]=0;
                  for(int f=0; f&lt;cols2; f++){
                      C[k][j]+=A[k][f]*B[f][j];
                      //sched_yield();
                  }
              }
          }
          gettimeofday(&amp;end,NULL);
          printf(&quot;Time taken for thread_other %d in microsec %ld\n&quot;,s+1,((end.tv_sec*1000000 +end.tv_usec)-(start.tv_sec *1000000 + start.tv_usec)));
          //if rows/5!=0 then the last threads doing the rest rows of array A
          if(s==4 &amp;&amp; rows/5!=0){
             for(int k=5*part; k&lt;rows; k++){
              for(int j=0; j&lt;cols; j++){
                  C[k][j]=0;
                  for(int f=0; f&lt;cols2; f++){
                      C[k][j]+=A[k][f]*B[f][j];
                  }
              }
          }
          }
          
  }
  
  int main(int argc,char *argv[]){
      
      pthread_t t[5];
      srand(time(NULL));
      printf(&quot;Give rows of array A\n&quot;);
      scanf(&quot;%d&quot;,&amp;rows);
      printf(&quot;Give cols of array A\n&quot;);
      scanf(&quot;%d&quot;,&amp;cols);
      printf(&quot;Give cols of array B\n&quot;);
      scanf(&quot;%d&quot;,&amp;cols2); 
  
      A=malloc(rows*(sizeof(int*)));
      for(int i=0; i&lt;rows; i++){
          A[i]=malloc(cols*(sizeof(int)));
      }
      B=malloc(cols*(sizeof(int*)));
      for(int i=0; i&lt;cols; i++){
          B[i]=malloc(cols2*(sizeof(int)));
      }
  
      C=malloc(rows*(sizeof(int*)));
      for(int i=0; i&lt;rows; i++){
          C[i]=malloc(cols2*(sizeof(int)));
      }
      for(int i=0; i&lt;rows; i++){
          for(int l=0; l&lt;cols; l++){
              A[i][l]= (rand()%2)+1;
              //A[i][l]=1;
             // printf(&quot;%5d&quot;,A[i][l]);
          }
          //printf(&quot;\n&quot;);
      }
      printf(&quot;\n&quot;);
      for(int i=0; i&lt;cols; i++){
          for(int l=0; l&lt;cols2; l++){
              B[i][l]= (rand()%2)+1;
              //B[i][l]=1;
              //printf(&quot;%5d&quot;,B[i][l]);
          }
          //printf(&quot;\n&quot;);
      }
      printf(&quot;\n&quot;);
      part=rows/5;
  
      
          int res;
          for(int i=0; i&lt;5; i++){
          res=pthread_create(&amp;t[i],NULL,mul,NULL);
          }
      
  
      for(int i=0; i&lt;5; i++){
          res=pthread_join(t[i],NULL);
      }
  
      for(int i=0; i&lt;rows; i++){
          for(int l=0; l&lt;cols2; l++){
              printf(&quot;%8d&quot;,C[i][l]);
  
          }
          printf(&quot;\n&quot;);
      }
      free(A);
      free(B);
      free(C);
      return 0;
  
  }
  </code></pre>