Apostolos Fanakis
6 years ago
14 changed files with 262 additions and 141 deletions
Binary file not shown.
@ -1,24 +1,47 @@ |
|||
#ifndef CSR_SPARSE_MATRIX_H /* Include guard */ |
|||
#define CSR_SPARSE_MATRIX_H |
|||
|
|||
/* ===== INCLUDES ===== */ |
|||
|
|||
#include <stdbool.h> |
|||
#include <stdlib.h> |
|||
#include <stdio.h> |
|||
#include <stdlib.h> |
|||
|
|||
/* ===== STRUCTURES ===== */ |
|||
|
|||
// A sparse matrix in compressed SparseRow format.
|
|||
typedef struct csrSparseMatrix { |
|||
int size, numberOfNonZeroElements; |
|||
int size, numberOfElements; |
|||
int *rowCumulativeIndexes, *columnIndexes; |
|||
double *values; |
|||
} CsrSparseMatrix; |
|||
|
|||
/* ===== FUNCTION DEFINITIONS ===== */ |
|||
|
|||
// initCsrSparseMatrix creates and initializes the members of a CsrSparseMatrix
|
|||
// structure instance.
|
|||
CsrSparseMatrix initCsrSparseMatrix(); |
|||
void allocMemoryForCsr(CsrSparseMatrix *sparseMatrix, int numberOfElements); |
|||
|
|||
// allocMemoryForCsr allocates memory for the elements of the matrix.
|
|||
void allocMemoryForCsr(CsrSparseMatrix *sparseMatrix, int size, int numberOfElements); |
|||
|
|||
// zeroOutRow assigns a zero value to all the elements of a row in the matrix.
|
|||
void zeroOutRow(CsrSparseMatrix *sparseMatrix, int row); |
|||
|
|||
// zeroOutColumn assigns a zero value to all the elements of a column in the
|
|||
// matrix.
|
|||
void zeroOutColumn(CsrSparseMatrix *sparseMatrix, int column); |
|||
|
|||
// csrSparseMatrixVectorMultiplication calculates the product of a
|
|||
// CsrSparseMatrix and a vector.
|
|||
void csrSparseMatrixVectorMultiplication(CsrSparseMatrix sparseMatrix, |
|||
double *vector, double **product, int vectorSize); |
|||
|
|||
// destroyCsrSparseMatrix frees all space used by the CsrSparseMatrix.
|
|||
void destroyCsrSparseMatrix(CsrSparseMatrix *sparseMatrix); |
|||
|
|||
// printCsrSparseMatrix prints the values of a CsrSparseMatrix.
|
|||
void printCsrSparseMatrix(CsrSparseMatrix sparseMatrix); |
|||
|
|||
#endif // CSR_SPARSE_MATRIX_H
|
Binary file not shown.
@ -0,0 +1,65 @@ |
|||
#include <sys/time.h> |
|||
|
|||
#include "openmp_gs_pagerank_functions.h" |
|||
|
|||
struct timeval startwtime, endwtime; |
|||
|
|||
int main(int argc, char **argv) { |
|||
CsrSparseMatrix transitionMatrix = initCsrSparseMatrix(); |
|||
double *pagerankVector; |
|||
bool convergenceStatus; |
|||
Parameters parameters; |
|||
int maxIterationsForConvergence = 0; |
|||
|
|||
parseArguments(argc, argv, ¶meters); |
|||
|
|||
initialize(&transitionMatrix, &pagerankVector, ¶meters); |
|||
|
|||
// Saves information about the dataset to the output file
|
|||
{ |
|||
FILE *outputFile; |
|||
outputFile = fopen(parameters.outputFilename, "w"); |
|||
|
|||
if (outputFile == NULL) { |
|||
printf("Error while opening the output file.\n"); |
|||
exit(EXIT_FAILURE); |
|||
} |
|||
|
|||
fprintf(outputFile, "Pagerank will run for the dataset %s\n"\ |
|||
"Dataset contains %d pages with %d outlinks.\n", |
|||
parameters.graphFilename, parameters.numberOfPages, transitionMatrix.size); |
|||
|
|||
fclose(outputFile); |
|||
} |
|||
|
|||
// Starts wall-clock timer
|
|||
gettimeofday (&startwtime, NULL); |
|||
int* iterations = (int *)malloc(parameters.numberOfPages*sizeof(int)); |
|||
|
|||
// Calculates pagerank
|
|||
iterations = pagerank(&transitionMatrix, &pagerankVector, |
|||
&convergenceStatus, parameters, &maxIterationsForConvergence); |
|||
|
|||
// Stops wall-clock timer
|
|||
gettimeofday (&endwtime, NULL); |
|||
double seq_time = (double)((endwtime.tv_usec - startwtime.tv_usec)/1.0e6 + |
|||
endwtime.tv_sec - startwtime.tv_sec); |
|||
printf("%s wall clock time = %f\n","Pagerank (Gauss-Seidel method), serial implementation", |
|||
seq_time); |
|||
|
|||
printf(ANSI_COLOR_YELLOW "\n----- RESULTS -----\n" ANSI_COLOR_RESET); |
|||
if (convergenceStatus) { |
|||
printf(ANSI_COLOR_GREEN "Pagerank converged after %d iterations!\n" \ |
|||
ANSI_COLOR_RESET, maxIterationsForConvergence); |
|||
} else { |
|||
printf(ANSI_COLOR_RED "Pagerank did not converge after max number of" \ |
|||
" iterations (%d) was reached!\n" ANSI_COLOR_RESET, maxIterationsForConvergence); |
|||
} |
|||
|
|||
// Saves results to the output file
|
|||
savePagerankToFile(parameters.outputFilename, iterations, pagerankVector, |
|||
parameters.numberOfPages, maxIterationsForConvergence); |
|||
|
|||
free(pagerankVector); |
|||
destroyCsrSparseMatrix(&transitionMatrix); |
|||
} |
Binary file not shown.
@ -1,44 +0,0 @@ |
|||
#include <sys/time.h> |
|||
#include <omp.h> |
|||
#include "serial_gs_pagerank_functions.h" |
|||
//#include "coo_sparse_matrix.h"
|
|||
|
|||
struct timeval startwtime, endwtime; |
|||
double seq_time; |
|||
|
|||
int main(int argc, char **argv) { |
|||
CsrSparseMatrix transitionMatrix = initCsrSparseMatrix(); |
|||
double *pagerankVector; |
|||
bool convergenceStatus; |
|||
Parameters parameters; |
|||
omp_set_dynamic(0); |
|||
parseArguments(argc, argv, ¶meters); |
|||
|
|||
initialize(&transitionMatrix, &pagerankVector, ¶meters); |
|||
|
|||
// Starts wall-clock timer
|
|||
gettimeofday (&startwtime, NULL); |
|||
|
|||
int iterations = pagerank(&transitionMatrix, &pagerankVector, |
|||
&convergenceStatus, parameters); |
|||
if (parameters.verbose) { |
|||
printf(ANSI_COLOR_YELLOW "\n----- RESULTS -----\n" ANSI_COLOR_RESET); |
|||
if (convergenceStatus) { |
|||
printf(ANSI_COLOR_GREEN "Pagerank converged after %d iterations!\n" \ |
|||
ANSI_COLOR_RESET, iterations); |
|||
} else { |
|||
printf(ANSI_COLOR_RED "Pagerank did not converge after max number of" \ |
|||
" iterations (%d) was reached!\n" ANSI_COLOR_RESET, iterations); |
|||
} |
|||
} |
|||
|
|||
// Stops wall-clock timer
|
|||
gettimeofday (&endwtime, NULL); |
|||
double seq_time = (double)((endwtime.tv_usec - startwtime.tv_usec)/1.0e6 + |
|||
endwtime.tv_sec - startwtime.tv_sec); |
|||
printf("%s wall clock time = %f\n","Pagerank (Gauss-Seidel method), serial implementation", |
|||
seq_time); |
|||
|
|||
free(pagerankVector); |
|||
destroyCsrSparseMatrix(&transitionMatrix); |
|||
} |
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue