malleabilityZombies.c 1.83 KB
Newer Older
iker_martin's avatar
iker_martin committed
1
2
3
4
5
6
7
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <mpi.h>
#include <signal.h>
8
#include "../IOcodes/results.h"
iker_martin's avatar
iker_martin committed
9
10
11
12
13
14
15
16
17
18
19
#include "malleabilityZombies.h"

#define PIDS_QTY 320

void zombies_suspend();

int offset_pids, *pids = NULL;


void gestor_usr2() {}

20
void zombies_collect_suspended(MPI_Comm comm, int myId, int numP, int numC, int root, void *results_void, size_t n_stages, int capture_method) {
iker_martin's avatar
iker_martin committed
21
  int pid = getpid();
22
23
  int *pids_counts = malloc(numP * sizeof(int));
  int *pids_displs = malloc(numP * sizeof(int));
iker_martin's avatar
iker_martin committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  int i, count=1;

  if(myId < numC) {
    count = 0;
    if(myId == root) {
      for(i=0; i < numC; i++) {
	pids_counts[i] = 0;
      }
      for(i=numC; i<numP; i++) {
  	pids_counts[i] = 1;
	pids_displs[i] = (i + offset_pids) - numC;
      }
      offset_pids += numP - numC;
      }
  }
  MPI_Gatherv(&pid, count, MPI_INT, pids, pids_counts, pids_displs, MPI_INT, root, comm);
  free(pids_counts);
  free(pids_displs);

  if(myId >= numC) {
44
45
46
    // FIXME No deberia estar aqui
    // Needed to ensure iteration times are collected before suspending these processes
    results_data *results = (results_data *) results_void;
47
    compute_results_iter(results, myId, numP, root, n_stages, capture_method, comm); 
iker_martin's avatar
iker_martin committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
    zombies_suspend();
  }
}

void zombies_service_init() {
  offset_pids = 0;
  pids = malloc(PIDS_QTY * sizeof(int));

  for(int i=0; i<PIDS_QTY; i++) {
    pids[i] = 0;
  }
}

void zombies_service_free() {
  free(pids);
}

void zombies_suspend() {
  struct sigaction act;

  sigemptyset(&act.sa_mask);
  act.sa_flags=0;
  act.sa_handler=gestor_usr2;

  sigaction(SIGUSR2, &act, NULL);

  sigset_t set;
  sigprocmask(SIG_SETMASK,NULL,&set);

  sigsuspend(&set);
}

void zombies_awake() {
  for(int i=0; i < offset_pids; i++) { // Despertar a los zombies
    kill(pids[i], SIGUSR2);
  }
}