Browse Source

Minor fixes for serial, New dataset for testing

master
Apostolos Fanakis 6 years ago
parent
commit
1c008f0f04
No known key found for this signature in database GPG Key ID: 56CE2DEDE9F1FB78
  1. 90003
      datasets/barabasi-90000.txt
  2. 1
      serial/serial_gs_pagerank.c
  3. BIN
      serial/serial_gs_pagerank.o
  4. 49
      serial/serial_gs_pagerank_functions.c
  5. 4
      serial/serial_gs_pagerank_functions.h

90003
datasets/barabasi-90000.txt

File diff suppressed because it is too large

1
serial/serial_gs_pagerank.c

@ -1,7 +1,6 @@
#include <sys/time.h> #include <sys/time.h>
#include "serial_gs_pagerank_functions.h" #include "serial_gs_pagerank_functions.h"
//#include "coo_sparse_matrix.h"
struct timeval startwtime, endwtime; struct timeval startwtime, endwtime;
double seq_time; double seq_time;

BIN
serial/serial_gs_pagerank.o

Binary file not shown.

49
serial/serial_gs_pagerank_functions.c

@ -15,8 +15,8 @@ const int NUMERICAL_BASE = 10;
char *DEFAULT_OUTPUT_FILENAME = "pagerank_output"; char *DEFAULT_OUTPUT_FILENAME = "pagerank_output";
const int FILE_READ_BUFFER_SIZE = 4096; const int FILE_READ_BUFFER_SIZE = 4096;
const int CONVERGENCE_CHECK_ITERATION_PERIOD = 3; const int CONVERGENCE_CHECK_ITERATION_PERIOD = 2;
const int SPARSITY_INCREASE_ITERATION_PERIOD = 3; const int SPARSITY_INCREASE_ITERATION_PERIOD = 10;
/* ===== FUNCTIONS ===== */ /* ===== FUNCTIONS ===== */
@ -72,7 +72,7 @@ int pagerank(CsrSparseMatrix *transitionMatrix, double **pagerankVector,
if (parameters.history) { if (parameters.history) {
// Outputs pagerank vector to file // Outputs pagerank vector to file
savePagerankToFile(parameters.outputFilename, iterations != 0, savePagerankToFile(parameters.outputFilename, iterations != 0,
*pagerankVector, numberOfPages, realIterations); *pagerankVector, numberOfPages, iterations);
} }
// Periodically checks for convergence // Periodically checks for convergence
@ -149,11 +149,11 @@ int pagerank(CsrSparseMatrix *transitionMatrix, double **pagerankVector,
} }
} while (!*convergenceStatus && (parameters.maxIterations == 0 || } while (!*convergenceStatus && (parameters.maxIterations == 0 ||
iterations < parameters.maxIterations)); iterations < parameters.maxIterations));
(*parameters).realIterations = iterations;
if (!parameters.history) { if (!parameters.history) {
// Outputs last pagerank vector to file // Always outputs last pagerank vector to file
savePagerankToFile(parameters.outputFilename, false, *pagerankVector, savePagerankToFile(parameters.outputFilename, false, *pagerankVector,
numberOfPages, parameters.realIterations); numberOfPages, iterations);
} }
// Frees memory // Frees memory
@ -195,7 +195,7 @@ void initialize(CsrSparseMatrix *transitionMatrix,
"\nGraph filename: %s\n", (*parameters).convergenceCriterion, "\nGraph filename: %s\n", (*parameters).convergenceCriterion,
(*parameters).dampingFactor, (*parameters).graphFilename); (*parameters).dampingFactor, (*parameters).graphFilename);
} }
(*parameters).realIterations = 0;
// Allocates memory for the pagerank vector // Allocates memory for the pagerank vector
(*pagerankVector) = (double *) malloc((*parameters).numberOfPages * sizeof(double)); (*pagerankVector) = (double *) malloc((*parameters).numberOfPages * sizeof(double));
double webUniformProbability = 1. / (*parameters).numberOfPages; double webUniformProbability = 1. / (*parameters).numberOfPages;
@ -230,9 +230,9 @@ void calculateNextPagerank(CsrSparseMatrix *transitionMatrix,
vectorNorm(*pagerankVector, vectorSize); vectorNorm(*pagerankVector, vectorSize);
for (int i=0; i<vectorSize; ++i) { for (int i=0; i<vectorSize; ++i) {
//(*pagerankVector)[i] += normDifference * webUniformProbability + (*pagerankVector)[i] += normDifference * webUniformProbability +
//linksFromConvergedPagesPagerankVector[i] + convergedPagerankVector[i]; linksFromConvergedPagesPagerankVector[i] + convergedPagerankVector[i];
(*pagerankVector)[i] += 0.5*normDifference* webUniformProbability +linksFromConvergedPagesPagerankVector[i] + convergedPagerankVector[i]; //(*pagerankVector)[i] += 0.5*normDifference* webUniformProbability +linksFromConvergedPagesPagerankVector[i] + convergedPagerankVector[i];
} }
} }
@ -417,33 +417,27 @@ void generateNormalizedTransitionMatrixFromFile(CsrSparseMatrix *transitionMatri
// Calculates the outdegree of each page and assigns the uniform probability // Calculates the outdegree of each page and assigns the uniform probability
// of transition to the elements of the corresponding row // of transition to the elements of the corresponding row
int* pageOutdegree = malloc((*parameters).numberOfPages*sizeof(int)); int* pageOutdegree = malloc((*parameters).numberOfPages*sizeof(int));
for (int i=0; i<(*parameters).numberOfPages; ++i){ for (int i=0; i<(*parameters).numberOfPages; ++i){
pageOutdegree[i] = 0; pageOutdegree[i] = 0;
} }
for (int i=0; i<numberOfEdges; ++i) { for (int i=0; i<numberOfEdges; ++i) {
int currentRow = tempMatrix.elements[i]->rowIndex; int currentRow = tempMatrix.elements[i]->rowIndex;
++pageOutdegree[currentRow];
if (currentRow == tempMatrix.elements[i]->rowIndex) {
++pageOutdegree[currentRow];
}
} }
for (int i=0; i<tempMatrix.size; ++i) { for (int i=0; i<tempMatrix.size; ++i) {
tempMatrix.elements[i]->value = 1./pageOutdegree[tempMatrix.elements[i]->rowIndex]; tempMatrix.elements[i]->value = 1./pageOutdegree[tempMatrix.elements[i]->rowIndex];
} }
free(pageOutdegree);
// Transposes the temporary transition matrix (P^T). // Transposes the temporary transition matrix (P^T).
transposeSparseMatrix(&tempMatrix); transposeSparseMatrix(&tempMatrix);
allocMemoryForCsr(transitionMatrix, numberOfEdges); allocMemoryForCsr(transitionMatrix, numberOfEdges);
// Transforms the temporary COO matrix to the desired CSR format // Transforms the temporary COO matrix to the desired CSR format
transformToCSR(tempMatrix, transitionMatrix); transformToCSR(tempMatrix, transitionMatrix);
//printCsrSparseMatrix(*transitionMatrix);
destroyCooSparseMatrix(&tempMatrix); destroyCooSparseMatrix(&tempMatrix);
fclose(graphFile); fclose(graphFile);
@ -481,7 +475,7 @@ int checkIncrement(int previousIndex, int maxIndex, char *programName) {
} }
void savePagerankToFile(char *filename, bool append, double *pagerankVector, void savePagerankToFile(char *filename, bool append, double *pagerankVector,
int vectorSize, int realIterations) { int vectorSize, int iteration) {
FILE *outputFile; FILE *outputFile;
if (append) { if (append) {
@ -494,13 +488,18 @@ void savePagerankToFile(char *filename, bool append, double *pagerankVector,
printf("Error while opening the output file.\n"); printf("Error while opening the output file.\n");
return; return;
} }
//Save numberofPages and convergence time
// Saves the pagerank vector
//fprintf(outputFile, "Iteration %d:\t", iteration);
double sum = 0;
for (int i=0; i<vectorSize; ++i) {
sum += pagerankVector[i];
}
//fprintf(outputFile, "%f\n", sum);
for (int i=0; i<vectorSize; ++i) { for (int i=0; i<vectorSize; ++i) {
fprintf(outputFile, "%f ", pagerankVector[i]); fprintf(outputFile, "%d = %.10g\n", i, pagerankVector[i]/sum);
} }
fprintf(outputFile, "\n");
//fprintf(outputFile, "%d\t", vectorSize);
//fprintf(outputFile, "%d\t", realIterations);
fclose(outputFile); fclose(outputFile);
} }

4
serial/serial_gs_pagerank_functions.h

@ -41,7 +41,7 @@ extern const int FILE_READ_BUFFER_SIZE;
// A data structure to conveniently hold the algorithm's parameters. // A data structure to conveniently hold the algorithm's parameters.
typedef struct parameters { typedef struct parameters {
int numberOfPages, maxIterations, realIterations; int numberOfPages, maxIterations;
double convergenceCriterion, dampingFactor; double convergenceCriterion, dampingFactor;
bool verbose, history; bool verbose, history;
char *outputFilename, *graphFilename; char *outputFilename, *graphFilename;
@ -72,7 +72,7 @@ void generateNormalizedTransitionMatrixFromFile(CsrSparseMatrix *transitionMatri
// Function savePagerankToFile appends or overwrites the pagerank vector // Function savePagerankToFile appends or overwrites the pagerank vector
// "pagerankVector" to the file with the filename supplied in the arguments. // "pagerankVector" to the file with the filename supplied in the arguments.
void savePagerankToFile(char *filename, bool append, double *pagerankVector, void savePagerankToFile(char *filename, bool append, double *pagerankVector,
int vectorSize, int realIterations); int vectorSize, int iteration);
// Function initialize allocates memory for the pagerank vector, reads the // Function initialize allocates memory for the pagerank vector, reads the
// dataset from the file and creates the transition probability distribution // dataset from the file and creates the transition probability distribution

Loading…
Cancel
Save