Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. /*
  2. ============================================================================
  3. Name : laborator7_probl1.c
  4. Author : Muller Preparata
  5. Version :
  6. Copyright : Your copyright notice
  7. Description : Hello OpenMP World in C
  8. ============================================================================
  9. */
  10. #include <omp.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. /**
  14. * Hello OpenMP World prints the number of threads and the current thread id
  15. */
  16. int main(int argc, char *argv[]) {
  17.  
  18. int n = 4;
  19. int A[] = { 2, 6, 3, 8 };
  20. int R[2 * n - 2][n];
  21.  
  22. omp_set_num_threads(n);
  23.  
  24. for (int i = 0; i < 2 * n - 2; i++) {
  25. for (int j = 0; j < n; j++)
  26. R[i][j] = 0;
  27. }
  28.  
  29. #pragma omp parallel
  30. {
  31.  
  32. int tid = omp_get_thread_num();
  33. //printf("Salut de la threadul %d.(%d)\n",tid,A[tid]);
  34. for (int i = 0; i < n; i++) {
  35.  
  36. if (A[tid] < A[i]) {
  37. R[tid+n][i]=1;
  38. printf("Threadul %d a pus R[%d][%d] pe 1.\n",tid,(tid+n),i);
  39. }
  40. else{
  41. R[tid+n][i]=0;
  42. printf("Threadul %d a pus R[%d][%d] pe 0.\n",tid,tid+n,i);
  43. }
  44. }
  45.  
  46. #pragma omp barrier
  47. tid = omp_get_thread_num();
  48. for(int i=0;i<n;i++)
  49. {
  50. R[0][tid] += R[i+n][tid];
  51. }
  52. }
  53.  
  54. for (int i = 0; i < 2 * n - 1; i++) {
  55. for (int j = 0; j < n; j++)
  56. printf("%d ",R[i][j]);
  57. printf("\n");
  58. }
  59.  
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement