fork(1) download
  1. #define _BSD_SOURCE
  2.  
  3. #include <omp.h>
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. #include <stdlib.h>
  7. #include <sys/time.h>
  8.  
  9. #define LENGHT 144
  10.  
  11. //omp_set_num_threads(64);
  12. void numero1(int* arr, int n);
  13. void numero2(int* arr, int n);
  14. void printArray(int* arr);
  15.  
  16. void main(int argc, char *argv[])
  17. {
  18. if(argc == 4) {
  19. int p = atoi(argv[1]);
  20. int v = atoi(argv[2]);
  21. int n = atoi(argv[3]);
  22. // read p, v, n
  23. int i;
  24. int arr[LENGHT];
  25. struct timeval begin, end;
  26. for(i = 0; i < LENGHT; i++) {
  27. arr[i] = v;
  28. if(p == 2) {
  29. omp_init_lock(&(arr[i]));
  30. }
  31. }
  32. gettimeofday(&begin, NULL);
  33. if(p == 1) {
  34. numero1(arr, n);
  35. } else if(p == 2) {
  36. numero2(arr, n);
  37. }
  38. gettimeofday(&end, NULL);
  39. double elapsed = (end.tv_sec - begin.tv_sec) + ((end.tv_usec - begin.tv_usec)/1000000.0);
  40. printf("Time elapsed: %f\n",elapsed);
  41. }
  42. }
  43.  
  44. void numero1(int* arr, int n) {
  45. int i, k;
  46. #pragma omp parallel num_threads(48)
  47. {
  48. k = omp_get_thread_num();
  49. #pragma omp for
  50. for (i = 1; i < n; i++){
  51. arr[k] = arr[k] + (k / 8) + (k % 8);
  52. k = k + 48;
  53. arr[k] = arr[k] + (k / 8) + (k % 8);
  54. k = k + 48;
  55. arr[k] = arr[k] + (k / 8) + (k % 8);
  56. usleep(50000);
  57.  
  58. }
  59. }
  60. }
  61.  
  62. void numero2(int* arr, int n) {
  63. int i, j, k;
  64. #pragma omp parallel num_threads(48)
  65. {
  66. k = omp_get_thread_num();
  67. #pragma omp for
  68. for (i = 1; i < n; i++) {
  69. j = k % 12;
  70. k += 96;
  71. omp_set_lock(&(arr[k]));
  72. usleep(25000);
  73. if(j < 11) {
  74. omp_set_lock(&(arr[k + 1]));
  75. // Lock jusqua temps j == 1 execute
  76. arr[k] = arr[k] + arr[k + 1];
  77. omp_unset_lock(&(arr[k + 1]));
  78. k = k - 48;
  79. omp_set_lock(&(arr[k+ 1]));
  80. // Lock jusqua temps j == 1 execute
  81. arr[k] = arr[k] + arr[k + 1];
  82. omp_unset_lock(&(arr[k + 1]));
  83. k = k - 48;
  84. omp_set_lock(&(arr[k + 1]));
  85. // Lock jusqua temps j == 1 execute
  86. arr[k] = arr[k] + arr[k + 1];
  87. omp_unset_lock(&(arr[k + 1]));
  88. } else {
  89. arr[k] = arr[k] + (k / 8);
  90. }
  91. omp_unset_lock(&(arr[k]));
  92. usleep(25000);
  93. }
  94. }
  95. }
  96.  
  97. void printArray(int* arr) {
  98. int i;
  99. for (i = 0; i < LENGHT; i++) {
  100. int val = arr[i];
  101. printf("%d ", val);
  102. if(((i + 1) % 12) == 0) {
  103. printf("\n");
  104. }
  105. }
  106. }
  107.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/include/stdio.h:27:0,
                 from prog.c:4:
/usr/include/features.h:148:3: warning: #warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" [-Wcpp]
 # warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
   ^~~~~~~
prog.c:16:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
 void main(int argc, char *argv[])
      ^~~~
prog.c: In function ‘main’:
prog.c:29:23: warning: passing argument 1 of ‘omp_init_lock’ from incompatible pointer type [-Wincompatible-pointer-types]
         omp_init_lock(&(arr[i]));
                       ^
In file included from prog.c:3:0:
/usr/lib/gcc/x86_64-linux-gnu/6/include/omp.h:100:13: note: expected ‘omp_lock_t * {aka struct <anonymous> *}’ but argument is of type ‘int *’
 extern void omp_init_lock (omp_lock_t *) __GOMP_NOTHROW;
             ^~~~~~~~~~~~~
prog.c: In function ‘numero1’:
prog.c:46:0: warning: ignoring #pragma omp parallel [-Wunknown-pragmas]
   #pragma omp parallel num_threads(48)
 
prog.c:49:0: warning: ignoring #pragma omp for [-Wunknown-pragmas]
     #pragma omp for
 
prog.c: In function ‘numero2’:
prog.c:64:0: warning: ignoring #pragma omp parallel [-Wunknown-pragmas]
   #pragma omp parallel num_threads(48)
 
prog.c:67:0: warning: ignoring #pragma omp for [-Wunknown-pragmas]
     #pragma omp for
 
prog.c:71:20: warning: passing argument 1 of ‘omp_set_lock’ from incompatible pointer type [-Wincompatible-pointer-types]
       omp_set_lock(&(arr[k]));
                    ^
In file included from prog.c:3:0:
/usr/lib/gcc/x86_64-linux-gnu/6/include/omp.h:104:13: note: expected ‘omp_lock_t * {aka struct <anonymous> *}’ but argument is of type ‘int *’
 extern void omp_set_lock (omp_lock_t *) __GOMP_NOTHROW;
             ^~~~~~~~~~~~
prog.c:74:22: warning: passing argument 1 of ‘omp_set_lock’ from incompatible pointer type [-Wincompatible-pointer-types]
         omp_set_lock(&(arr[k + 1]));
                      ^
In file included from prog.c:3:0:
/usr/lib/gcc/x86_64-linux-gnu/6/include/omp.h:104:13: note: expected ‘omp_lock_t * {aka struct <anonymous> *}’ but argument is of type ‘int *’
 extern void omp_set_lock (omp_lock_t *) __GOMP_NOTHROW;
             ^~~~~~~~~~~~
prog.c:77:24: warning: passing argument 1 of ‘omp_unset_lock’ from incompatible pointer type [-Wincompatible-pointer-types]
         omp_unset_lock(&(arr[k + 1]));
                        ^
In file included from prog.c:3:0:
/usr/lib/gcc/x86_64-linux-gnu/6/include/omp.h:105:13: note: expected ‘omp_lock_t * {aka struct <anonymous> *}’ but argument is of type ‘int *’
 extern void omp_unset_lock (omp_lock_t *) __GOMP_NOTHROW;
             ^~~~~~~~~~~~~~
prog.c:79:22: warning: passing argument 1 of ‘omp_set_lock’ from incompatible pointer type [-Wincompatible-pointer-types]
         omp_set_lock(&(arr[k+ 1]));
                      ^
In file included from prog.c:3:0:
/usr/lib/gcc/x86_64-linux-gnu/6/include/omp.h:104:13: note: expected ‘omp_lock_t * {aka struct <anonymous> *}’ but argument is of type ‘int *’
 extern void omp_set_lock (omp_lock_t *) __GOMP_NOTHROW;
             ^~~~~~~~~~~~
prog.c:82:24: warning: passing argument 1 of ‘omp_unset_lock’ from incompatible pointer type [-Wincompatible-pointer-types]
         omp_unset_lock(&(arr[k + 1]));
                        ^
In file included from prog.c:3:0:
/usr/lib/gcc/x86_64-linux-gnu/6/include/omp.h:105:13: note: expected ‘omp_lock_t * {aka struct <anonymous> *}’ but argument is of type ‘int *’
 extern void omp_unset_lock (omp_lock_t *) __GOMP_NOTHROW;
             ^~~~~~~~~~~~~~
prog.c:84:22: warning: passing argument 1 of ‘omp_set_lock’ from incompatible pointer type [-Wincompatible-pointer-types]
         omp_set_lock(&(arr[k + 1]));
                      ^
In file included from prog.c:3:0:
/usr/lib/gcc/x86_64-linux-gnu/6/include/omp.h:104:13: note: expected ‘omp_lock_t * {aka struct <anonymous> *}’ but argument is of type ‘int *’
 extern void omp_set_lock (omp_lock_t *) __GOMP_NOTHROW;
             ^~~~~~~~~~~~
prog.c:87:24: warning: passing argument 1 of ‘omp_unset_lock’ from incompatible pointer type [-Wincompatible-pointer-types]
         omp_unset_lock(&(arr[k + 1]));
                        ^
In file included from prog.c:3:0:
/usr/lib/gcc/x86_64-linux-gnu/6/include/omp.h:105:13: note: expected ‘omp_lock_t * {aka struct <anonymous> *}’ but argument is of type ‘int *’
 extern void omp_unset_lock (omp_lock_t *) __GOMP_NOTHROW;
             ^~~~~~~~~~~~~~
prog.c:91:22: warning: passing argument 1 of ‘omp_unset_lock’ from incompatible pointer type [-Wincompatible-pointer-types]
       omp_unset_lock(&(arr[k]));
                      ^
In file included from prog.c:3:0:
/usr/lib/gcc/x86_64-linux-gnu/6/include/omp.h:105:13: note: expected ‘omp_lock_t * {aka struct <anonymous> *}’ but argument is of type ‘int *’
 extern void omp_unset_lock (omp_lock_t *) __GOMP_NOTHROW;
             ^~~~~~~~~~~~~~
/home/utUZEO/cc4MJ4Fs.o: In function `numero1':
prog.c:(.text+0x10): undefined reference to `omp_get_thread_num'
/home/utUZEO/cc4MJ4Fs.o: In function `numero2':
prog.c:(.text+0xf9): undefined reference to `omp_get_thread_num'
prog.c:(.text+0x133): undefined reference to `omp_unset_lock'
prog.c:(.text+0x160): undefined reference to `omp_set_lock'
prog.c:(.text+0x196): undefined reference to `omp_set_lock'
prog.c:(.text+0x1b4): undefined reference to `omp_unset_lock'
prog.c:(.text+0x1bc): undefined reference to `omp_set_lock'
prog.c:(.text+0x1d7): undefined reference to `omp_unset_lock'
prog.c:(.text+0x1df): undefined reference to `omp_set_lock'
prog.c:(.text+0x1ed): undefined reference to `omp_unset_lock'
/home/utUZEO/cc4MJ4Fs.o: In function `main':
prog.c:(.text.startup+0x89): undefined reference to `omp_init_lock'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty