Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. /*
  2. ============================================================================
  3. Name : 1.c
  4. Author : DaTe
  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 numThreads, tid;
  19. int i, j;
  20. int n = 4;
  21. int A[]={30,10,40,20};
  22. int B[]={30,10,40,20};
  23. int R[2*n-1][n];
  24. int P[20];
  25.  
  26. /* This creates a team of threads; each thread has own copy of variables */
  27. #pragma omp parallel for
  28. for(i=0;i<=n-1;++i)
  29. {
  30. for(j=0;j<=n-1;++j)
  31. {
  32. if(A[i] < A[j])
  33. {
  34. R[i+n-1][j] = 1;
  35. }
  36. else
  37. {
  38. R[i+n-1][j] = 0;
  39. }
  40. }
  41. }
  42.  
  43. printf("aa\n");
  44. #pragma omp parallel for
  45. for(j=0;j<=n-1;j++)
  46. {
  47. for(i=n-2;i>=0;--i)
  48. {
  49. R[i][j]=R[2*i+1][j]+R[2*i+2][j];
  50. }
  51. }
  52.  
  53. printf("aa\n");
  54. #pragma omp parallel for
  55. for(j=0;j<n;j++)
  56. {
  57. B[R[0][j]] = A[j];
  58. }
  59. printf("aa\n");
  60.  
  61. for(j=0;j<n;j++){
  62. printf("%d\n", B[j]);
  63. }printf("aa\n");
  64.  
  65. for(i=0;i<n;++i){
  66. for(j=0;j<n;j++){
  67. printf("%d\t", R[i][j]);
  68. }
  69. printf("\n");
  70. }
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement