int main (int argc, char* argv[]){ int nodecount, *num_in_links, *num_out_links; int err = get_node_stat(&nodecount, &num_in_links, &num_out_links); if (err != 0) { return err; } node_t *nodehead; err = node_init(&nodehead, num_in_links, num_out_links, 0, nodecount); if (err != 0) { return err; } double start, end; GET_TIME(start); double damp_const = (1.0 - DAMPING_FACTOR) / nodecount; double *r = init_result_vector(nodecount, false); double *r_pre = init_result_vector(nodecount, true); page_rank(r, r_pre, num_out_links, num_in_links, nodecount, nodehead, damp_const); free(r_pre); GET_TIME(end); double delay = end - start; Lab4_saveoutput(r, nodecount, delay); node_destroy(nodehead, nodecount); free(num_in_links); free(num_out_links); free(r); }
int calculate(double *r, node *A) { int i, j; double *r_pre; double damp_const; damp_const = (1.0 - DAMPING_FACTOR) / n; int my_rank, comm_sz, local_n; double start = 0, end = 0; // for time MPI_Init(NULL, NULL); /* Get my process rank */ MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); /* Find out how many processes are being used */ MPI_Comm_size(MPI_COMM_WORLD, &comm_sz); r_pre = malloc(n * sizeof(double)); local_n = n / comm_sz; double still_err = 1; double *local_r = malloc(local_n * sizeof(double)); if (my_rank == 0) { GET_TIME(start); } while (still_err > EPSILON) { backup_vec(r, r_pre, n); for ( i = local_n * my_rank; i < local_n * (my_rank + 1); i++) { local_r[i - local_n * my_rank] = 0.0; for ( j = 0; j < A[i].size_Di; ++j) { local_r[i - local_n * my_rank] += r_pre[A[i].Di[j]] / A[A[i].Di[j]].li; } local_r[i - local_n * my_rank] *= DAMPING_FACTOR; local_r[i - local_n * my_rank] += damp_const; } MPI_Gather(local_r, local_n, MPI_DOUBLE, r, local_n, MPI_DOUBLE, 0, MPI_COMM_WORLD); if (my_rank == 0) { still_err = rel_err(r, r_pre, n); } MPI_Bcast(&still_err, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); MPI_Bcast(r, n, MPI_DOUBLE, 0, MPI_COMM_WORLD); } if (my_rank == 0) { GET_TIME(end); printf("%f\n", end-start); Lab4_saveoutput(r, n, end-start); } free(r_pre); MPI_Finalize(); return 0; }