X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/40f9c3e861f4b651dc2dd63b79271e735931a1a7..b3b356352e87ae00a20f737c48e19b0c8413455a:/examples/smpi/energy/se.c diff --git a/examples/smpi/energy/se.c b/examples/smpi/energy/se.c index 6632e3d880..be95ba91ad 100644 --- a/examples/smpi/energy/se.c +++ b/examples/smpi/energy/se.c @@ -1,3 +1,9 @@ +/* Copyright (c) 2013-2015. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + #include #include #include @@ -10,13 +16,20 @@ int main(int argc, char *argv[]) char buf[1024]; char *s; size_t sz, x; + int err; - if (MPI_Init(&argc, &argv) != MPI_SUCCESS) { - printf("MPI initialization failed!\n"); + err = MPI_Init(&argc, &argv); + if (err != MPI_SUCCESS) { + fprintf(stderr, "MPI_init failed: %d\n", err); exit(EXIT_FAILURE); } - MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* Get id of this process */ + err = MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* Get id of this process */ + if (err != MPI_SUCCESS) { + fprintf(stderr, "MPI_Comm_rank failed: %d", err); + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); + exit(EXIT_FAILURE); + } pstates = smpi_get_host_nb_pstates(); @@ -38,20 +51,27 @@ int main(int argc, char *argv[]) } else sz = 0; } - printf("%s%s\n", buf, (sz ? "" : " [...]")); + fprintf(stderr, "%s%s\n", buf, (sz ? "" : " [...]")); for (i = 0; i < pstates; i++) { - smpi_set_host_power_peak_at(i); - printf("[%.6f] [rank %d] Current pstate: %d; Current power: %.0f\n", - MPI_Wtime(), rank, i, smpi_get_host_current_power_peak()); + smpi_set_host_pstate(i); + fprintf(stderr, "[%.6f] [rank %d] Current pstate: %d; Current power: %.0f\n", + MPI_Wtime(), rank, i, smpi_get_host_current_power_peak()); SMPI_SAMPLE_FLOPS(1e9) { /* imagine here some code running for 1e9 flops... */ } - printf("[%.6f] [rank %d] Energy consumed: %g Joules.\n", - MPI_Wtime(), rank, smpi_get_host_consumed_energy()); + fprintf(stderr, "[%.6f] [rank %d] Energy consumed: %g Joules.\n", + MPI_Wtime(), rank, smpi_get_host_consumed_energy()); + } + + err = MPI_Finalize(); + if (err != MPI_SUCCESS) { + fprintf(stderr, "MPI_Finalize failed: %d\n", err); + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); + exit(EXIT_FAILURE); } - return MPI_Finalize(); + return EXIT_SUCCESS; }