File: ampi_test.cpp

package info (click to toggle)
simgrid 4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 38,980 kB
  • sloc: cpp: 123,583; ansic: 66,779; python: 8,358; java: 6,406; fortran: 6,079; f90: 5,123; xml: 4,587; sh: 2,337; perl: 1,436; makefile: 105; lisp: 49; javascript: 7; sed: 6
file content (47 lines) | stat: -rw-r--r-- 1,359 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* Copyright (c) 2009-2025. 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 <simgrid/s4u/Actor.hpp>
#include "smpi/smpi.h"
#include "smpi/sampi.h"

int main(int argc, char* argv[])
{
  MPI_Init(&argc, &argv);
  // useless alocations for testing and coverage
  void* pointer = malloc(100 * sizeof(int));
  void* ptmp;
  if ((ptmp = realloc(pointer, 50 * sizeof(int))) != nullptr)
    pointer = ptmp;
  if ((ptmp = realloc(pointer, 200 * sizeof(int))) != nullptr)
    pointer = ptmp;
  free(pointer);
  pointer = calloc(100, sizeof(int));
  int rank;
  /* Get id of this process */
  if (int err = MPI_Comm_rank(MPI_COMM_WORLD, &rank); err != MPI_SUCCESS) {
    fprintf(stderr, "MPI_Comm_rank failed: %d", err);
    MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
    exit(EXIT_FAILURE);
  }
  AMPI_Iteration_in(MPI_COMM_WORLD);
  simgrid::s4u::this_actor::sleep_for(rank);
  AMPI_Iteration_out(MPI_COMM_WORLD);

  AMPI_Iteration_in(MPI_COMM_WORLD);
  simgrid::s4u::this_actor::sleep_for(rank);
  AMPI_Iteration_out(MPI_COMM_WORLD);
  if (rank == 0) {
    free(pointer);
    pointer = nullptr;
  }
  AMPI_Migrate(MPI_COMM_WORLD);
  if (rank != 0)
    free(pointer);

  MPI_Finalize();
  return 0;
}