Skip to content

Commit

Permalink
Parallelized join child execution
Browse files Browse the repository at this point in the history
  • Loading branch information
Griezn committed Nov 18, 2024
1 parent 586f3d1 commit fad87aa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
7 changes: 7 additions & 0 deletions include/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
#include "source.h"
#include "defs.h"

typedef struct {
const operator_t *operator_;
const data_t *in;
data_t *out;
} operator_thread_arg_t;


void execute_query(const query_t *query, const source_t *source, sink_t *sink);

#endif //QUERY_H
25 changes: 23 additions & 2 deletions src/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>


/// The join operator
Expand Down Expand Up @@ -95,6 +96,14 @@ void select_query(const data_t *in, data_t *out, const parameter_t param)
}


void execute_operator(const operator_t *operator_, const data_t *in, data_t *out);
void *execute_operator_thread(void *arg) {
const operator_thread_arg_t *targ = arg;
execute_operator(targ->operator_, targ->in, targ->out);
return NULL;
}


/// This function executed the right operator
/// @param operator_ The operator to be executed
/// @param in The input stream
Expand All @@ -109,8 +118,20 @@ void execute_operator(const operator_t *operator_, const data_t *in, data_t *out
assert(operator_->left);
assert(operator_->right);

execute_operator(operator_->left, in, &tmpo1);
execute_operator(operator_->right, in, &tmpo2);
// Thread arguments
operator_thread_arg_t left_arg = {operator_->left, in, &tmpo1};
operator_thread_arg_t right_arg = {operator_->right, in, &tmpo2};

// Threads
pthread_t left_thread, right_thread;

// Execute left and right operators in parallel
pthread_create(&left_thread, NULL, execute_operator_thread, &left_arg);
pthread_create(&right_thread, NULL, execute_operator_thread, &right_arg);

// Wait for threads to finish
pthread_join(left_thread, NULL);
pthread_join(right_thread, NULL);

join(&tmpo1, &tmpo2, out, operator_->params);

Expand Down

0 comments on commit fad87aa

Please sign in to comment.