malleabilityDataStructures.c 2.99 KB
Newer Older
1
2
#include "malleabilityDataStructures.h"

3
4
malleability_config_t *mall_conf = NULL;
malleability_t *mall = NULL;
5
int state = MALL_UNRESERVED;
6

7
8
9
10
11
/*
 * Crea un tipo derivado para mandar las dos estructuras principales
 * de MaM.
 */
void MAM_Def_main_datatype() {
12
  int i, counts = 11;
13
14
15
16
  int blocklengths[counts];
  MPI_Aint displs[counts];
  MPI_Datatype types[counts];

17
18
19
20
21
  for(i=0; i<5; i++) {
    blocklengths[i] = 1;
    types[i] = MPI_UNSIGNED;
  }
  for(i=5; i<counts; i++) {
22
23
24
25
    blocklengths[i] = 1;
    types[i] = MPI_INT;
  }

26
  // Obtain base direction
27
28
29
30
31
  MPI_Get_address(&(mall_conf->spawn_method), &displs[0]);
  MPI_Get_address(&(mall_conf->spawn_strategies), &displs[1]);
  MPI_Get_address(&(mall_conf->spawn_dist), &displs[2]);
  MPI_Get_address(&(mall_conf->red_method), &displs[3]);
  MPI_Get_address(&(mall_conf->red_strategies), &displs[4]);
32

iker_martin's avatar
iker_martin committed
33
  MPI_Get_address(&(mall->root_parents), &displs[5]);
34
35
36
37
38
  MPI_Get_address(&(mall->num_parents), &displs[6]); //TODO Add only when Single strat active?
  MPI_Get_address(&(mall->numC), &displs[7]); //TODO Add only when MultipleSpawn strat active?
  MPI_Get_address(&(mall->num_cpus), &displs[8]);
  MPI_Get_address(&(mall->num_nodes), &displs[9]);
  MPI_Get_address(&(mall->nodelist_len), &displs[10]);
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

  MPI_Type_create_struct(counts, blocklengths, displs, types, &mall->struct_type);
  MPI_Type_commit(&mall->struct_type);
}

void MAM_Free_main_datatype() {
  if(mall->struct_type != MPI_DATATYPE_NULL) {
    MPI_Type_free(&mall->struct_type);
  }
}

/*
 * Comunica datos necesarios de las estructuras
 * principales de MAM de sources a targets.
 */
54
void MAM_Comm_main_structures(MPI_Comm comm, int rootBcast) {
55

56
  MPI_Bcast(MPI_BOTTOM, 1, mall->struct_type, rootBcast, comm);
57

58
  if(mall->nodelist == NULL) {
59
    mall->nodelist = calloc(mall->nodelist_len+1, sizeof(char));
60
61
    mall->nodelist[mall->nodelist_len] = '\0';
  }
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
  MPI_Bcast(mall->nodelist, mall->nodelist_len, MPI_CHAR, rootBcast, comm);
}

/*
 * Muestra por pantalla el estado actual de todos los comunicadores
 */
void MAM_print_comms_state() {
  int tester;
  char *comm_name = malloc(MPI_MAX_OBJECT_NAME * sizeof(char));

  MPI_Comm_get_name(mall->comm, comm_name, &tester);
  printf("P%d Comm=%d Name=%s\n", mall->myId, mall->comm, comm_name);
  MPI_Comm_get_name(*(mall->user_comm), comm_name, &tester);
  printf("P%d Comm=%d Name=%s\n", mall->myId, *(mall->user_comm), comm_name);
  if(mall->intercomm != MPI_COMM_NULL) {
    MPI_Comm_get_name(mall->intercomm, comm_name, &tester);
    printf("P%d Comm=%d Name=%s\n", mall->myId, mall->intercomm, comm_name);
  }
  free(comm_name);
}

/*
 * Función para modificar los comunicadores principales de MaM
 */
void MAM_comms_update(MPI_Comm comm) {
87
88
  if(mall->thread_comm != MPI_COMM_WORLD) MPI_Comm_disconnect(&(mall->thread_comm));
  if(mall->comm != MPI_COMM_WORLD) MPI_Comm_disconnect(&(mall->comm));
89
90
91
92
93
94

  MPI_Comm_dup(comm, &(mall->thread_comm));
  MPI_Comm_dup(comm, &(mall->comm));

  MPI_Comm_set_name(mall->thread_comm, "MAM_THREAD");
  MPI_Comm_set_name(mall->comm, "MAM_MAIN");
95
}