예제 #1
0
int
Qinquiry(Queue *q, int op)
{
	switch (op) {
	case Q_SIZE:		/* what's the capacity of the queue? */
		return Qsize (q);
	case Q_USED:		/* how much space is used? */
		return Qused (q);
	case Q_SPACE:		/* how much space is left? */
		return Qspace (q);
	}
	return -1;
}
void bfs(unsigned char* adjMatrix, int num_of_vertices, int source_vertex)
{
    int currentVertex, i;
    unsigned char *label = (unsigned char *) malloc(num_of_vertices * sizeof(unsigned char));
    unsigned char *visited = (unsigned char *) malloc(num_of_vertices * sizeof(unsigned char));

    for(i = 0; i < num_of_vertices; ++i)
        label[i] = -1;

    for(i = 0; i < num_of_vertices; ++i)
        visited[i] = 0;

    label[source_vertex] = 0;
    visited[source_vertex] = 1;
    Qpush(source_vertex);

    t_start = MPI_Wtime();

    while(Qsize() != 0)
    {
        currentVertex = Qpop();

        int j;
        for(j = 0; j < num_of_vertices; ++j)
        {
            if(*(adjMatrix + currentVertex * num_of_vertices + j) == 1)
            {
                if(visited[j] != 1)
                {
                    label[j] = label[currentVertex] + 1;
                    Qpush(j);
                    visited[j] = 1;
                }
            }
        }
    }

    t_end = MPI_Wtime();

    printf("Serial BFS complete. Time taken = %lf\n", t_end - t_start);

    free(label);
    free(visited);
}