diff --git a/serial/Makefile b/serial/Makefile index b321b1d..e74d3ca 100644 --- a/serial/Makefile +++ b/serial/Makefile @@ -3,7 +3,7 @@ SHELL := /bin/bash # ============================================ # COMMANDS -CC = gcc +CC = gcc -std=gnu99 RM = rm -f CFLAGS_DEBUG=-O0 -ggdb3 -Wall -I. CFLAGS=-O3 -Wall -I. diff --git a/serial/serial_gs_pagerank.o b/serial/serial_gs_pagerank.o new file mode 100644 index 0000000..1632016 Binary files /dev/null and b/serial/serial_gs_pagerank.o differ diff --git a/serial/serial_gs_pagerank_functions.c b/serial/serial_gs_pagerank_functions.c index 98fd38c..93d0041 100644 --- a/serial/serial_gs_pagerank_functions.c +++ b/serial/serial_gs_pagerank_functions.c @@ -62,7 +62,7 @@ int pagerank(CsrSparseMatrix *transitionMatrix, double **pagerankVector, do { // Stores previous pagerank vector memcpy(previousPagerankVector, *pagerankVector, numberOfPages * sizeof(double)); - + // Calculates new pagerank vector calculateNextPagerank(transitionMatrix, previousPagerankVector, pagerankVector, linksFromConvergedPagesPagerankVector, @@ -72,7 +72,7 @@ int pagerank(CsrSparseMatrix *transitionMatrix, double **pagerankVector, if (parameters.history) { // Outputs pagerank vector to file savePagerankToFile(parameters.outputFilename, iterations != 0, - *pagerankVector, numberOfPages); + *pagerankVector, numberOfPages, realIterations); } // Periodically checks for convergence @@ -149,11 +149,11 @@ int pagerank(CsrSparseMatrix *transitionMatrix, double **pagerankVector, } } while (!*convergenceStatus && (parameters.maxIterations == 0 || iterations < parameters.maxIterations)); - + (*parameters).realIterations = iterations; if (!parameters.history) { // Outputs last pagerank vector to file savePagerankToFile(parameters.outputFilename, false, *pagerankVector, - numberOfPages); + numberOfPages, parameters.realIterations); } // Frees memory @@ -163,7 +163,7 @@ int pagerank(CsrSparseMatrix *transitionMatrix, double **pagerankVector, free(linksFromConvergedPagesPagerankVector); free(convergenceMatrix); destroyCooSparseMatrix(&linksFromConvergedPages); - + return iterations; } @@ -195,7 +195,7 @@ void initialize(CsrSparseMatrix *transitionMatrix, "\nGraph filename: %s\n", (*parameters).convergenceCriterion, (*parameters).dampingFactor, (*parameters).graphFilename); } - + (*parameters).realIterations = 0; // Allocates memory for the pagerank vector (*pagerankVector) = (double *) malloc((*parameters).numberOfPages * sizeof(double)); double webUniformProbability = 1. / (*parameters).numberOfPages; @@ -215,6 +215,8 @@ void calculateNextPagerank(CsrSparseMatrix *transitionMatrix, double *linksFromConvergedPagesPagerankVector, double *convergedPagerankVector, int vectorSize, double dampingFactor) { // Calculates the web uniform probability once. + + double webUniformProbability = 1. / vectorSize; csrSparseMatrixVectorMultiplication(*transitionMatrix, previousPagerankVector, @@ -228,8 +230,9 @@ void calculateNextPagerank(CsrSparseMatrix *transitionMatrix, vectorNorm(*pagerankVector, vectorSize); for (int i=0; irowIndex, pageOutdegree = 1; - for (int i=1; irowIndex == currentRow) { - ++pageOutdegree; - } else { - double pageUniformProbability = 1. / pageOutdegree; - for (int j=i-pageOutdegree; jvalue = pageUniformProbability; - } - currentRow = currentElement->rowIndex; - pageOutdegree = 1; - } + int* pageOutdegree = malloc((*parameters).numberOfPages*sizeof(int)); + for (int i=0; i<(*parameters).numberOfPages; ++i){ + pageOutdegree[i] = 0; } - // Does the last row - double pageUniformProbability = 1. / pageOutdegree; - for (int j=tempMatrix.size-pageOutdegree; jvalue = pageUniformProbability; + + for (int i=0; irowIndex; + + if (currentRow == tempMatrix.elements[i]->rowIndex) { + ++pageOutdegree[currentRow]; + } + + } + for (int i=0; ivalue = 1./pageOutdegree[tempMatrix.elements[i]->rowIndex]; + } + // Transposes the temporary transition matrix (P^T). transposeSparseMatrix(&tempMatrix); - allocMemoryForCsr(transitionMatrix, numberOfEdges); // Transforms the temporary COO matrix to the desired CSR format transformToCSR(tempMatrix, transitionMatrix); + //printCsrSparseMatrix(*transitionMatrix); destroyCooSparseMatrix(&tempMatrix); fclose(graphFile); @@ -479,7 +481,7 @@ int checkIncrement(int previousIndex, int maxIndex, char *programName) { } void savePagerankToFile(char *filename, bool append, double *pagerankVector, - int vectorSize) { + int vectorSize, int realIterations) { FILE *outputFile; if (append) { @@ -492,11 +494,13 @@ void savePagerankToFile(char *filename, bool append, double *pagerankVector, printf("Error while opening the output file.\n"); return; } - + //Save numberofPages and convergence time + for (int i=0; i