Instantly share code, notes, and snippets.

# printesoi/parallel.c Created Nov 2, 2012

What would you like to do?
 for (t = 0; t < iteratii; ++t) { n_res0 = n_res1 = 0; p_res0 = p_res1 = 0; // pentru fiecare negustor #pragma omp parallel for private(i, j, _c, _v, k, l) schedule(dynamic) for (i = 0; i < n; ++i) { for (j = 0; j < n; ++j) { // calculele _c = pMax; _v = pMax; for (k = 0; k < n; ++k) { for (l = 0; l < n; ++l) { if (res[i][j] != res[k][l]) { // resursa complementara _c = min(_c, pret[k][l] + dist(i, j, k, l)); } else { // aceeasi resursa _v = min(_v, pret[k][l] + dist(i, j, k, l)); } } } cmin[i][j] = _c; cmin_res[i][j] = _v; } } #pragma omp parallel for private(i, j) schedule(dynamic) for (i = 0; i < n; ++i) { for (j = 0; j < n; ++j) { // Actualizare preturi si bugete pentru anul urmator if (cmin[i][j] < buget[i][j]) { pret[i][j] += (cmin[i][j] - buget[i][j]) / 2; buget[i][j] = cmin[i][j]; pret[i][j] = max(pret[i][j], pMin); } else { if (cmin[i][j] > buget[i][j]) { pret[i][j] += (cmin[i][j] - buget[i][j]); buget[i][j] = cmin[i][j]; } else { buget[i][j] = cmin[i][j]; pret[i][j] = cmin_res[i][j] + 1; } if (pret[i][j] > pMax) { res[i][j] = 1 - res[i][j]; buget[i][j] = pMax; pret[i][j] = (pMin + pMax) / 2; } } if (res[i][j]) { #pragma omp critical { n_res1++; p_res1 = max(p_res1, pret[i][j]); } } else { #pragma omp critical { n_res0++; p_res0 = max(p_res0, pret[i][j]); } } } } fprintf(out, "%d %d %d %d\n", n_res0, p_res0, n_res1, p_res1); }