From 150ee8ad97c74ab8ab616287b1ff454e66382a21 Mon Sep 17 00:00:00 2001 From: Brandon Rodriguez <brodriguez8774@gmail.com> Date: Tue, 16 Feb 2021 07:36:40 -0500 Subject: [PATCH] Further program cleanup --- src/load_balance_general.c | 19 ++++++++++++++++++- src/load_balance_schemes.c | 30 ++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/load_balance_general.c b/src/load_balance_general.c index 8162376..cc23764 100644 --- a/src/load_balance_general.c +++ b/src/load_balance_general.c @@ -14,6 +14,11 @@ /** * Displays provided worker data through master process. + * + * :param thread_args_ptr: Struct for processor values. + * :param process_num: Processor to update status of. + * :param process_load_status: Load value to display for processor. + * :param init_run: Bool indicating if this is an initialization run or not. Determines if terminal lines are overridden. */ void main_display_status(thread_struct* thread_args_ptr, int process_num, int process_load_status, int init_run) { int index; @@ -58,6 +63,8 @@ void main_display_status(thread_struct* thread_args_ptr, int process_num, int pr /** * Sends message to all worker processes that all work has been completed, and it's okay to terminate now. + * + * :param thread_args_ptr: Struct for processor values. */ void main_terminate_workers(thread_struct* thread_args_ptr) { int index; @@ -91,6 +98,9 @@ void main_terminate_workers(thread_struct* thread_args_ptr) { /** * Sends worker load status and rank to master process. + * + * :param process_rank: Id of process sending status update. + * :param process_load_status: Current value of load to display to console. */ void worker_send_status(int process_rank, int process_load_status) { int* send_array = calloc(2, sizeof(int)); @@ -98,6 +108,9 @@ void worker_send_status(int process_rank, int process_load_status) { log(""); log("FUNCTION worker_send_status()"); + sprintf(log_msg, " process_rank: %i", process_rank); + log(log_msg); free(log_msg); + log_msg = calloc(256, sizeof(char)); sprintf(log_msg, " process_load_status: %i", process_load_status); log(log_msg); free(log_msg); fflush(stdout); @@ -147,8 +160,10 @@ int worker_check_status() { /** * Attempts to receive work from given "possible donor" process (donor is determined by load balancing schema). - * * Does so by sending message to "possible donor" process, to initiate request. + * + * :param thread_args_ptr: Struct for processor values. + * :param possible_donor: Fellow worker thread to beg for work from. */ void worker_send_request(thread_struct* thread_args_ptr, int possible_donor) { int msg_status_flag = 0; @@ -199,6 +214,8 @@ void worker_send_request(thread_struct* thread_args_ptr, int possible_donor) { * * To handle request, either splits current work load in half (asking process gets the smaller portion if odd number) * or returns negative number if no work to send. + * + * :param thread_args_ptr: Struct for processor values. */ void worker_handle_request(thread_struct* thread_args_ptr) { int msg_status_flag = 0; diff --git a/src/load_balance_schemes.c b/src/load_balance_schemes.c index ee51fc8..d80e4ea 100644 --- a/src/load_balance_schemes.c +++ b/src/load_balance_schemes.c @@ -15,6 +15,8 @@ /** * Entrypoint for logic to run "Asynchronous Round Robin" load scheme. + * + * :param thread_args_ptr: Struct for processor values. */ void arr_run(thread_struct* thread_args_ptr) { int process_rank = thread_args_ptr->thread_num; @@ -53,6 +55,8 @@ void arr_run(thread_struct* thread_args_ptr) { /** * Main processor logic for "Asynchronous Round Robin" load scheme. + * + * :param thread_args_ptr: Struct for processor values. */ void arr_main(thread_struct* thread_args_ptr) { int index; @@ -130,6 +134,8 @@ void arr_main(thread_struct* thread_args_ptr) { /** * Worker processor logic for "Asynchronous Round Robin" load scheme. + * + * :param thread_args_ptr: Struct for processor values. */ void arr_worker(thread_struct* thread_args_ptr) { int process_rank = thread_args_ptr->thread_num; @@ -236,18 +242,14 @@ void arr_worker(thread_struct* thread_args_ptr) { } } - // Work is complete. Stick around briefly to ensure all pending message requests are handled. - for (index = 0; index < 5; index++) { - worker_handle_request(thread_args_ptr); - sleep(1); - } - log("Finished ARR worker."); } /** * Entrypoint for logic to run "Global Round Robin" load scheme. + * + * :param thread_args_ptr: Struct for processor values. */ void grr_run(int total_processors) { printf("Starting GRR load scheme."); @@ -258,6 +260,8 @@ void grr_run(int total_processors) { /** * Main processor logic for "Global Round Robin" load scheme. + * + * :param thread_args_ptr: Struct for processor values. */ void grr_main(thread_struct* thread_args_ptr) { log("Starting GRR main."); @@ -268,6 +272,8 @@ void grr_main(thread_struct* thread_args_ptr) { /** * Worker processor logic for "Global Round Robin" load scheme. + * + * :param thread_args_ptr: Struct for processor values. */ void grr_worker(thread_struct* thread_args_ptr) { log("Starting GRR worker."); @@ -278,6 +284,8 @@ void grr_worker(thread_struct* thread_args_ptr) { /** * Entrypoint for logic to run "Random Poling" load scheme. + * + * :param thread_args_ptr: Struct for processor values. */ void rp_run(int total_processors) { log("Starting RP load scheme."); @@ -288,6 +296,8 @@ void rp_run(int total_processors) { /** * Main processor logic for "Random Poling" load scheme. + * + * :param thread_args_ptr: Struct for processor values. */ void rp_main(thread_struct* thread_args_ptr) { log("Starting RP main."); @@ -298,6 +308,8 @@ void rp_main(thread_struct* thread_args_ptr) { /** * Worker processor logic for "Random Poling" load scheme. + * + * :param thread_args_ptr: Struct for processor values. */ void rp_worker(thread_struct* thread_args_ptr) { log("Starting RP worker."); @@ -309,6 +321,8 @@ void rp_worker(thread_struct* thread_args_ptr) { /** * Entrypoint for logic to run "Nearest Neighbor" load scheme. + * + * :param thread_args_ptr: Struct for processor values. */ void nn_run(int total_processors) { log("Starting NN load scheme."); @@ -319,6 +333,8 @@ void nn_run(int total_processors) { /** * Main processor logic for "Nearest Neighbor" load scheme. + * + * :param thread_args_ptr: Struct for processor values. */ void nn_main(thread_struct* thread_args_ptr) { log("Starting NN main."); @@ -330,6 +346,8 @@ void nn_main(thread_struct* thread_args_ptr) { /** * Worker processor logic for "Nearest Neighbor" load scheme. + * + * :param thread_args_ptr: Struct for processor values. */ void nn_worker(thread_struct* thread_args_ptr) { log("Starting NN worker."); -- GitLab