From d552fb0bfde859412d12f593832cc9b407a1aabb Mon Sep 17 00:00:00 2001 From: mtzikara Date: Sun, 30 Sep 2018 23:40:34 +0200 Subject: [PATCH] Add files via upload --- serial/Makefile | 2 +- serial/serial_gs_pagerank.o | Bin 0 -> 3384 bytes serial/serial_gs_pagerank_functions.c | 62 ++++++++++++++------------ serial/serial_gs_pagerank_functions.h | 4 +- 4 files changed, 36 insertions(+), 32 deletions(-) create mode 100644 serial/serial_gs_pagerank.o 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 0000000000000000000000000000000000000000..16320163ddcd9b9ae3e58ec4349ecab7931e2bb9 GIT binary patch literal 3384 zcmbtWO>7%Q6duQchCrR9KnV(msboU}%_>fE2p}q3PMQUUQsqYq3az#Aj^icXwb@-$ zCkl|N1=U26Doz~XiiE_mst|P*4jecjajAMK2ZTUENJM~;iWJ_Pow3K8>;<0Wee-?u zy*F=WcgFMH%-q?oSd2)Eku#)?BumJhc)Ok9%?#-$$H~yj#Dv{Dibm&W7MA7~7br)) zLn~u8!Txdkys^ey!&#?=it{#e*O*C-qR(8KGN}dL@U4pDof08DJH(~iai(Qbr{cHb zMYwI$sZ+C8AycKOWTL|#&3;#3f%RRdRvnI>lP}5{+(%%L(Ht+66uZZqz-&tZ%ik9^qs58ZIC1A zM{rGmK?K(Ypa?z|U>LzC0*vu-w!h?3QrlEV-`D$|Jq|je?>xZWbKKp;_E-40g&zf~ znm2f>?;;oM_buOU#qRgLaa+t~E2#&q_HtbQ8rLV?T)D8<*yB0VO`bI=|IOFtF{bT9(Y_axc)~rPZ3_*XX1+rA>~G*EmYQo1WChCbfx? zfafuf@h2g%&3O{5_s51FIo5L>W_B9*r$pa7IMZyR|AVfxiNP!JmlNN`;xyKq7|bR5 zvx%PU!>H4|4cj+X!TWCDOS0v&x=%FI@C~A^dLGf-3IbH7wW&^+2FS{WhA|*8T)$Rr zDGHts@@0gO8KH|*i6*^f87uy!0A62N|Xs<2~n%sDFDbR z#|H1t@aN%2IQ|)s^uX`G#^Za$oa69QEhE5BDhX{I3r*JXqG*TXpB92Axw`$3anipg z;t#E#5b$rS9S&z{r@aEOyOZMR2RL)kGF^dBfWt9l{euBbE`Z0OP6#YrQ^ZNV#H$>(!`f?t3(Nl&gdR#D>z4EtXdJbEl%H~h z$aTW?!+k8{B|iXM_}c@DWCZyU0>#4hBM#S&@;k?Zpk>k72M|jNkN*&GM~y!w-v4Jo zn$|NseybzYKwUTaT^^ksz41eDA?S`DITNh!s0xukYUPpV{}~-)B8VS4W#qVWRXRiB zL@Yul4SD#9+`*pYC@K%Ga;M?BcS5O0?o$eUc#mS_WCWj!;Lia+K=u!0F6m#7&=({4 zN<^M|g#P^q{=*3VQ;}b;ob)8PAm!J*d{x})v;xuQaudWhEQeT*<>x$ip=!7ud)4q= zt4?@3>#o)C@5|#7xMNwHjPO6YOL(6mYs^PqDVoLxLb~Hy9^6%O+#YezAdmSaKcMiBEBuhch($ literal 0 HcmV?d00001 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