Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include "arc.h"
#include "jerasure.h"
#include "reed_sol.h"
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
// Type Malloc Macro
#define talloc(type, num) (type *) malloc(sizeof(type)*(num))

Expand Down Expand Up @@ -49,9 +53,9 @@ int RS_ID = 4;
// Resource Variables Section
// ###########################
// Resource Folder Location
char *resource_location = "/home/dakotaf/ARC/src/res/";
char *resource_location = "/home/jetson/ARC/src/res/";
// Cache Resource Folder Location
char *cache_resource_location = "/home/dakotaf/ARC/src/res/cache/";
char *cache_resource_location = "/home/jetson/ARC/src/res/cache/";
// Set configuration information cache string
char *thread_resource_file = "_information_cache.csv";
// Hamming & SECDED Resource Variables
Expand Down Expand Up @@ -2802,8 +2806,15 @@ int arc_reed_solomon_encode(uint8_t* data, uint32_t data_size, uint32_t data_dev
n_per_thread = block_count / threads;
}
// Set number of threads
omp_set_num_threads(threads);

omp_set_num_threads(threads);

// Pre-compute Vandermonde matrices outside loop to avoid redundant recomputation
int* matrix = reed_sol_vandermonde_coding_matrix(data_devices, code_devices, 8);
int* remainder_matrix = NULL;
if (remainder_data_devices != 0) {
remainder_matrix = reed_sol_vandermonde_coding_matrix(remainder_data_devices, code_devices, 8);
}

// Calculate Reed-Solomon Encoding for each block
#pragma omp parallel for schedule(static, n_per_thread)
for (blocks_processed = 0; blocks_processed < block_count; blocks_processed++){
Expand Down Expand Up @@ -2865,11 +2876,11 @@ int arc_reed_solomon_encode(uint8_t* data, uint32_t data_size, uint32_t data_dev
rs_code[i] = talloc(char, 8);
}

// Setup Vandermonde Matrix
int* matrix = reed_sol_vandermonde_coding_matrix(current_block_data_devices, code_devices, 8);
// Select pre-computed matrix based on block type
int* current_matrix = (blocks_processed == block_count-1 && remainder_data_devices != 0) ? remainder_matrix : matrix;

// Encode with classic Reed-Solomon Encoding
jerasure_matrix_encode(current_block_data_devices, code_devices, 8, matrix, rs_data, rs_code, 8);
jerasure_matrix_encode(current_block_data_devices, code_devices, 8, current_matrix, rs_data, rs_code, 8);

// Flatten rs_code and rs_data back to a uint8_t array
uint32_t block_stream_size = (current_block_data_devices + code_devices) * 8;
Expand Down Expand Up @@ -2927,9 +2938,12 @@ int arc_reed_solomon_encode(uint8_t* data, uint32_t data_size, uint32_t data_dev
}
free(rs_code);
free(block_stream);
free(matrix);
}

// Free pre-computed matrices
free(matrix);
if (remainder_matrix) free(remainder_matrix);

// Return resulting array
if (PRINT){
printf("Reed Solomon Encoding Finished\n");
Expand Down