Commit 66e054d8 authored by Millian Poquet's avatar Millian Poquet

Some machine metadata are now stored. This is done to prepare the energy...

Some machine metadata are now stored. This is done to prepare the energy integration (in order to change a machine state, such a state must exist somewhere...). This will also allow to improve the Pajé trace generation in the future.
parent 3aa8afd9
......@@ -11,17 +11,17 @@ include(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG("-std=c11" COMPILER_SUPPORTS_C11)
CHECK_C_COMPILER_FLAG("-std=c99" COMPILER_SUPPORTS_C99)
if(COMPILER_SUPPORTS_C11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
elseif(COMPILER_SUPPORTS_C99)
message(STATUS "The compiler ${CMAKE_C_COMPILER} has no C11 support. Using C99 instead.")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
message(STATUS "The compiler ${CMAKE_C_COMPILER} has no C11 support. Using C99 instead.")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
else()
message(STATUS "The compiler ${CMAKE_C_COMPILER} has no C11 nor C99 support. Please update your C compiler.")
message(STATUS "The compiler ${CMAKE_C_COMPILER} has no C11 nor C99 support. Please update your C compiler.")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
add_executable(batsim batsim.c job.c utils.c export.c)
add_executable(batsim batsim.c job.c utils.c export.c machines.c)
add_executable(batexec batexec.c job.c utils.c export.c)
### Add definitions for compile
......
......@@ -29,6 +29,7 @@ XBT_LOG_NEW_CATEGORY(network, "Network");
#include "job.h"
#include "utils.h"
#include "export.h"
#include "machines.h"
//! The total number of microseconds used by the external scheduler
long long microseconds_used_by_scheduler = 0;
......@@ -279,6 +280,8 @@ static int launch_job(int argc, char *argv[])
pajeTracer_addJobLaunching(tracer, MSG_get_clock(), jobID, data->reservedNodeCount, data->reservedNodesIDs);
pajeTracer_addJobRunning(tracer, MSG_get_clock(), jobID, data->reservedNodeCount, data->reservedNodesIDs);
updateMachinesOnJobRun(jobID, data->reservedNodeCount, data->reservedNodesIDs);
if (job_exec(jobID, data->reservedNodeCount, data->reservedNodesIDs, nodes, job->walltime) == 1)
{
XBT_INFO("Job %d finished in time", data->jobID);
......@@ -295,6 +298,8 @@ static int launch_job(int argc, char *argv[])
job->runtime = MSG_get_clock() - job->startingTime;
updateMachinesOnJobEnd(jobID, data->reservedNodeCount, data->reservedNodesIDs);
//free(data->reservedNodesIDs);
free(data);
send_message("server", JOB_COMPLETED, jobID, NULL);
......@@ -701,6 +706,7 @@ msg_error_t deploy_all(const char *platform_file, const char * masterHostName, c
}
nb_nodes = xbt_dynar_length(all_hosts);
createMachines(all_hosts);
nodes = xbt_dynar_to_array(all_hosts);
XBT_INFO("Nb nodes: %d", nb_nodes);
......@@ -715,6 +721,7 @@ msg_error_t deploy_all(const char *platform_file, const char * masterHostName, c
msg_error_t res = MSG_main();
freeMachines();
pajeTracer_finalize(tracer, MSG_get_clock(), nb_nodes, nodes);
pajeTracer_destroy(&tracer);
......
#include "machines.h"
int nb_machines = 0;
Machine * machines = NULL;
void createMachines(xbt_dynar_t hosts)
{
xbt_assert(machines == NULL, "Bad call to createMachines(): machines already created");
nb_machines = xbt_dynar_length(hosts);
machines = xbt_new(Machine, nb_machines);
msg_host_t host;
unsigned int i;
xbt_dynar_foreach(hosts, i, host)
{
Machine * machine = &machines[i];
machine->host = host;
machine->jobs_being_computed = xbt_dynar_new(sizeof(int), NULL);
machine->state = MACHINE_STATE_IDLE;
}
}
void displayDynarOfIntegers(const xbt_dynar_t d)
{
unsigned int index;
int value;
unsigned int lastIndex = xbt_dynar_length(d) - 1;
printf("[");
xbt_dynar_foreach(d, index, value)
{
if (index == lastIndex)
printf("%d", value);
else
printf("%d,", value);
}
printf("]");
}
void displayMachine(int machineID, const Machine * machine)
{
static const char* machineStateToStr[] = {"MACHINE_STATE_SLEEPING",
"MACHINE_STATE_IDLE",
"MACHINE_STATE_COMPUTING"};
printf("Machine %d, state=%s, jobs=", machineID, machineStateToStr[machine->state]);
displayDynarOfIntegers(machine->jobs_being_computed);
printf("\n");
fflush(stdout);
}
void freeMachines()
{
if (machines != NULL)
{
for (int i = 0; i < nb_machines; ++i)
xbt_dynar_free(&(machines[i].jobs_being_computed));
free(machines);
machines = NULL;
}
}
void updateMachinesOnJobRun(int jobID, int nbUsedMachines, int *usedMachines)
{
for (int i = 0; i < nbUsedMachines; ++i)
{
int machineID = usedMachines[i];
Machine * machine = &machines[machineID];
machine->state = MACHINE_STATE_COMPUTING;
//displayMachine(machineID, machine);
// Let's update the jobs_being_computed data structure
// This structure contains sorted job IDs
unsigned long nbBeingComputedJobs = xbt_dynar_length(machine->jobs_being_computed);
int inserted = 0;
unsigned int j;
int job;
xbt_dynar_foreach(machine->jobs_being_computed, j, job)
{
if (job > jobID)
{
xbt_dynar_insert_at(machine->jobs_being_computed, j, &jobID);
//displayMachine(machineID, machine);
inserted = 1;
break;
}
}
if (!inserted)
{
xbt_dynar_push_as(machine->jobs_being_computed, int, jobID);
//displayMachine(machineID, machine);
}
xbt_assert(xbt_dynar_length(machine->jobs_being_computed) == nbBeingComputedJobs + 1);
xbt_assert(*((int*)xbt_dynar_get_ptr(machine->jobs_being_computed, j)) == jobID);
}
}
void updateMachinesOnJobEnd(int jobID, int nbUsedMachines, int *usedMachines)
{
for (int i = 0; i < nbUsedMachines; ++i)
{
int machineID = usedMachines[i];
Machine * machine = &machines[machineID];
//displayMachine(machineID, machine);
// Let's find where jobID is in the jobs_being_computed data structure
unsigned long nbBeingComputedJobs = xbt_dynar_length(machine->jobs_being_computed);
int found = 0;
unsigned int j;
int job;
xbt_dynar_foreach(machine->jobs_being_computed, j, job)
{
if (job == jobID)
{
xbt_dynar_remove_at(machine->jobs_being_computed, j, NULL);
//displayMachine(machineID, machine);
found = 1;
break;
}
}
xbt_assert(found == 1);
xbt_assert(xbt_dynar_length(machine->jobs_being_computed) == nbBeingComputedJobs - 1);
if (xbt_dynar_is_empty(machine->jobs_being_computed))
{
machine->state = MACHINE_STATE_IDLE;
// todo: handle the Pajé trace in this file, not directly in batsim.c
}
}
}
#pragma once
#include <simgrid/msg.h>
enum e_machine_state_t
{
MACHINE_STATE_SLEEPING,
MACHINE_STATE_IDLE,
MACHINE_STATE_COMPUTING,
};
typedef enum e_machine_state_t MachineState;
struct s_machine_t
{
msg_host_t host;
MachineState state;
xbt_dynar_t jobs_being_computed; // the IDs of the jobs being computed by the machine
};
typedef struct s_machine_t Machine;
// The array of machines
extern int nb_machines;
extern Machine* machines;
void createMachines(xbt_dynar_t hosts);
void freeMachines();
void updateMachinesOnJobRun(int jobID, int nbUsedMachines, int * usedMachines);
void updateMachinesOnJobEnd(int jobID, int nbUsedMachines, int * usedMachines);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment