#include "graph.h" #include "matrix.h" #include #include #include #include void benchmark() { const uint64_t vertex_count1 = 1024; uint64_t (*matrix1)[vertex_count1] = malloc(vertex_count1 * vertex_count1 * sizeof(uint64_t)); const uint64_t vertex_count2 = 1024; uint64_t (*matrix2)[vertex_count2] = malloc(vertex_count2 * vertex_count2 * sizeof(uint64_t)); uint64_t (*new_matrix)[vertex_count2] = malloc(vertex_count1 * vertex_count2 * sizeof(uint64_t)); double elapsed_time = 0.0; const uint64_t iterations = 10; clock_t start_time; for (uint64_t i = 0; i < iterations; i++) { random_adjacency(vertex_count1, matrix1); random_adjacency(vertex_count2, matrix2); start_time = clock(); gemm_basic(vertex_count1, vertex_count1, matrix1, vertex_count2, vertex_count2, matrix2, new_matrix); elapsed_time += (double)(clock() - start_time) / CLOCKS_PER_SEC; } 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); free(matrix1); free(matrix2); free(new_matrix); } void test_with_csv() { const uint64_t vertex_count = 24; uint64_t adjacency_matrix[vertex_count][vertex_count]; uint64_t distance_matrix[vertex_count][vertex_count]; uint64_t path_matrix[vertex_count][vertex_count]; uint64_t eccentricities[vertex_count]; uint64_t radius, diameter, centre[vertex_count]; uint64_t components[vertex_count][vertex_count]; uint64_t bridges[vertex_count][2]; uint64_t articulations[vertex_count]; if (read_csv("csv/24n.csv", vertex_count, vertex_count, adjacency_matrix) == 1) { return; } calculate_distance_matrix(vertex_count, adjacency_matrix, distance_matrix); get_eccentricities(vertex_count, distance_matrix, eccentricities); radius = get_radius(vertex_count, eccentricities); diameter = get_diameter(vertex_count, eccentricities); get_centre(vertex_count, eccentricities, radius, centre); calculate_path_matrix(vertex_count, adjacency_matrix, path_matrix); find_components_basic(vertex_count, path_matrix, components); find_bridges_basic(vertex_count, adjacency_matrix, components, bridges); find_articulations_basic(vertex_count, adjacency_matrix, components, articulations); puts("adjacency_matrix:"); print_matrix(vertex_count, vertex_count, adjacency_matrix); puts("\ndistance_matrix:"); print_matrix(vertex_count, vertex_count, distance_matrix); puts("\neccentricities:"); for (uint64_t index = 0; index < vertex_count; index++) { printf("\tVertex %lu: %lu\n", index + 1, eccentricities[index]); } printf("\nradius: %lu", radius); printf("\ndiameter: %lu", diameter); puts("\ncentre:"); for (uint64_t index = 0; index < vertex_count; index++) { if (centre[index] == 1) { printf("\tVertex %lu\n", index + 1); } } puts("\npath_matrix:"); print_matrix(vertex_count, vertex_count, path_matrix); puts("\ncomponents:"); for (uint64_t row_index = 0; row_index < vertex_count; row_index++) { int empty = 1; for (uint64_t column_index = 0; column_index < vertex_count; column_index++) { if (components[row_index][column_index] != UINT64_MAX) { empty = 0; } } if (empty) { continue; } printf("\tComponent %lu: {", row_index + 1); for (uint64_t column_index = 0; column_index < vertex_count; column_index++) { if (components[row_index][column_index] != UINT64_MAX) { printf("%lu, ", components[row_index][column_index]); } } puts("}"); } puts("\nbridges:"); for (uint64_t index = 0; index < vertex_count; index++) { if (bridges[index][0] != UINT64_MAX) { printf("\tBridge %lu: {%lu, %lu}\n", index + 1, bridges[index][0], bridges[index][1]); } } puts("\narticulations:"); for (uint64_t index = 0; index < vertex_count; index++) { if (articulations[index] != UINT64_MAX) { printf("\tVertex %lu\n", articulations[index]); } } } void test_dfs() { const uint64_t vertex_count = 7; uint64_t adjacency_matrix[vertex_count][vertex_count]; int visited[vertex_count]; if (read_csv("csv/7n.csv", vertex_count, vertex_count, adjacency_matrix) == 1) { return; } for (uint64_t vertex = 0; vertex < vertex_count; vertex++) { for (uint64_t index = 0; index < vertex_count; index++) { visited[index] = 0; } dfs(vertex_count, adjacency_matrix, vertex, visited); for (uint64_t index = 0; index < vertex_count; index++) { printf("%d", visited[index]); } printf("\n"); } } int main(void) { test_with_csv(); // test_dfs(); // benchmark(); }