tiny changes

This commit is contained in:
AustrianToast 2024-10-04 16:46:40 +02:00
parent 5cb04ff579
commit 9f17802c49
Signed by: AustrianToast
GPG Key ID: 174D780E041684FF
3 changed files with 11 additions and 11 deletions

View File

@ -1,13 +1,13 @@
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void random_adjacency(const uint64_t vertex_count, uint64_t matrix[vertex_count][vertex_count]) {
srand(time(NULL));
for (uint8_t row_index=0; row_index < vertex_count; row_index++) {
for (uint8_t column_index=0; column_index < vertex_count; column_index++) {
for (uint64_t row_index=0; row_index < vertex_count; row_index++) {
for (uint64_t column_index=0; column_index < vertex_count; column_index++) {
if(column_index == row_index) {
matrix[row_index][column_index] = 0;
continue;

10
main.c
View File

@ -5,12 +5,10 @@
#include <time.h>
void benchmark() {
const uint64_t row_length1 = 100;
const uint64_t column_length1 = 100;
const uint64_t row_length1 = 100, column_length1 = 100;
uint64_t matrix1[row_length1][column_length1];
const uint64_t row_length2 = 100;
const uint64_t column_length2 = 100;
const uint64_t row_length2 = 100, column_length2 = 100;
uint64_t matrix2[row_length2][column_length2];
uint64_t new_matrix[row_length1][column_length2];
@ -21,7 +19,7 @@ void benchmark() {
for (uint64_t i = 0; i < iterations; i++) {
random_adjacency(row_length1, matrix1);
random_adjacency(row_length2, matrix2);
random_adjacency(row_length2, matrix2);;
start_time = clock();
@ -33,7 +31,7 @@ void benchmark() {
}
printf("%lu iterations of matrix_multiply_basic took roughly %f seconds\n", iterations, elapsed_time);
printf("1 iteration of matrix_multiply_basic took on average roughly %f seconds\n", elapsed_time/iterations);
printf("An iteration of matrix_multiply_basic took on average roughly %f seconds\n", elapsed_time/iterations);
}
void test() {

View File

@ -22,9 +22,11 @@ int matrix_multiply_basic(const uint64_t row_length1, const uint64_t column_leng
return 1;
}
uint64_t sum;
for (uint64_t i = 0; i < row_length1; i++) {
for(uint64_t j = 0; j < column_length2; j++) {
uint64_t sum = 0;
sum = 0;
for (uint64_t k = 0; k <row_length1; k++) {
sum += matrix1[i][k] * matrix2[k][j];
@ -39,7 +41,7 @@ int matrix_multiply_basic(const uint64_t row_length1, const uint64_t column_leng
int read_csv(const char *file_name, const uint64_t row_length, const uint64_t column_length, uint64_t output_matrix[row_length][column_length]) {
FILE *file_ptr;
uint32_t bufsize = row_length*2; // have to account for delimiters
uint64_t bufsize = row_length*2; // have to account for delimiters
char buffer[bufsize];
char *value, *file_line;
uint64_t row_index = 0, column_index = 0;