Skip to content
Snippets Groups Projects
Commit 479af8d1 authored by Razvan Deaconescu's avatar Razvan Deaconescu
Browse files

src: Add setup for testing of parallelism


Use call to `nanosleep()` to simulate work being done by each thread.
This way force parallelism and point whether tasks are properly balanced
among threads.

Signed-off-by: default avatarRazvan Deaconescu <razvan.deaconescu@upb.ro>
parent 02edde74
No related branches found
No related tags found
No related merge requests found
Pipeline #44200 passed
......@@ -69,6 +69,7 @@ os_task_t *dequeue_task(os_threadpool_t *tp)
static void *thread_loop_function(void *arg)
{
os_threadpool_t *tp = (os_threadpool_t *) arg;
unsigned int nodes = 0;
while (1) {
os_task_t *t;
......@@ -80,6 +81,8 @@ static void *thread_loop_function(void *arg)
destroy_task(t);
}
printf("num processed nodes: %d\n", nodes);
return NULL;
}
......
......@@ -25,6 +25,14 @@ static void process_node(unsigned int idx)
/* TODO: Implement thread-pool based processing of graph. */
}
struct timespec ts = {
.tv_sec = 0,
.tv_nsec = 1000000
};
/* TODO: Call nanosleep(&ts, NULL); when adding to sum */
/* Make call outside a lock / unlock section. */
int main(int argc, char *argv[])
{
FILE *input_file;
......
......@@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "os_graph.h"
#include "log/log.h"
......@@ -10,13 +11,22 @@
static int sum;
static os_graph_t *graph;
static unsigned int num_nodes;
struct timespec ts = {
.tv_sec = 0,
.tv_nsec = 1000000
};
static void process_node(unsigned int idx)
{
os_node_t *node;
node = graph->nodes[idx];
sum += node->info;
nanosleep(&ts, NULL);
graph->visited[idx] = DONE;
num_nodes++;
for (unsigned int i = 0; i < node->num_neighbours; i++)
if (graph->visited[node->neighbours[i]] == NOT_VISITED)
......@@ -40,6 +50,7 @@ int main(int argc, char *argv[])
process_node(0);
printf("%d", sum);
printf("num_nodes: %d", num_nodes);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment