Skip to content

Instantly share code, notes, and snippets.

@printesoi
Created November 2, 2012 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save printesoi/4002876 to your computer and use it in GitHub Desktop.
Save printesoi/4002876 to your computer and use it in GitHub Desktop.
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment