/* -----------------------------------------------------!
! The current code has the purpose:                     !
! (1) how to use single blocks.                         !
!-------------------------------------------------------!
! Xiaoxu Guan at LSU HPC.                               !
! March 07, 2016                                        !
!----------------------------------------------------- */

#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main () 
{
    int i,j,k,id;
    const int nsize_a = 800, nsize_b = 200;
    double time_start,time_end,temp;
    double array_a[nsize_a-1,nsize_a-1,nsize_a-1];
    double array_b[nsize_b-1,nsize_b-1];


    time_start = omp_get_wtime();

 #pragma omp parallel
    {
        #pragma omp single
          { 
           id = omp_get_thread_num(); 
           printf("single block 1. My id is %d\n", id);
           for (i=0; i<=nsize_a-1; i++) {
           for (j=0; j<=nsize_a-1; j++) {
           for (k=0; k<=nsize_a-1; k++) {
              temp = sin((double)(i+j+k));
              array_a[i,j,k] = exp(temp);
                  } } }
          }

        #pragma omp single
          {
           id = omp_get_thread_num();
           printf("single block 2. My id is %d\n", id);
           for (i=0; i<=nsize_b-1; i++) {
           for (j=0; j<=nsize_b-1; j++) {
               temp = sin((double)(i+j)); 
               array_b[i,j] = exp(temp);
                       } }
           }

    }

      time_end = omp_get_wtime();
      printf("elapsed time (seconds) = %.5f\n", time_end-time_start) ;

}

