IMPISD_BEGIN_NAMESPACE GaussianProcessInterpolation::GaussianProcessInterpolation( FloatsList x, Floats sample_mean, Floats sample_std, unsigned n_obs, UnivariateFunction *mean_function, BivariateFunction *covariance_function, Particle *sigma, double sparse_cutoff) : Object("GaussianProcessInterpolation%1%"), x_(x), n_obs_(n_obs), mean_function_(mean_function), covariance_function_(covariance_function), sigma_(sigma), cutoff_(sparse_cutoff) { // O(M) // store dimensions M_ = x.size(); N_ = x[0].size(); sigma_val_ = Scale(sigma_).get_nuisance(); // basic checks IMP_USAGE_CHECK(sample_mean.size() == M_, "sample_mean should have the same size as x"); IMP_USAGE_CHECK(sample_std.size() == M_, "sample_std should have the same size as x"); IMP_USAGE_CHECK(mean_function->get_ndims_x() == N_, "mean_function should have " << N_ << " input dimensions"); IMP_USAGE_CHECK(mean_function->get_ndims_y() == 1, "mean_function should have 1 output dimension"); IMP_USAGE_CHECK(covariance_function->get_ndims_x1() == N_, "covariance_function should have " << N_ << " input dimensions for first vector"); IMP_USAGE_CHECK(covariance_function->get_ndims_x2() == N_, "covariance_function should have " << N_ << " input dimensions for second vector"); IMP_USAGE_CHECK(covariance_function->get_ndims_y() == 1, "covariance_function should have 1 output dimension"); // set all flags to false = need update. force_mean_update(); force_covariance_update(); // compute needed matrices compute_I(sample_mean); compute_S(sample_std); }
int main() { vtx **P; vtx *gd; vtx *S; double hmin; P = (vtx**)malloc(3 * sizeof(vtx*)); gd = (vtx*)malloc(sizeof(vtx)); S = (vtx*)malloc(sizeof(vtx)); *(P + 0) = initialize_vertex(*(P + 0)); *(P + 1) = initialize_vertex(*(P + 1)); *(P + 2) = initialize_vertex(*(P + 2)); gd = initialize_vertex(gd); S = initialize_vertex(S); (*(P + 0))->coord_x = -3; (*(P + 0))->coord_y = -2; do{ gd = gradient(*(P + 0),gd); S = compute_S(gd, S); //show_vertex(gd); //show_vertex(S); hmin = compute_min(*(P + 0), S); printf("%.8lf\\\\\\hline\n",hmin); (*(P + 1))->coord_x = (*(P+0))->coord_x; (*(P + 1))->coord_y = (*(P+0))->coord_y; (*(P + 0))->coord_x = (*(P+0))->coord_x + hmin * S->coord_x; (*(P + 0))->coord_y = (*(P+0))->coord_y + hmin * S->coord_y; }while(distance(*(P + 0), *(P + 1)) > 1e-7); return 0; }
int main(int argc, char ** argv) { MPI_Init(&argc, &argv); int P, rank; MPI_Comm_size(MPI_COMM_WORLD, &P); MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (isPowerOfTwo(P) == false) { if (rank == 0) { printf("The number of processes is not a power of two \n"); } MPI_Finalize(); return 1; } if (argc > 1) { if (rank == 0) { printf("No argument needed\n"); } MPI_Finalize (); return 1; } int k; int k_max = 15, k_min = 3; double *err_vec, *S_vec; err_vec = calloc( k_max - k_min, sizeof(double) ); S_vec = calloc( k_max - k_min, sizeof(double) ); for ( k = k_min; k < k_max; k++ ) { int n = (int) pow(2, k); int np = (int) (n - n%P)/P; double *v, S = 0.0; MPI_Status status; int i; if ( rank == 0 ) { FILE *f; f = fopen("Error_Ex03.txt", "w"); fprintf(f, "Error Ex03, P = %d\n", P); v = calloc(n, sizeof(double)); compute_v(n, v); for (i = 1; i < P; i++ ){ MPI_Send( &v[np*i], np, MPI_DOUBLE, i, 0, MPI_COMM_WORLD); } double S_n = compute_S(np, v); MPI_Reduce(&S_n, &S, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); double err = compute_error(S); S_vec[k - k_min] = S; err_vec[k - k_min] = err; if (k == k_max-1) { print_vec(k_max-k_min, S_vec, err_vec); for ( i = 0; i < k_max-k_min; i++ ) { fprintf(f, "%1.16f\n", err_vec[i]); } } free(v); fclose(f); } else { double *v_n; if (rank == P-1) { v_n = calloc(np + n%P, sizeof(double)); } else { v_n = calloc(np, sizeof(double)); } MPI_Recv(v_n, np, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &status); double S_n = compute_S(np, v_n); MPI_Reduce(&S_n, &S, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); } } MPI_Finalize(); return 0; }
int main (int argc, char **argv) { double *S; /*Overlap matrix*/ double *H; /*Core Hamiltonian*/ double *D_new; /*Density matrix current*/ double *D_old; /*Density matrix previous*/ double *F; /*Fock matrix*/ erd_t *erd_inp; int maxit = MAX_IT; /*Max. no of iterations*/ int diis_lim = DIIS_LIM; int conv; /*convergence flag*/ basis_set_t *basis; /*Basis set Structure*/ double *scratch; double *S_sinv; /*Initialize Basis Set*/ basis = create_basis_set (); load_basis_set (basis, argv[1]); preprocess_basis_set (basis); fprintf (stderr, "\n DEBUG: Initialized basis set successfully \n"); fflush (stderr); /*Allocate memory for matrices*/ F = (double *)malloc (basis->nfunctions * basis->nfunctions * sizeof(double)); H = (double *)malloc (basis->nfunctions * basis->nfunctions * sizeof(double)); D_old = (double *)malloc (basis->nfunctions * basis->nfunctions * sizeof(double)); D_new = (double *)malloc (basis->nfunctions * basis->nfunctions * sizeof(double)); S = (double *)malloc (basis->nfunctions * basis->nfunctions * sizeof(double)); S_sinv = (double *)malloc (basis->nfunctions * basis->nfunctions * sizeof(double)); scratch = (double *)malloc (basis->nfunctions * basis->nfunctions * sizeof(double)); fprintf (stderr, "\n DEBUG: Initialized matrices successfully \n"); fflush (stderr); /*TODO: Initialize integrals package*/ erd_inp = init_erd (basis); fprintf (stderr, "\n DEBUG: Initialized ERD successfully \n"); fflush (stderr); /*Compute Core Hamiltonian and overlap matrix*/ compute_S (S, basis, 0, basis->nshells - 1, 0, basis->nshells - 1); compute_H (H, basis, 0, basis->nshells - 1, 0, basis->nshells - 1); fprintf (stderr, "\n DEBUG: Computed One electron stuff successfully \n"); fflush (stderr); /* printmatCM ("S", S, basis->nfunctions, basis->nfunctions); */ /* printmatCM ("H", H, basis->nfunctions, basis->nfunctions); */ /*Compute square root inverse of S*/ sqrtinv_matrix (basis->nfunctions, S, S_sinv, scratch); fprintf (stderr, "\n DEBUG: Computed Square root inverse of S \n"); fflush (stderr); /*TODO: SCF iterate until converged*/ conv = sscf (basis, erd_inp, H, S, S_sinv, basis->nfunctions, basis->nelectrons, maxit, diis_lim, D_old, D_new, F); if (!conv) { fprintf (stderr, "\n DEBUG: Convergence not achieved in %d iterations \n", maxit); fflush (stderr); } else { fprintf (stderr, "\n DEBUG: Convergence achieved! \n"); fflush (stderr); } /*TODO: Print energy, and eigenvalues*/ /*TODO: clean exit*/ destroy_basis_set (basis); destroy_erd (erd_inp); free (F); free (H); free (S); free (S_sinv); free (scratch); free (D_old); free (D_new); fprintf (stderr, "\n DEBUG: All allocated memory freed, Exiting. \n"); fflush (stderr); return 0; }
int main(int argc, char ** argv) { MPI_Init(&argc, &argv); int P, rank; MPI_Comm_size(MPI_COMM_WORLD, &P); // P = number of processes MPI_Comm_rank(MPI_COMM_WORLD, &rank); // Rank = numbering of each process if (isPowerOfTwo(P) == false) { if (rank == 0) { printf("The number of processes is not a power of two \n"); } MPI_Finalize(); return 1; } if (argc < 2) { if (rank == 0) { printf("Usage: ex3 k, n=pow(2,k)\n"); printf("n = vector/matrix size\n"); } MPI_Finalize (); return 1; } int k = atoi(argv[1]); int n = (int) pow(2, k); int np = (int) (n - n%P)/P; double *v, S = 0.0; MPI_Status status; int i; if ( rank == 0 ) { v = calloc(n, sizeof(double)); compute_v(n, v); for (i = 1; i < P; i++ ){ MPI_Send(&v[np*i], np, MPI_DOUBLE, i, 0, MPI_COMM_WORLD); } double S_n = compute_S(np, v); MPI_Reduce(&S_n, &S, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); printf("S = %1.16f\n", S); double err = compute_error(S); printf("Error = %1.16f\n", err); free(v); } else { double *v_n; if (rank == P-1) { v_n = calloc(np + n%P, sizeof(double)); } else { v_n = calloc(np, sizeof(double)); } MPI_Recv(v_n, np, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &status); double S_n = compute_S(np, v_n); free(v_n); MPI_Reduce(&S_n, &S, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); } MPI_Finalize(); return 0; }
int main(int argc, char ** argv) { MPI_Init(&argc, &argv); int P, rank; MPI_Comm_size(MPI_COMM_WORLD, &P); // size = number of processes nprocs MPI_Comm_rank(MPI_COMM_WORLD, &rank); // Numbering of process if (argc > 1) { // Only one process needs to print usage output if (rank == 0) { printf("Argument k needed.\n"); } MPI_Finalize (); return 1; } double start = MPI_Wtime(); int k = 14; int n = (int) pow(2, k); int np = (int) (n - n%P)/P; double *v, S = 0.0; MPI_Status status; int i; if ( rank == 0 ) { v = calloc(n, sizeof(double)); compute_v(n, v); for (i = 1; i < P; i++ ){ MPI_Send( &v[np*i], np, MPI_DOUBLE, i, 0, MPI_COMM_WORLD); } double S_n = compute_S(np, v); MPI_Reduce(&S_n, &S, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); double err = compute_error(S); printf("Error = %1.16f\n", err); free(v); } else { double *v_n; if (rank == P-1) { v_n = calloc(np + n%P, sizeof(double)); } else { v_n = calloc(np, sizeof(double)); } MPI_Recv(v_n, np, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &status); double S_n = compute_S(np, v_n); free(v_n); MPI_Reduce(&S_n, &S, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); } double end = MPI_Wtime(); if (rank == 0) printf("Elapsed time: %.16f seconds\n", end-start); MPI_Finalize(); return 0; }