Skip to content

Commit

Permalink
Use PETSc format specifier for printing PetscInts to support 64bit in…
Browse files Browse the repository at this point in the history
…dices
  • Loading branch information
nilsfriess committed Sep 20, 2024
1 parent 37b105f commit 66d0307
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 25 deletions.
6 changes: 3 additions & 3 deletions examples/benchmark/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ static PetscErrorCode InfoView(Mat A, Parameters params, PetscViewer viewer)

PetscCall(PetscViewerASCIIPrintf(viewer, "\n"));
PetscCall(MatGetSize(A, &n, nullptr));
PetscCall(PetscViewerASCIIPrintf(viewer, "Problem size (degrees of freedom): %d\n\n", n));
PetscCall(PetscViewerASCIIPrintf(viewer, "Problem size (degrees of freedom): %" PetscInt_FMT "\n\n", n));
PetscCall(MPI_Comm_size(MPI_COMM_WORLD, &size));
PetscCall(PetscViewerASCIIPrintf(viewer, "Running on %d MPI ranks\n\n", size));
PetscCall(PetscViewerASCIIPrintf(viewer, "Running on %" PetscInt_FMT " MPI ranks\n\n", size));

PetscCall(PetscOptionsView(nullptr, viewer));
PetscFunctionReturn(PETSC_SUCCESS);
Expand Down Expand Up @@ -275,7 +275,7 @@ int main(int argc, char *argv[])

PetscCall(PetscOptionsGetBool(nullptr, nullptr, "-print_acf", &print_acf, nullptr));
PetscCall(IACT(params->n_samples, ctx->qois, &tau, print_acf ? &acf : nullptr, &valid));
if (!valid) PetscCall(PetscPrintf(MPI_COMM_WORLD, "WARNING: Chain is too short to give reliable IACT estimate (need at least %d)\n", (int)ceil(500 * tau)));
if (!valid) PetscCall(PetscPrintf(MPI_COMM_WORLD, "WARNING: Chain is too short to give reliable IACT estimate (need at least %" PetscInt_FMT ")\n", (int)ceil(500 * tau)));
PetscCall(PetscPrintf(MPI_COMM_WORLD, "IACT: %.5f\n", tau));
PetscCall(PetscPrintf(MPI_COMM_WORLD, "Time per independent sample [ms]: %.6f\n\n", PetscMax(tau, 1) * time / params->n_samples * 1000));
if (print_acf) {
Expand Down
4 changes: 2 additions & 2 deletions examples/benchmark/params.hh
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ inline PetscErrorCode ParametersView(Parameters params, PetscViewer viewer)
PetscCheck(viewer == PETSC_VIEWER_STDOUT_WORLD || viewer == PETSC_VIEWER_STDOUT_SELF, MPI_COMM_WORLD, PETSC_ERR_SUP, "Viewer not supported");

PetscCall(PetscViewerASCIIPrintf(viewer, "Number of samples\n"));
PetscCall(PetscViewerASCIIPrintf(viewer, "\t Burn-in: %d\n", params->n_burnin));
PetscCall(PetscViewerASCIIPrintf(viewer, "\t Actual: %d\n", params->n_samples));
PetscCall(PetscViewerASCIIPrintf(viewer, "\t Burn-in: %" PetscInt_FMT "\n", params->n_burnin));
PetscCall(PetscViewerASCIIPrintf(viewer, "\t Actual: %" PetscInt_FMT "\n", params->n_samples));

PetscFunctionReturn(PETSC_SUCCESS);
}
12 changes: 6 additions & 6 deletions examples/benchmark/problem_mfem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ public:
nobs_given = nobs * cdim;
PetscCallVoid(PetscMalloc1(nobs_given, &obs_coords));
PetscCallVoid(PetscOptionsGetRealArray(nullptr, nullptr, "-obs_coords", obs_coords, &nobs_given, nullptr));
PetscCheckAbort(nobs_given == nobs * cdim, MPI_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Wrong number of observation coordinates provided, expected %d got %d", nobs * cdim, nobs_given);
PetscCheckAbort(nobs_given == nobs * cdim, MPI_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Wrong number of observation coordinates provided, expected %" PetscInt_FMT " got %" PetscInt_FMT, nobs * cdim, nobs_given);

PetscCallVoid(PetscMalloc1(nobs, &obs_radii));
nobs_given = nobs;
PetscCallVoid(PetscOptionsGetRealArray(nullptr, nullptr, "-obs_radii", obs_radii, &nobs_given, nullptr));
PetscCheckAbort(nobs_given == 1 || nobs_given == nobs, MPI_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Wrong number of observation radii provided, expected either 1 or `nobs` got %d", nobs_given);
PetscCheckAbort(nobs_given == 1 || nobs_given == nobs, MPI_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Wrong number of observation radii provided, expected either 1 or `nobs` got %" PetscInt_FMT, nobs_given);
if (nobs_given == 1)
for (PetscInt i = 1; i < nobs; ++i) obs_radii[i] = obs_radii[0]; // If only one radius provided, use that for all observations

PetscCallVoid(PetscMalloc1(nobs, &obs_values));
nobs_given = nobs;
PetscCallVoid(PetscOptionsGetRealArray(nullptr, nullptr, "-obs_values", obs_values, &nobs_given, nullptr));
PetscCheckAbort(nobs_given == 1 || nobs_given == nobs, MPI_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Wrong number of observation values provided, expected either 1 or `nobs` got %d", nobs_given);
PetscCheckAbort(nobs_given == 1 || nobs_given == nobs, MPI_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Wrong number of observation values provided, expected either 1 or `nobs` got %" PetscInt_FMT, nobs_given);
if (nobs_given == 1)
for (PetscInt i = 1; i < nobs; ++i) obs_values[i] = obs_values[0]; // If only one value provided, use that for all observations

Expand Down Expand Up @@ -217,7 +217,7 @@ private:
PetscInt got_dim = mesh->Dimension();
PetscCall(PetscCalloc1(got_dim, &centre_data));
PetscCall(PetscOptionsGetRealArray(nullptr, nullptr, "-qoi_centre", centre_data, &got_dim, nullptr));
PetscCheckAbort(got_dim == 0 or got_dim == mesh->Dimension(), MPI_COMM_WORLD, PETSC_ERR_SUP, "Incorrect number of points passed, expected %d", mesh->Dimension());
PetscCheckAbort(got_dim == 0 or got_dim == mesh->Dimension(), MPI_COMM_WORLD, PETSC_ERR_SUP, "Incorrect number of points passed, expected %" PetscInt_FMT, mesh->Dimension());
centre.SetData(centre_data);

PetscCall(PetscOptionsGetReal(nullptr, nullptr, "-qoi_radius", &radius, nullptr));
Expand All @@ -230,10 +230,10 @@ private:
for (PetscInt i = 0; i < got_dim; ++i) end_data[i] = 1;

PetscCall(PetscOptionsGetRealArray(nullptr, nullptr, "-qoi_start", start_data, &got_dim, nullptr));
PetscCheckAbort(got_dim == 0 or got_dim == mesh->Dimension(), MPI_COMM_WORLD, PETSC_ERR_SUP, "Incorrect number of points passed for start, expected %d", mesh->Dimension());
PetscCheckAbort(got_dim == 0 or got_dim == mesh->Dimension(), MPI_COMM_WORLD, PETSC_ERR_SUP, "Incorrect number of points passed for start, expected %" PetscInt_FMT, mesh->Dimension());
got_dim = mesh->Dimension();
PetscCall(PetscOptionsGetRealArray(nullptr, nullptr, "-qoi_end", end_data, &got_dim, nullptr));
PetscCheckAbort(got_dim == 0 or got_dim == mesh->Dimension(), MPI_COMM_WORLD, PETSC_ERR_SUP, "Incorrect number of points passed for end, expected %d", mesh->Dimension());
PetscCheckAbort(got_dim == 0 or got_dim == mesh->Dimension(), MPI_COMM_WORLD, PETSC_ERR_SUP, "Incorrect number of points passed for end, expected %" PetscInt_FMT, mesh->Dimension());

start.SetData(start_data);
end.SetData(end_data);
Expand Down
12 changes: 6 additions & 6 deletions examples/benchmark/problem_petsc.hh
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,19 @@ public:
nobs_given = nobs * cdim;
PetscCallVoid(PetscMalloc1(nobs_given, &obs_coords));
PetscCallVoid(PetscOptionsGetRealArray(nullptr, nullptr, "-obs_coords", obs_coords, &nobs_given, nullptr));
PetscCheckAbort(nobs_given == nobs * cdim, MPI_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Wrong number of observation coordinates provided, expected %d got %d", nobs * cdim, nobs_given);
PetscCheckAbort(nobs_given == nobs * cdim, MPI_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Wrong number of observation coordinates provided, expected %" PetscInt_FMT " got %" PetscInt_FMT, nobs * cdim, nobs_given);

PetscCallVoid(PetscMalloc1(nobs, &obs_radii));
nobs_given = nobs;
PetscCallVoid(PetscOptionsGetRealArray(nullptr, nullptr, "-obs_radii", obs_radii, &nobs_given, nullptr));
PetscCheckAbort(nobs_given == 1 || nobs_given == nobs, MPI_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Wrong number of observation radii provided, expected either 1 or `nobs` got %d", nobs_given);
PetscCheckAbort(nobs_given == 1 || nobs_given == nobs, MPI_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Wrong number of observation radii provided, expected either 1 or `nobs` got %" PetscInt_FMT, nobs_given);
if (nobs_given == 1)
for (PetscInt i = 1; i < nobs; ++i) obs_radii[i] = obs_radii[0]; // If only one radius provided, use that for all observations

PetscCallVoid(PetscMalloc1(nobs, &obs_values));
nobs_given = nobs;
PetscCallVoid(PetscOptionsGetRealArray(nullptr, nullptr, "-obs_values", obs_values, &nobs_given, nullptr));
PetscCheckAbort(nobs_given == 1 || nobs_given == nobs, MPI_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Wrong number of observation values provided, expected either 1 or `nobs` got %d", nobs_given);
PetscCheckAbort(nobs_given == 1 || nobs_given == nobs, MPI_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Wrong number of observation values provided, expected either 1 or `nobs` got %" PetscInt_FMT, nobs_given);
if (nobs_given == 1)
for (PetscInt i = 1; i < nobs; ++i) obs_values[i] = obs_values[0]; // If only one value provided, use that for all observations

Expand Down Expand Up @@ -246,7 +246,7 @@ private:
PetscCall(PetscCalloc1(dim, &ctx.centre));
got_dim = dim;
PetscCall(PetscOptionsGetRealArray(nullptr, nullptr, "-qoi_centre", ctx.centre, &got_dim, nullptr));
PetscCheck(got_dim == 0 or got_dim == dim, MPI_COMM_WORLD, PETSC_ERR_SUP, "Incorrect number of points passed, expected %d", dim);
PetscCheck(got_dim == 0 or got_dim == dim, MPI_COMM_WORLD, PETSC_ERR_SUP, "Incorrect number of points passed, expected %" PetscInt_FMT, dim);
ctx.radius = 1;
PetscCall(PetscOptionsGetReal(nullptr, nullptr, "-qoi_radius", &ctx.radius, nullptr));
PetscCall(VolumeOfSphere(dm, ctx.radius, &ctx.vol));
Expand All @@ -258,10 +258,10 @@ private:
for (PetscInt i = 0; i < dim; ++i) ctx.end[i] = 1;
got_dim = dim;
PetscCall(PetscOptionsGetRealArray(nullptr, nullptr, "-qoi_start", ctx.start, &got_dim, nullptr));
PetscCheck(got_dim == 0 or got_dim == dim, MPI_COMM_WORLD, PETSC_ERR_SUP, "Incorrect number of points passed for start, expected %d", dim);
PetscCheck(got_dim == 0 or got_dim == dim, MPI_COMM_WORLD, PETSC_ERR_SUP, "Incorrect number of points passed for start, expected %" PetscInt_FMT, dim);
got_dim = dim;
PetscCall(PetscOptionsGetRealArray(nullptr, nullptr, "-qoi_end", ctx.end, &got_dim, nullptr));
PetscCheck(got_dim == 0 or got_dim == dim, MPI_COMM_WORLD, PETSC_ERR_SUP, "Incorrect number of points passed for end, expected %d", dim);
PetscCheck(got_dim == 0 or got_dim == dim, MPI_COMM_WORLD, PETSC_ERR_SUP, "Incorrect number of points passed for end, expected %" PetscInt_FMT, dim);
PetscCall(VolumeOfRect(dm, ctx.start, ctx.end, &ctx.vol));

funcs[0] = f_rect;
Expand Down
3 changes: 1 addition & 2 deletions examples/ex6.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
per chain, it requires about ~12 GB).
*/


#include "parmgmc/parmgmc.h"
#include "parmgmc/stats.h"

Expand Down Expand Up @@ -149,7 +148,7 @@ int main(int argc, char *argv[])
PetscCall(AssembleMatrix(&A));
PetscCall(MatCreateVecs(A, &b, NULL));
PetscCall(MatGetSize(A, &n, NULL));
PetscCall(PetscPrintf(MPI_COMM_WORLD, "Degrees of freedom: %d\n", n));
PetscCall(PetscPrintf(MPI_COMM_WORLD, "Degrees of freedom: %" PetscInt_FMT "\n", n));

PetscCall(PetscOptionsGetInt(NULL, NULL, "-seed", &seed, NULL));
PetscCall(PetscOptionsGetInt(NULL, NULL, "-chains", &chains, NULL));
Expand Down
4 changes: 2 additions & 2 deletions examples/ex7.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int main(int argc, char *argv[])
PetscCall(MSGetPrecisionMatrix(ms, &A));
PetscCall(MatGetSize(A, &n, NULL));
PetscCall(MatGetInfo(A, MAT_GLOBAL_SUM, &info));
PetscCall(PetscPrintf(MPI_COMM_WORLD, "Degrees of freedom: %d (nnz %.0f)\n", n, info.nz_used));
PetscCall(PetscPrintf(MPI_COMM_WORLD, "Degrees of freedom: %" PetscInt_FMT " (nnz %.0f)\n", n, info.nz_used));

PetscCallMPI(MPI_Comm_rank(MPI_COMM_WORLD, &rank));
PetscCall(PetscRandomCreate(MPI_COMM_WORLD, &pr));
Expand Down Expand Up @@ -204,7 +204,7 @@ int main(int argc, char *argv[])

elapsed += MPI_Wtime() - start;
PetscCall(GelmanRubin(chains, i + check_every, ctx->qois, &gr));
PetscCall(PetscPrintf(MPI_COMM_WORLD, "Gelman-Rubin (%d samples, %.5fs): %.5f\n", i + check_every, elapsed, gr));
PetscCall(PetscPrintf(MPI_COMM_WORLD, "Gelman-Rubin (%" PetscInt_FMT " samples, %.5fs): %.5f\n", i + check_every, elapsed, gr));
times[i / check_every] = elapsed;
grs[i / check_every] = gr;

Expand Down
6 changes: 3 additions & 3 deletions examples/ex8.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ int main(int argc, char *argv[])
snprintf(buffer, sizeof buffer, "%f", range_threshold_scale[j]);
PetscCall(PetscOptionsSetValue(NULL, "-pc_gamg_threshold_scale", buffer));

snprintf(buffer, sizeof buffer, "%d", k);
snprintf(buffer, sizeof buffer, "%" PetscInt_FMT, k);
PetscCall(PetscOptionsSetValue(NULL, "-pc_gamg_aggressive_coarsening", buffer));

snprintf(buffer, sizeof buffer, "%d", m);
snprintf(buffer, sizeof buffer, "%" PetscInt_FMT, m);
PetscCall(PetscOptionsSetValue(NULL, "-pc_gamg_agg_nsmooths", buffer));

PetscCall(KSPCreate(MPI_COMM_WORLD, &ksp));
Expand All @@ -113,7 +113,7 @@ int main(int argc, char *argv[])
start = MPI_Wtime();
PetscCall(KSPSolve(ksp, b, x));
end = MPI_Wtime();
PetscCall(PetscPrintf(MPI_COMM_WORLD, "Agg. nsmooth %d, Agg. Coarsening %d, Threshold %.5f, Scale %.5f: %.6f\n", m, k, range_threshold[i], range_threshold_scale[j], (end - start) * 1000));
PetscCall(PetscPrintf(MPI_COMM_WORLD, "Agg. nsmooth %" PetscInt_FMT ", Agg. Coarsening %" PetscInt_FMT ", Threshold %.5f, Scale %.5f: %.6f\n", m, k, range_threshold[i], range_threshold_scale[j], (end - start) * 1000));

if (end - start < min_time) {
min_time = end - start;
Expand Down
2 changes: 1 addition & 1 deletion src/pc_gibbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ static PetscErrorCode PCView_Gibbs(PC pc, PetscViewer viewer)

PetscFunctionBeginUser;
PetscCall(MCSORGetNumColors(pg->mc, &ncolors));
PetscCall(PetscViewerASCIIPrintf(viewer, "Number of colours: %d\n", ncolors));
PetscCall(PetscViewerASCIIPrintf(viewer, "Number of colours: %" PetscInt_FMT "\n", ncolors));
PetscFunctionReturn(PETSC_SUCCESS);
}

Expand Down

0 comments on commit 66d0307

Please sign in to comment.