int main(int argc, char *argv[])
{
-
int size, rank;
int N;
struct timeval *start_time = NULL, *stop_time = NULL;
}
for (N = N_START; N <= N_STOP; N = N_NEXT) {
-
buffer = malloc(sizeof(char) * N);
if (0 == rank) {
MPI_Bcast(buffer, N, MPI_BYTE, 0, MPI_COMM_WORLD);
if (0 == rank) {
for (j = 1; j < size; j++) {
- MPI_Recv(&check, 1, MPI_INT, MPI_ANY_SOURCE, 1, MPI_COMM_WORLD,
- MPI_STATUS_IGNORE);
+ MPI_Recv(&check, 1, MPI_INT, MPI_ANY_SOURCE, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
}
} else {
MPI_Send(&rank, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
MPI_Abort(MPI_COMM_WORLD, GETTIMEOFDAY_ERROR);
exit(EXIT_FAILURE);
}
- seconds =
- (double) (stop_time->tv_sec - start_time->tv_sec) +
- (double) (stop_time->tv_usec -
- start_time->tv_usec) / ONE_MILLION;
+ seconds = (double) (stop_time->tv_sec - start_time->tv_sec) +
+ (double) (stop_time->tv_usec - start_time->tv_usec) / ONE_MILLION;
}
free(buffer);
if (0 == rank) {
- printf("N: %10d, iter: %d, time: %10f s, avg rate: %12f Mbps\n", N,
- ITER, seconds,
+ printf("N: %10d, iter: %d, time: %10f s, avg rate: %12f Mbps\n", N, ITER, seconds,
((double) N * ITER * 8) / (1024.0 * 1024.0 * seconds));
}
-
}
if (0 == rank) {
#include <stdlib.h>
#include <ctype.h>
#include <mpi.h>
-
#include <xbt/str.h>
#define ITERATIONS 10
-
#define USAGE_ERROR 1
#define SANITY_ERROR 2
#define GETTIMEOFDAY_ERROR 3
int main(int argc, char *argv[])
{
-
int size, rank;
int N, n, i, j, k, current_iteration, successful_iterations = 0;
double *matrix = NULL, *vector = NULL, *vcalc, *vcheck;
MPI_Status status;
struct timeval *start_time = NULL, *stop_time = NULL;
- long parallel_usecs, parallel_usecs_total =
- 0, sequential_usecs, sequential_usecs_total = 0;
+ long parallel_usecs, parallel_usecs_total = 0, sequential_usecs, sequential_usecs_total = 0;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (0 == rank) {
-
// root node parses cmdline args
if (2 > argc || !isdigit(*argv[1])) {
printf("usage:\n%s <size>\n", argv[0]);
start_time = (struct timeval *) malloc(sizeof(struct timeval));
stop_time = (struct timeval *) malloc(sizeof(struct timeval));
-
}
- for (current_iteration = 0; current_iteration < ITERATIONS;
- current_iteration++) {
-
+ for (current_iteration = 0; current_iteration < ITERATIONS; current_iteration++) {
if (0 == rank) {
-
matrix = (double *) malloc(N * N * sizeof(double));
vector = (double *) malloc(N * sizeof(double));
vector[i] = (double) rand() / ((double) RAND_MAX + 1);
}
- // for the sake of argument, the parallel algorithm begins
- // when the root node begins to transmit the matrix to the
+ // for the sake of argument, the parallel algorithm begins when the root node begins to transmit the matrix to the
// workers.
if (-1 == gettimeofday(start_time, NULL)) {
printf("couldn't set start_time on node 0!\n");
for (i = 1; i < size; i++) {
MPI_Send(&N, 1, MPI_INT, i, 0, MPI_COMM_WORLD);
}
-
} else {
MPI_Recv(&N, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
}
// this algorithm uses at most N processors...
if (rank < N) {
-
if (size > N)
size = N;
n = N / size + ((rank < (N % size)) ? 1 : 0);
if (0 == rank) {
-
for (i = 1, j = n; i < size && j < N; i++, j += k) {
k = N / size + ((i < (N % size)) ? 1 : 0);
- MPI_Send(matrix + N * j, N * k, MPI_DOUBLE, i, 0,
- MPI_COMM_WORLD);
+ MPI_Send(matrix + N * j, N * k, MPI_DOUBLE, i, 0, MPI_COMM_WORLD);
MPI_Send(vector, N, MPI_DOUBLE, i, 0, MPI_COMM_WORLD);
}
// sanity check
#ifdef DEBUG
if (i != size || j != N) {
- printf("index calc error: i = %d, size = %d, j = %d, N = %d\n",
- i, size, j, N);
+ printf("index calc error: i = %d, size = %d, j = %d, N = %d\n", i, size, j, N);
MPI_Abort(MPI_COMM_WORLD, SANITY_ERROR);
exit(SANITY_ERROR);
}
#endif
vcalc = (double *) malloc(N * sizeof(double));
-
} else {
-
matrix = (double *) malloc(N * n * sizeof(double));
vector = (double *) malloc(N * sizeof(double));
vcalc = (double *) malloc(n * sizeof(double));
MPI_Recv(matrix, N * n, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &status);
MPI_Recv(vector, N, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &status);
-
}
for (i = 0; i < n; i++) {
if (0 != rank) {
MPI_Send(vcalc, n, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD);
} else {
-
for (i = 1, j = n; i < size && j < N; i++, j += k) {
k = N / size + ((i < (N % size)) ? 1 : 0);
- MPI_Recv(vcalc + j, k, MPI_DOUBLE, i, 0, MPI_COMM_WORLD,
- &status);
+ MPI_Recv(vcalc + j, k, MPI_DOUBLE, i, 0, MPI_COMM_WORLD, &status);
}
// sanity check
#ifdef DEBUG
if (i != size || j != N) {
- printf("index calc error 2: i = %d, size = %d, j = %d, N = %d\n",
- i, size, j, N);
+ printf("index calc error 2: i = %d, size = %d, j = %d, N = %d\n", i, size, j, N);
MPI_Abort(MPI_COMM_WORLD, SANITY_ERROR);
exit(SANITY_ERROR);
}
exit(GETTIMEOFDAY_ERROR);
}
- parallel_usecs =
- (stop_time->tv_sec * 1000000 + stop_time->tv_usec) -
- (start_time->tv_sec * 1000000 + start_time->tv_usec);
+ parallel_usecs = (stop_time->tv_sec * 1000000 + stop_time->tv_usec) -
+ (start_time->tv_sec * 1000000 + start_time->tv_usec);
if (-1 == gettimeofday(start_time, NULL)) {
printf("couldn't set start_time on node 0!\n");
exit(GETTIMEOFDAY_ERROR);
}
- sequential_usecs =
- (stop_time->tv_sec * 1000000 + stop_time->tv_usec) -
- (start_time->tv_sec * 1000000 + start_time->tv_usec);
+ sequential_usecs = (stop_time->tv_sec * 1000000 + stop_time->tv_usec) -
+ (start_time->tv_sec * 1000000 + start_time->tv_usec);
// verify correctness
for (i = 0; i < N && vcalc[i] == vcheck[i]; i++);
printf("prog: blocking, i: %d ", current_iteration);
if (i == N) {
- printf
- ("ptime: %ld us, stime: %ld us, speedup: %.3f, nodes: %d, efficiency: %.3f\n",
- parallel_usecs, sequential_usecs,
- (double) sequential_usecs / (double) parallel_usecs, size,
- (double) sequential_usecs / ((double) parallel_usecs *
- (double) size));
+ printf("ptime: %ld us, stime: %ld us, speedup: %.3f, nodes: %d, efficiency: %.3f\n",
+ parallel_usecs, sequential_usecs, (double) sequential_usecs / (double) parallel_usecs, size,
+ (double) sequential_usecs / ((double) parallel_usecs * (double) size));
parallel_usecs_total += parallel_usecs;
sequential_usecs_total += sequential_usecs;
}
free(vcheck);
-
}
free(matrix);
free(vector);
free(vcalc);
}
-
}
if (0 == rank) {
printf("prog: blocking, ");
if (0 < successful_iterations) {
- printf
- ("iterations: %d, avg. ptime: %.3f us, avg. stime: %.3f us, avg. speedup: %.3f, nodes: %d, avg. efficiency: %.3f\n",
- successful_iterations,
- (double) parallel_usecs_total / (double) successful_iterations,
- (double) sequential_usecs_total /
- (double) successful_iterations,
- (double) sequential_usecs_total / (double) parallel_usecs_total,
- size,
- (double) sequential_usecs_total /
- ((double) parallel_usecs_total * (double) size));
+ printf("iterations: %d, avg. ptime: %.3f us, avg. stime: %.3f us, avg. speedup: %.3f, nodes: %d, avg. efficiency: %.3f\n",
+ successful_iterations, (double) parallel_usecs_total / (double) successful_iterations,
+ (double) sequential_usecs_total / (double) successful_iterations,
+ (double) sequential_usecs_total / (double) parallel_usecs_total, size,
+ (double) sequential_usecs_total / ((double) parallel_usecs_total * (double) size));
} else {
printf("no successful iterations!\n");
}
free(start_time);
free(stop_time);
-
}
MPI_Finalize();
/* 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 <stdio.h>
-#include "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
-#include "xbt/sysdep.h" /* calloc, printf */
+#include "simgrid/msg.h"
#include "mpi.h"
-/* Create a log channel to have nice outputs. */
-#include "xbt/log.h"
-#include "xbt/asserts.h"
-#include "smpi/smpi.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
- "Messages specific for this msg example");
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
static int smpi_replay(int argc, char *argv[]) {
smpi_replay_run(&argc, &argv);
int main(int argc, char *argv[]){
msg_error_t res;
- const char *platform_file;
- const char *application_file;
- const char *description_file;
MSG_init(&argc, argv);
- if (argc < 4) {
- printf("Usage: %s description_file platform_file deployment_file\n", argv[0]);
- printf("example: %s smpi_multiple_apps msg_platform.xml msg_deployment.xml\n", argv[0]);
- exit(1);
- }
- description_file = argv[1];
- platform_file = argv[2];
- application_file = argv[3];
-
+ xbt_assert(argc > 3, "Usage: %s description_file platform_file deployment_file\n"
+ "\tExample: %s smpi_multiple_apps msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
/* Simulation setting */
- MSG_create_environment(platform_file);
+ MSG_create_environment(argv[2]);
/* Application deployment: read the description file in order to identify instances to launch */
- FILE* fp = fopen(description_file, "r");
+ FILE* fp = fopen(argv[1], "r");
if (fp == NULL)
- xbt_die("Cannot open %s", description_file);
+ xbt_die("Cannot open %s", argv[1]);
ssize_t read;
char *line = NULL;
size_t n = 0;
xbt_free(line_char);
}
- MSG_launch_application(application_file);
+ MSG_launch_application(argv[3]);
SMPI_init();
res = MSG_main();
XBT_INFO("Simulation time %g", MSG_get_clock());
SMPI_finalize();
- if (res == MSG_OK)
- return 0;
- else
- return 1;
-
+ return res != MSG_OK;
}
/* 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 <stdio.h>
-#include "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
-#include "xbt/sysdep.h" /* calloc, printf */
+#include "simgrid/msg.h"
#include "mpi.h"
-/* Create a log channel to have nice outputs. */
-#include "xbt/log.h"
-#include "xbt/asserts.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
- "Messages specific for this msg example");
-
-int master(int argc, char *argv[]);
-int slave(int argc, char *argv[]);
-int master_mpi(int argc, char *argv[]);
-int alltoall_mpi(int argc, char *argv[]);
-
-/** sender function */
-int master(int argc, char *argv[])
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
+
+static int master(int argc, char *argv[])
{
long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
double task_comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");
sprintf(mailbox, "slave-%ld", i % slaves_count);
sprintf(sprintf_buffer, "Task_%d", i);
- task =
- MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size,
- NULL);
+ task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
if (number_of_tasks < 10000 || i % 10000 == 0)
- XBT_INFO("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name,
- number_of_tasks, mailbox);
+ XBT_INFO("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name, number_of_tasks, mailbox);
MSG_task_send(task, mailbox);
}
- XBT_INFO
- ("All tasks have been dispatched. Let's tell everybody the computation is over.");
+ XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over.");
for (i = 0; i < slaves_count; i++) {
char mailbox[80];
MSG_task_send(finalize, mailbox);
}
-// XBT_INFO("Goodbye now!");
return 0;
-} /* end_of_master */
-
+}
-int master_mpi(int argc, char *argv[])
+static int master_mpi(int argc, char *argv[])
{
MPI_Init(&argc, &argv);
XBT_INFO("here for rank %d", rank);
int test[1000]={rank};
if(rank==0)
- MPI_Send(&test, 1000,
- MPI_INT, 1, 1, MPI_COMM_WORLD);
+ MPI_Send(&test, 1000, MPI_INT, 1, 1, MPI_COMM_WORLD);
else
- MPI_Recv(&test, 1000,
- MPI_INT, 0, 1, MPI_COMM_WORLD, MPI_STATUSES_IGNORE);
+ MPI_Recv(&test, 1000, MPI_INT, 0, 1, MPI_COMM_WORLD, MPI_STATUSES_IGNORE);
XBT_INFO("After comm %d", rank);
MPI_Finalize();
XBT_INFO("After finalize %d %d", rank, test[0]);
return 0;
-} /* end_of_master */
-
+}
-
-int alltoall_mpi(int argc, char *argv[])
+static int alltoall_mpi(int argc, char *argv[])
{
MPI_Init(&argc, &argv);
free(in);
MPI_Finalize();
return 0;
-} /* end_of_master */
-
+}
-/** Receiver function */
-int slave(int argc, char *argv[])
+static int slave(int argc, char *argv[])
{
msg_task_t task = NULL;
XBT_ATTRIB_UNUSED int res;
XBT_INFO("I'm done. See you!");
return 0;
-} /* end_of_slave */
+}
-/** Main function */
int main(int argc, char *argv[])
{
msg_error_t res;
- const char *platform_file;
- const char *application_file;
MSG_init(&argc, argv);
- if (argc < 3) {
- printf("Usage: %s platform_file deployment_file\n", argv[0]);
- printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
- exit(1);
- }
- platform_file = argv[1];
- application_file = argv[2];
+ xbt_assert(argc > 2,"Usage: %s platform_file deployment_file\n"
+ "\nexample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
+
+ MSG_create_environment(argv[1]);
+
+ MSG_function_register("master", master);
+ MSG_function_register("slave", slave);
+ // launch two MPI applications as well, one using master_mpi function as main on 2 nodes
+ SMPI_app_instance_register("master_mpi", master_mpi,2);
+ // the second performing an alltoall on 4 nodes
+ SMPI_app_instance_register("alltoall_mpi", alltoall_mpi,4);
+ MSG_launch_application(argv[2]);
+ SMPI_init();
- { /* Simulation setting */
- MSG_create_environment(platform_file);
- }
- { /* Application deployment */
- MSG_function_register("master", master);
- MSG_function_register("slave", slave);
- // launch two MPI applications as well, one using master_mpi function as main on 2 nodes
- SMPI_app_instance_register("master_mpi", master_mpi,2);
- // the second performing an alltoall on 4 nodes
- SMPI_app_instance_register("alltoall_mpi", alltoall_mpi,4);
- MSG_launch_application(application_file);
- SMPI_init();
- }
res = MSG_main();
XBT_INFO("Simulation time %g", MSG_get_clock());
-
SMPI_finalize();
- if (res == MSG_OK)
- return 0;
- else
- return 1;
-} /* end_of_main */
+ return res != MSG_OK;
+}