title: OpenMP Multithread Parallel Programming
body: <p>My parallel program have same time compared to serial program and I don't know why (both 7.3s for small data 43s for big data, so there is no acceleration). But I guess it caused of printf? But my teacher ask me keep to use printf.
  And 1 more, is there a way to parallel the input procedure? Because it also takes much time. (With some trick like delete the number after read, etc xD)</p>
  
  <pre><code>void input(int ***a, int set){
   int i,j;
   FILE *f;
  switch(set){
      case 1: f = fopen("dataset1.txt","r");break;
      case 2: f = fopen("dataset2.txt","r");break;
      case 3: f = fopen("dataset3.txt","r");break;
      case 4: f = fopen("dataset4.txt","r");break;
      case 5: f = fopen("dataset5.txt","r");break;
      case 6: f = fopen("dataset6.txt","r");break;
      case 7: f = fopen("dataset7.txt","r");break;
      case 8: f = fopen("dataset8.txt","r");break;
      case 9: f = fopen("dataset9.txt","r");break;
      case 10: f = fopen("dataset10.txt","r");break;
  }
  for(i=0;i&lt;s;i++)
      for(j=0;j&lt;s;j++)
          fscanf(f,"%d ",&amp;(*a)[i][j]);
  fclose(f);
  }
  
  serial code:
      void rangeCheck(int **a){
        int i,j;
        for(i=0;i&lt;s;i++)
          for(j=0;j&lt;s;j++)
           if(a[i][j]&gt;=min &amp;&amp; a[i][j]&lt;=max)
             printf("(%d,%d) ",i,j);
      }
  
  parallel code:
      void rangeCheck(const int **a){
        int i,chunk,id,p=4;
        chunk = (s%p==0) ? s/p : s/p+1;
        #pragma omp parallel private(i,id)
        {
          id = omp_get_thread_num();
          #pragma omp for schedule (static,chunk)
            for(i=0;i&lt;s;i++){
              int j;
              for(j=0;j&lt;s;j++)
                if(a[i][j]&gt;=min &amp;&amp; a[i][j]&lt;=max)
                  printf("(%d,%d) ",i,j);
            }
        }
  }
  </code></pre>