Skip to content
Snippets Groups Projects
Commit 5b38f952 authored by Brandon Rodriguez's avatar Brandon Rodriguez
Browse files

Make NN scheme more correct

parent ed7ee0c1
Branches
No related merge requests found
......@@ -850,7 +850,7 @@ void nn_main(thread_struct* thread_args_ptr) {
*/
void nn_worker(thread_struct* thread_args_ptr) {
int process_rank = thread_args_ptr->thread_num;
int nn_counter;
int nn_counter = process_rank;
int main_loop_bool = 1;
int msg_status_flag;
int request_flag = -1;
......@@ -858,12 +858,13 @@ void nn_worker(thread_struct* thread_args_ptr) {
int send_status = 1;
int ten_percent;
int nn_range;
int nn_range_low = process_rank;
int nn_range_high = process_rank;
int calculate_nn;
int index;
log("Starting NN worker.");
// Initialize random number generator.
srand(time(NULL));
// Determine "neighbor" range, based on thread number.
// Range is [ process_id +- 10%_of_total_processes ]. If hits 0 or max, then loops around.
ten_percent = thread_args_ptr->total_processors / 10;
......@@ -872,6 +873,28 @@ void nn_worker(thread_struct* thread_args_ptr) {
}
nn_range = ten_percent * 2;
for (index = 0; index < nn_range; index++) {
nn_range_low -= 1;
if (nn_range_low == 0) {
nn_range_low = thread_args_ptr->total_processors - 1;
}
nn_range_high = (nn_range_high + 1) % thread_args_ptr->total_processors;
if (nn_range_high == 0) {
nn_range_high += 1;
}
}
char* log_msg = calloc(256, sizeof(char));
sprintf(log_msg, "nn_range: %i", nn_range);
log(log_msg); free(log_msg);
log_msg = calloc(256, sizeof(char));
sprintf(log_msg, "nn_range_low: %i", nn_range_low);
log(log_msg); free(log_msg);
log_msg = calloc(256, sizeof(char));
sprintf(log_msg, "nn_range_high: %i", nn_range_high);
log(log_msg); free(log_msg);
// Initialize process "1" to have full loads. All others start with none.
if (process_rank == 1) {
thread_args_ptr->remaining_loads = thread_args_ptr->total_loads;
......@@ -922,12 +945,27 @@ void nn_worker(thread_struct* thread_args_ptr) {
if (request_flag == -1) {
// Update personal NN counter.
nn_counter = thread_args_ptr->thread_num;
while (nn_counter == thread_args_ptr->thread_num) {
nn_counter = rand() % nn_range;
nn_counter = nn_counter + thread_args_ptr->thread_num + 1;
if (nn_counter > thread_args_ptr->total_processors - 1) {
nn_counter = (nn_counter % thread_args_ptr->total_processors) + 1;
calculate_nn = 1;
while (calculate_nn == 1) {
nn_counter = (nn_counter + 1) % thread_args_ptr->total_processors;
calculate_nn = 0;
// Check for basic validation.
if (nn_counter == 0 || nn_counter == thread_args_ptr->thread_num) {
calculate_nn = 1;
}
// Check for range validation.
if (nn_range_low < nn_range_high) {
// Standard value set range. Handle normally.
if (nn_counter < nn_range_low || nn_counter > nn_range_high) {
calculate_nn = 1;
}
} else {
// Non-standard value set range. There's an overflow.
if (nn_range_high < nn_counter && nn_counter < nn_range_low) {
calculate_nn = 1;
}
}
}
......
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