Download h source code

/*
 * Copyright 2021 Jeisson Hidalgo-Cespedes - Universidad de Costa Rica
 */

#ifndef DYNAMIC_SIMULATION_H
#define DYNAMIC_SIMULATION_H

#include <semaphore.h>
#include <time.h>

#include "simulation.h"
#include "queue.h"

typedef struct {
  simulation_t* simulation;
  data_t* durations;  // conditional safe
  struct timespec start_time;

  queue_t work_queue;
  sem_t can_work;
} dynamic_simulation_t;

int dynamic_simulation_init(dynamic_simulation_t* dynamic_simulation
  , simulation_t* simulation);
void dynamic_simulation_destroy(dynamic_simulation_t* dynamic_simulation);
int dynamic_simulation_run(dynamic_simulation_t* dynamic_simulation);

size_t calculate_block_start(size_t rank, size_t work_count
  , size_t worker_count);
size_t calculate_block_finish(size_t rank, size_t work_count
  , size_t worker_count);

#endif  // DYNAMIC_SIMULATION_H