2024-09-26 14:32:20 +02:00
|
|
|
#include "graph.h"
|
|
|
|
#include "matrix.h"
|
|
|
|
#include <stdint.h>
|
2024-10-04 01:03:39 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
2024-09-26 14:32:20 +02:00
|
|
|
|
2024-10-04 01:03:39 +02:00
|
|
|
void benchmark() {
|
2024-10-04 16:46:40 +02:00
|
|
|
const uint64_t row_length1 = 100, column_length1 = 100;
|
2024-10-04 01:03:39 +02:00
|
|
|
uint64_t matrix1[row_length1][column_length1];
|
2024-09-26 14:32:20 +02:00
|
|
|
|
2024-10-04 16:46:40 +02:00
|
|
|
const uint64_t row_length2 = 100, column_length2 = 100;
|
2024-10-04 01:03:39 +02:00
|
|
|
uint64_t matrix2[row_length2][column_length2];
|
|
|
|
|
|
|
|
uint64_t new_matrix[row_length1][column_length2];
|
|
|
|
|
|
|
|
double elapsed_time = 0.0;
|
|
|
|
const uint64_t iterations = 10000;
|
|
|
|
clock_t start_time;
|
|
|
|
|
|
|
|
for (uint64_t i = 0; i < iterations; i++) {
|
2024-10-04 13:05:02 +02:00
|
|
|
random_adjacency(row_length1, matrix1);
|
2024-10-04 16:46:40 +02:00
|
|
|
random_adjacency(row_length2, matrix2);;
|
2024-10-04 01:03:39 +02:00
|
|
|
|
|
|
|
start_time = clock();
|
|
|
|
|
|
|
|
matrix_multiply_basic(row_length1, column_length1, matrix1,
|
|
|
|
row_length2, column_length2, matrix2,
|
|
|
|
new_matrix);
|
|
|
|
|
|
|
|
elapsed_time += (double)(clock() - start_time) / CLOCKS_PER_SEC;
|
|
|
|
}
|
2024-09-26 14:32:20 +02:00
|
|
|
|
2024-10-04 01:03:39 +02:00
|
|
|
printf("%lu iterations of matrix_multiply_basic took roughly %f seconds\n", iterations, elapsed_time);
|
2024-10-04 16:46:40 +02:00
|
|
|
printf("An iteration of matrix_multiply_basic took on average roughly %f seconds\n", elapsed_time/iterations);
|
2024-10-04 01:03:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void test() {
|
2024-10-04 17:36:40 +02:00
|
|
|
const uint64_t vertex_count = 5;
|
|
|
|
uint64_t adjacency_matrix[vertex_count][vertex_count];
|
2024-10-04 01:03:39 +02:00
|
|
|
|
2024-10-04 17:36:40 +02:00
|
|
|
read_csv("csv/graph.csv", vertex_count, vertex_count, adjacency_matrix);
|
2024-10-04 01:03:39 +02:00
|
|
|
|
2024-10-04 13:05:02 +02:00
|
|
|
printf("G:\n");
|
2024-10-04 17:36:40 +02:00
|
|
|
print_matrix(vertex_count, vertex_count, adjacency_matrix);
|
2024-10-04 13:05:02 +02:00
|
|
|
printf("\n");
|
2024-09-26 14:32:20 +02:00
|
|
|
|
2024-10-07 09:03:29 +02:00
|
|
|
// uint64_t new_matrix1[vertex_count][vertex_count];
|
2024-10-04 17:36:40 +02:00
|
|
|
//
|
2024-10-07 09:03:29 +02:00
|
|
|
// matrix_multiply_basic(vertex_count, vertex_count, adjacency_matrix,
|
|
|
|
// vertex_count, vertex_count, adjacency_matrix,
|
|
|
|
// new_matrix1);
|
2024-10-04 17:36:40 +02:00
|
|
|
//
|
|
|
|
// printf("G²:\n");
|
2024-10-07 09:03:29 +02:00
|
|
|
// print_matrix(vertex_count, vertex_count, new_matrix1);
|
|
|
|
// printf("\n");
|
|
|
|
//
|
|
|
|
// uint64_t new_matrix2[vertex_count][vertex_count];
|
|
|
|
//
|
|
|
|
// copy(vertex_count, vertex_count, new_matrix1, new_matrix2);
|
|
|
|
//
|
|
|
|
// matrix_multiply_basic(vertex_count, vertex_count, new_matrix1,
|
|
|
|
// vertex_count, vertex_count, adjacency_matrix,
|
|
|
|
// new_matrix2);
|
|
|
|
//
|
|
|
|
// printf("G³:\n");
|
|
|
|
// print_matrix(vertex_count, vertex_count, new_matrix2);
|
2024-10-04 17:36:40 +02:00
|
|
|
// printf("\n");
|
|
|
|
|
|
|
|
uint64_t distance_matrix[vertex_count][vertex_count];
|
2024-10-04 13:05:02 +02:00
|
|
|
|
2024-10-04 17:36:40 +02:00
|
|
|
calculate_distance_matrix(vertex_count, adjacency_matrix, distance_matrix);
|
2024-10-04 13:05:02 +02:00
|
|
|
|
2024-10-04 17:36:40 +02:00
|
|
|
printf("distance_matrix:\n");
|
|
|
|
print_matrix(vertex_count, vertex_count, distance_matrix);
|
2024-10-04 13:05:02 +02:00
|
|
|
printf("\n");
|
2024-10-04 01:03:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void) {
|
2024-10-04 17:36:40 +02:00
|
|
|
test();
|
|
|
|
// benchmark();
|
2024-09-26 14:32:20 +02:00
|
|
|
}
|