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>
|
2024-10-08 23:04:09 +02:00
|
|
|
#include <stdlib.h>
|
2024-10-04 01:03:39 +02:00
|
|
|
#include <time.h>
|
2024-09-26 14:32:20 +02:00
|
|
|
|
2024-10-04 01:03:39 +02:00
|
|
|
void benchmark() {
|
2024-10-08 23:04:09 +02:00
|
|
|
const uint64_t vertex_count1 = 1024;
|
|
|
|
uint64_t (*matrix1)[vertex_count1] = malloc(vertex_count1 * vertex_count1 * sizeof(uint64_t));
|
2024-09-26 14:32:20 +02:00
|
|
|
|
2024-10-08 23:04:09 +02:00
|
|
|
const uint64_t vertex_count2 = 1024;
|
|
|
|
uint64_t (*matrix2)[vertex_count2] = malloc(vertex_count2 * vertex_count2 * sizeof(uint64_t));
|
2024-10-04 01:03:39 +02:00
|
|
|
|
2024-10-08 23:04:09 +02:00
|
|
|
uint64_t (*new_matrix)[vertex_count2] = malloc(vertex_count1 * vertex_count2 * sizeof(uint64_t));
|
2024-10-04 01:03:39 +02:00
|
|
|
|
|
|
|
double elapsed_time = 0.0;
|
2024-10-08 23:29:02 +02:00
|
|
|
const uint64_t iterations = 10;
|
2024-10-04 01:03:39 +02:00
|
|
|
clock_t start_time;
|
|
|
|
|
|
|
|
for (uint64_t i = 0; i < iterations; i++) {
|
2024-10-08 23:04:09 +02:00
|
|
|
random_adjacency(vertex_count1, matrix1);
|
|
|
|
random_adjacency(vertex_count2, matrix2);
|
2024-10-04 01:03:39 +02:00
|
|
|
|
|
|
|
start_time = clock();
|
|
|
|
|
2024-10-08 23:29:02 +02:00
|
|
|
gemm_basic(vertex_count1, vertex_count1, matrix1,
|
2024-10-08 23:04:09 +02:00
|
|
|
vertex_count2, vertex_count2, matrix2,
|
2024-10-04 01:03:39 +02:00
|
|
|
new_matrix);
|
|
|
|
|
|
|
|
elapsed_time += (double)(clock() - start_time) / CLOCKS_PER_SEC;
|
|
|
|
}
|
2024-09-26 14:32:20 +02:00
|
|
|
|
2024-10-08 23:29:02 +02:00
|
|
|
printf("%lu iterations of gemm_basic took roughly %f seconds\n", iterations, elapsed_time);
|
|
|
|
printf("An iteration of gemm_basic took on average roughly %f seconds\n", elapsed_time/iterations);
|
2024-10-08 23:04:09 +02:00
|
|
|
|
|
|
|
free(matrix1);
|
|
|
|
free(matrix2);
|
|
|
|
free(new_matrix);
|
2024-10-04 01:03:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void test() {
|
2024-10-09 01:42:55 +02:00
|
|
|
const uint64_t vertex_count = 7;
|
2024-10-04 17:36:40 +02:00
|
|
|
uint64_t adjacency_matrix[vertex_count][vertex_count];
|
2024-10-09 01:42:55 +02:00
|
|
|
uint64_t distance_matrix[vertex_count][vertex_count];
|
|
|
|
uint64_t eccentricities[vertex_count];
|
|
|
|
uint64_t radius, diameter, centre[vertex_count];
|
2024-10-04 01:03:39 +02:00
|
|
|
|
2024-10-09 01:42:55 +02:00
|
|
|
read_csv("csv/7n.csv", vertex_count, vertex_count, adjacency_matrix);
|
2024-10-04 01:03:39 +02:00
|
|
|
|
2024-10-08 22:18:36 +02:00
|
|
|
puts("G:");
|
2024-10-04 17:36:40 +02:00
|
|
|
print_matrix(vertex_count, vertex_count, adjacency_matrix);
|
2024-10-08 22:18:36 +02:00
|
|
|
puts("");
|
2024-09-26 14:32:20 +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-08 22:18:36 +02:00
|
|
|
puts("distance_matrix:");
|
2024-10-04 17:36:40 +02:00
|
|
|
print_matrix(vertex_count, vertex_count, distance_matrix);
|
2024-10-08 22:18:36 +02:00
|
|
|
puts("");
|
2024-10-09 01:42:55 +02:00
|
|
|
|
|
|
|
get_eccentricities(vertex_count, distance_matrix, eccentricities);
|
|
|
|
|
|
|
|
puts("eccentricities:");
|
|
|
|
for (uint64_t index = 0; index < vertex_count; index++) {
|
|
|
|
printf("Vertex %lu: %lu, ", index + 1, eccentricities[index]);
|
|
|
|
}
|
|
|
|
puts("");
|
|
|
|
|
|
|
|
radius = get_radius(vertex_count, eccentricities);
|
|
|
|
diameter = get_diameter(vertex_count, eccentricities);
|
|
|
|
get_centre(vertex_count, eccentricities, radius, centre);
|
|
|
|
|
|
|
|
printf("radius: %lu\n", radius);
|
|
|
|
printf("diameter: %lu\n", diameter);
|
|
|
|
printf("centre: ");
|
|
|
|
for (uint64_t index = 0; index < vertex_count; index++) {
|
|
|
|
if (centre[index] == 1) {
|
|
|
|
printf("Vertex: %lu, ", index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
puts("");
|
2024-10-04 01:03:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void) {
|
2024-10-09 01:42:55 +02:00
|
|
|
test();
|
|
|
|
// benchmark();
|
2024-09-26 14:32:20 +02:00
|
|
|
}
|