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

#define PIDS_QTY 320

void zombies_suspend();

int offset_pids, *pids = NULL;


void gestor_usr2() {}

21
void zombies_collect_suspended(MPI_Comm comm, int myId, int numP, int numC, int root, void *results_void) {
iker_martin's avatar
iker_martin committed
22
  int pid = getpid();
23
24
  int *pids_counts = malloc((size_t)numP * sizeof(int));
  int *pids_displs = malloc((size_t)numP * sizeof(int));
iker_martin's avatar
iker_martin committed
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);

44
45
46
47
48
  // FIXME No deberia estar aqui
  // Needed to ensure iteration times are collected before suspending these processes
  results_data *results = (results_data *) results_void;
  compute_results_iter(results, myId, root, comm); 

iker_martin's avatar
iker_martin committed
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
85
86
  if(myId >= numC) {
    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);
  }
}