Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix prototype declaration for gtnets compilation
[simgrid.git] / examples / smpi / ttest01.c
1 /* Copyright (c) 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "mpi.h"
8 #include <stdio.h>
9 #include "instr/instr.h"
10
11 #define DATATOSENT 100000000
12
13 int main(int argc, char *argv[])
14 {
15   MPI_Status status;
16   int rank, numprocs, tag = 0;
17   int *r = malloc(sizeof(int) * DATATOSENT);
18
19   MPI_Init(&argc, &argv);
20   MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
21   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
22
23
24   int i;
25   for (i = 0; i < 10; i++) {
26     TRACE_smpi_set_category("A");
27     if (rank == 0) {
28       MPI_Send(r, DATATOSENT, MPI_INT, 1, tag, MPI_COMM_WORLD);
29     } else if (rank == 1) {
30       MPI_Recv(r, DATATOSENT, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
31     } else {
32       //do nothing
33     }
34
35     TRACE_smpi_set_category("B");
36     if (rank == 0) {
37       MPI_Recv(r, DATATOSENT, MPI_INT, 1, tag, MPI_COMM_WORLD, &status);
38     } else if (rank == 1) {
39       MPI_Send(r, DATATOSENT, MPI_INT, 0, tag, MPI_COMM_WORLD);
40     } else {
41       //do nothing
42     }
43   }
44   TRACE_smpi_set_category("C");
45   MPI_Barrier(MPI_COMM_WORLD);
46   MPI_Finalize();
47   return 0;
48 }