35 for (i = 0; i < count - 1; i++) {
38 while (j != -1 && tmp < indices[j]) {
39 indices[j + 1] = indices[j];
64 while ((i <= right) && (indices[i] <= key)) i++;
65 while ((j > left) && (indices[j] > key)) j--;
68 indices[i] = indices[j];
75 indices[left] = indices[j];
90 for (i = (count - 1); i > 0; i--) {
91 for (j = 1; j <= i; j++) {
92 if (indices[j - 1] > indices[j]) {
94 indices[j - 1] = indices[j];
117 for (i = 1; i < count; i++) {
118 if (indices[i] > max) {
121 if (indices[i] < min) min = indices[i];
124 buf = (
int *) calloc(max - min + 1,
sizeof(
int));
125 for (i = 0; i < count; i++) { buf[indices[i] - min] = 1; }
127 for (i = 0; i < (max - min + 1); i++) {
129 indices[j] = min + i;
143 for (m = n / 2; m > 0; m /= 2) {
144 for (j = m; j < n; j++) {
145 for (i = j - m; i >= 0; i -= m) {
146 if (a[i + m] >= a[i])
break;
172 int ssort(
int *indices,
int count,
int flag) {
195 for (i = 0; i < count - 1; i++) {
197 if (*ptr_i != *ptr_o) {
220 #pragma omp parallel shared(nths)
222 nths = omp_get_num_threads();
230 count = (
int *) malloc(nths *
sizeof(
int));
231 disp = (
int *) malloc(nths *
sizeof(
int));
233 for (i = 0; i < nths; i++) {
235 if (i < l) count[i] += PAGE;
236 if (i == l) count[i] += r;
240 for (i = 0; i < nths - 1; i++) { disp[i + 1] = disp[i] + count[i]; }
242 #pragma omp parallel private(tid, n, k, d, buf) shared(nths, A, nA, disp, count)
244 tid = omp_get_thread_num();
246 buf = (
int *) malloc(nA *
sizeof(
int));
248 memcpy(buf, A + disp[tid], count[tid] *
sizeof(
int));
250 n =
ssort(buf, count[tid], flag);
253 memcpy(A + disp[tid], buf, n *
sizeof(
int));
255 nths = omp_get_num_threads();
262 if (tid % (2 * d) == 0 && tid + d < nths) {
263 set_or(A + disp[tid], count[tid], A + disp[tid + d],
264 count[tid + d], buf);
266 memcpy(A + disp[tid], buf, n *
sizeof(
int));
311 #pragma omp parallel private(tid) shared(nths)
313 nths = omp_get_num_threads();
319 count = (
int *) malloc(nths *
sizeof(
int));
320 disp = (
int *) malloc(nths *
sizeof(
int));
322 for (i = 0; i < nths; i++) {
331 for (i = 0; i < nths - 1; i++) { disp[i + 1] = disp[i] + count[i]; }
333 #pragma omp parallel private(tid, n) shared(A, disp, count)
335 tid = omp_get_thread_num();
336 n =
ssort(A + disp[tid], count[tid], flag);
340 buf = (
int *) malloc(nA *
sizeof(
int));
342 #pragma omp parallel private(tid, n, k, d) shared(nths, nA, A, disp, count, buf)
344 tid = omp_get_thread_num();
345 nths = omp_get_num_threads();
349 if (tid % (2 * d) == 0 && tid + d < nths) {
352 n =
card_or(A + disp[tid], count[tid], A + disp[tid + d],
354 set_or(A + disp[tid], count[tid], A + disp[tid + d],
355 count[tid + d], buf + disp[tid]);
357 memcpy(A + disp[tid], buf + disp[tid], n *
sizeof(
int));
378 while (i < count - 2) {
379 if (indices[i] > indices[i + 1]) {
390 while (i < count - 2) {
391 if (indices[i] >= indices[i + 1]) {
int set_or(int *A1, int n1, int *A2, int n2, int *A1orA2)
int card_or(int *A1, int n1, int *A2, int n2)
int ssort(int *indices, int count, int flag)
int omp_psort(int *A, int nA, int flag)
int omp_psort_opt(int *A, int nA, int flag)
int counting_sort(int *indices, int count)
int sorted(int *indices, int count)
void shell_sort(int *a, int n)
int monotony(int *indices, int count)
void insertion_sort(int *indices, int count)
void quick_sort(int *indices, int left, int right)
void bubble_sort(int *indices, int count)