/* run this code with "conn-test < connectivity" */ #include #include #include struct tms begin_time, end_time; typedef long *long_p; typedef double *double_p; int main () { long **neighbors; double **coefficients; long *local_neighbors; double* local_coefficients; double sum; long *neighbor_size; double *vec1; double *vec2; long i, j, k, n; scanf ("%ld", &n); neighbors = (long **) malloc (n * sizeof (long_p)); coefficients = (double **) malloc (n * sizeof (double_p)); neighbor_size = (long *) malloc (n * sizeof (long)); for (i = 0; i < n; i++) { scanf ("%ld", &k); neighbors[i] = (long *) malloc (k * sizeof (long)); /* we'll zero the coefficients */ coefficients[i] = (double *) calloc (k, sizeof (double)); neighbor_size[i] = k; for (j = 0; j < k; j++) scanf ("%ld", neighbors[i] + j); } vec1 = (double *) calloc (n, sizeof (double)); (void) times(&begin_time); for (k = 0; k < 100; k++) { vec2 = (double *) calloc (n, sizeof (double)); for (i = 0; i < n; i++) { long m = neighbor_size[i]; local_neighbors = neighbors[i]; local_coefficients = coefficients[i]; if (m == 7) vec2[i] = local_coefficients[0] * vec1[local_neighbors[0]] + local_coefficients[1] * vec1[local_neighbors[1]] + local_coefficients[2] * vec1[local_neighbors[2]] + local_coefficients[3] * vec1[local_neighbors[3]] + local_coefficients[4] * vec1[local_neighbors[4]] + local_coefficients[5] * vec1[local_neighbors[5]] + local_coefficients[6] * vec1[local_neighbors[6]]; else if (m == 5) vec2[i] = local_coefficients[0] * vec1[local_neighbors[0]] + local_coefficients[1] * vec1[local_neighbors[1]] + local_coefficients[2] * vec1[local_neighbors[2]] + local_coefficients[3] * vec1[local_neighbors[3]] + local_coefficients[4] * vec1[local_neighbors[4]]; else { sum = 0.0; for (j = 0; j < m; j++) sum += local_coefficients[j] * vec1[local_neighbors[j]]; vec2[i] = sum; } } free (vec2); } (void) times(&end_time); printf("%ld\n", (long)(end_time.tms_utime+end_time.tms_stime-begin_time.tms_utime-begin_time.tms_stime)); return (n); }