1 /* Copyright (c) 2013-2018. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include <smpi/smpi.h>
12 #include <simgrid/host.h>
13 #include <simgrid/plugins/energy.h>
15 int main(int argc, char *argv[])
21 int err = MPI_Init(&argc, &argv);
22 if (err != MPI_SUCCESS) {
23 fprintf(stderr, "MPI_init failed: %d\n", err);
27 err = MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* Get id of this process */
28 if (err != MPI_SUCCESS) {
29 fprintf(stderr, "MPI_Comm_rank failed: %d", err);
30 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
34 int pstates = sg_host_get_nb_pstates(sg_host_self());
37 size_t sz = sizeof buf;
38 size_t x = snprintf(s, sz,
39 "[%.6f] [rank %d] Pstates: %d; Powers: %.0f",
40 MPI_Wtime(), rank, pstates, sg_host_get_pstate_speed(sg_host_self(), 0));
46 for (i = 1; i < pstates; i++) {
47 x = snprintf(s, sz, ", %.0f", sg_host_get_pstate_speed(sg_host_self(), i));
54 fprintf(stderr, "%s%s\n", buf, (sz ? "" : " [...]"));
56 for (i = 0; i < pstates; i++) {
57 sg_host_set_pstate(sg_host_self(), i);
58 fprintf(stderr, "[%.6f] [rank %d] Current pstate: %d; Current power: %.0f\n",
59 MPI_Wtime(), rank, i, sg_host_speed(sg_host_self()));
61 SMPI_SAMPLE_FLOPS(1e9) {
62 /* imagine here some code running for 1e9 flops... */
65 fprintf(stderr, "[%.6f] [rank %d] Energy consumed: %g Joules.\n",
66 MPI_Wtime(), rank, sg_host_get_consumed_energy(sg_host_self()));
70 if (err != MPI_SUCCESS) {
71 fprintf(stderr, "MPI_Finalize failed: %d\n", err);
72 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);