Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example added: Graph Input from User #5

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
57 changes: 47 additions & 10 deletions examples/bfsExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,55 @@
#include <iostream>

int main() {
std::cout << "Reached here !!!\n";

float sample_graph1_array[9] = {1, 1, 1, 1, -8, 1, 1, 1, 1};
intptr_t sample_graph_length = 3;
intptr_t sample_graph_width = 3;
// n -> number of nodes.
// m -> number of edges.
int n, m;
float adjMatrix[1000][1000] = {0};

std::cout << "Enter the number of nodes and edges: \n";
std::cin >> n >> m;

std::cout << "Enter the edges of the graph.\n";
for (int i = 0; i < m; ++i) {
int x, y;
std::cin >> x >> y;
adjMatrix[x][y] = 1;
adjMatrix[y][x] = 1;
}

int inputSize = n * n;
float *inputGraph = (float *)malloc(inputSize * sizeof(float));

for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
inputGraph[n * i + j] = (float)adjMatrix[i][j];
}
}

intptr_t graph_nodes = n;
float *allocation_pointer = (float *)malloc(sizeof(float));
intptr_t sample_graph_sizes[2] = {sample_graph_width, sample_graph_length};
intptr_t sample_graph_strides[2] = {sample_graph_width, sample_graph_length};
intptr_t graph_sizes[2] = {graph_nodes, graph_nodes};
intptr_t graph_strides[2] = {graph_nodes, graph_nodes};

MemRef_descriptor input_graph = MemRef_Descriptor(
allocation_pointer, inputGraph, 0, graph_sizes, graph_strides);

graph::graph_bfs(input_graph, input_graph, input_graph);

std::cout << "Graph using adjacency matrix created! \n";

// float sample_graph1_array[9] = {1, 1, 1, 1, -8, 1, 1, 1, 1};
// intptr_t sample_graph_length = 3;
// intptr_t sample_graph_width = 3;
// float *allocation_pointer = (float *)malloc(sizeof(float));
// intptr_t sample_graph_sizes[2] = {sample_graph_width, sample_graph_length};
// intptr_t sample_graph_strides[2] = {sample_graph_width,
// sample_graph_length};

MemRef_descriptor sample_graph =
MemRef_Descriptor(allocation_pointer, sample_graph1_array, 0,
sample_graph_sizes, sample_graph_strides);
// MemRef_descriptor sample_graph =
// MemRef_Descriptor(allocation_pointer, sample_graph1_array, 0,
// sample_graph_sizes, sample_graph_strides);

graph::graph_bfs(sample_graph, sample_graph, sample_graph);
// graph::graph_bfs(sample_graph, sample_graph, sample_graph);
}