#include #include #include #include #define N 25000 int main (int argc, char *argv[]) { // int *a; int a[N]; int i,j,tmp; double start,end; if (argc < 2) { printf("Usage omp_bubble.exe \n"); exit(0); } if (!omp_get_dynamic()) { //Set the number of threads omp_set_num_threads(atoi(argv[1])); } else { printf("ERROR: set OMP_DYNAMIC=FALSE\n"); exit(0); } //a = (int *) malloc(N * sizeof(int)); printf("Unsorted\n"); // j=0; // for (i=N; i>0; i--) { a[j] = i; printf("%d\n",a[j]); j++; } start = omp_get_wtime(); #pragma omp parallel for for (i=0; i a[j+1]) { tmp = a[j+1]; a[j+1] = a[j]; a[j] = tmp; } #pragma omp parallel for schedule(runtime) for(j=1; j<(N-1); j+=2) if (a[j] > a[j+1]) { tmp = a[j+1]; a[j+1] = a[j]; a[j] = tmp; } } end = omp_get_wtime(); printf("\nSorted\n"); for (i=0; i