struct preconditioner *new_preconditioner(int n, int nlevels) { struct preconditioner *precon = ec_malloc(sizeof(*precon)); precon->level = 0; precon->nmg = new_int_array(nlevels); for (int i = 0; i < nlevels; ++i) { precon->nmg[i] = max(2, (n - 1) / int_pow(2, i) + 1); if (precon->nmg[i] == 2) { nlevels = i + 1; break; } } precon->nlevels = nlevels; precon->geom = new_ptr_array(nlevels, 0, NULL); precon->basis = new_ptr_array(2 * nlevels - 1, 0, NULL); precon->poisson_diag = new_ptr_array(nlevels, 0, NULL); precon->helmholtz_diag = new_ptr_array(nlevels, 0, NULL); precon->stiffsum_scale = new_ptr_array(nlevels, 0, NULL); precon->dirichlet_mask = new_ptr_array(nlevels, 0, NULL); precon->sendcounts = new_ptr_array(nlevels, 0, NULL); precon->senddispls = new_ptr_array(nlevels, 0, NULL); precon->poisson_eigen_max = new_1d_array(nlevels); precon->helmholtz_eigen_max = new_1d_array(nlevels); return precon; }
int find_components(graph_t* g) { graph = g; total_vertices = get_num_vertices(graph); components = new_int_array(total_vertices); depth_first_search(graph, get_components); return num_components; }
void count_vertices_and_edges(int** num_vertices, int** num_edges) { int v, c; int* nv = new_int_array(num_components); int* ne = new_int_array(num_components); for (v = 0; v < total_vertices; v++) { nv[components[v]] += 1; ne[components[v]] += get_degree(graph, v); } for (c = 0; c < num_components; c++) ne[c] /= 2; *num_vertices = nv; *num_edges = ne; }
int main() { unique_ptr<int> v1 = new_int(); unique_ptr<int, array_deleter<int> > v2 = new_int_array(); unique_ptr<int, void(*)(void *)> v3 = malloc_int(); std::cout << *v1 << std::endl; v1.reset(NULL); return 0; }
void allocate_globals (matrix *A) { int n,i,bs,bs2; int *my_offsets; int num; int global_index; TAU_ub = R_ub = Z_ub = 0; n = A->n; bs = A->max_block_size; bs2 = bs*bs; J = new_index_set(NULL,max_dim,"J"); I = new_index_set(NULL,max_dim,"I"); J_tilde = new_index_set(NULL,max_dim,"J_tilde"); I_tilde = new_index_set(NULL,max_dim,"I_tilde"); remote_buf = new_int_array(NULL,A->maxnz,"remote_buf"); remote_rbuf = new_int_array(NULL,A->maxnz,"remote_rbuf"); remote_abuf = new_double_array(NULL,bs2*(A->maxnz+1),"remote_abuf"); is = new_index_set(NULL,max_dim,"is"); isres = new_index_set(NULL,max_dim,"isres"); res = new_double_array(NULL,bs2*max_dim,"res"); resb = new_double_array(NULL,bs2*max_dim,"resb"); n1 = new_int_array(NULL,nbsteps+1,"n1"); n2 = new_int_array(NULL,nbsteps,"n2"); Ahat_size = max_dim*maxapi; Ahat = new_double_array(NULL,Ahat_size,"Ahat"); if (debug) init_double_array(Ahat,Ahat_size,init_val); TAU_ptr = (int *) new_int_array(NULL,nbsteps+1,"TAU_ptr"); TAU_size = 1000; TAU = new_double_array(NULL,TAU_size,"TAU"); if (debug) init_double_array(TAU,TAU_size,init_val); R_size = 1000; R = new_double_array(NULL,R_size,"R"); if (debug) init_double_array(R,R_size,init_val); Z_size = 1000; Z = new_double_array(NULL,Z_size,"Z"); if (debug) init_double_array(Z,Z_size,init_val); rw = new_double_array(NULL,bs2*max_dim,"rw"); rs = new_double_array(NULL,bs2*max_dim,"rs"); rz = new_double_array(NULL,bs2*max_dim,"rz"); x = new_double_array(NULL,bs2*max_dim,"x"); xb = new_double_array(NULL,bs2*max_dim,"xb"); Qlist = (double **) mmalloc(nbsteps*sizeof(double *)); for (i=0; i<nbsteps; i++) Qlist[i] = NULL; temp_block = new_double_array(NULL,bs2,"temp_block"); minus_Bj = new_double_array(NULL,bs2,"minus_Bj"); sum_block = new_double_array(NULL,bs2,"sum_block"); nbits_of_int = sizeof(int)*8; if (nbits_of_int == 32) { log_nbits_of_int = 5;} else if (nbits_of_int == 64) { log_nbits_of_int = 6;} else { if (A->myid == 0) fprintf(stderr,"unsupported word size: %d\n",nbits_of_int); exit(1); } bitvec = (unsigned int *) mmalloc(sizeof(unsigned int)*A->n); if (! bitvec) { fprintf(stderr,"failed to malloc bitvec\n"); exit(1); } len_all = (int *) mmalloc(A->n*sizeof(int)); rlen_all = (int *) mmalloc(A->n*sizeof(int)); slen_all = (int *) mmalloc(A->n*sizeof(int)); #ifdef MPI ptr_offsets = (int *) mmalloc(A->n*sizeof(int *)); rptr_offsets = (int *) mmalloc(A->n*sizeof(int *)); A_offsets = (int *) mmalloc(A->n*sizeof(int *)); MPI_Barrier(A->comm); MPI_Allgatherv ((void *) A->lines->len, A->mnl, MPI_INT, (void *) len_all, A->mnls, A->start_indices, MPI_INT, A->comm); MPI_Barrier(A->comm); MPI_Allgatherv ((void *) A->lines->rlen, A->mnl, MPI_INT, (void *) rlen_all, A->mnls, A->start_indices, MPI_INT, A->comm); MPI_Barrier(A->comm); MPI_Allgatherv ((void *) A->lines->slen, A->mnl, MPI_INT, (void *) slen_all, A->mnls, A->start_indices, MPI_INT, A->comm); /* offsets for ptrs */ my_offsets = (int *) mmalloc(A->mnl*sizeof(int *)); my_offsets[0] = 0; for (i=1; i<A->mnl; i++) { my_offsets[i] = my_offsets[i-1] + A->lines->len[i-1]; } MPI_Barrier(A->comm); MPI_Allgatherv ((void *) my_offsets, A->mnl, MPI_INT, (void *) ptr_offsets, A->mnls, A->start_indices, MPI_INT, A->comm); /* offsets for rptrs */ my_offsets[0] = 0; for (i=1; i<A->mnl; i++) { my_offsets[i] = my_offsets[i-1] + A->lines->rlen[i-1]; } MPI_Barrier(A->comm); MPI_Allgatherv ((void *) my_offsets, A->mnl, MPI_INT, (void *) rptr_offsets, A->mnls, A->start_indices, MPI_INT, A->comm); /* offsets for coefficients */ my_offsets[0] = 0; global_index = A->my_start_index; for (i=1; i<A->mnl; i++) { bs = A->block_sizes[global_index]; num = bs*A->lines->slen[i-1]; my_offsets[i] = my_offsets[i-1] + num; global_index++; } MPI_Barrier(A->comm); MPI_Allgatherv ((void *) my_offsets, A->mnl, MPI_INT, (void *) A_offsets, A->mnls, A->start_indices, MPI_INT, A->comm); free(my_offsets); #endif }
static void initialise_multigrid_precon(struct element **sel) { const int nlevels = (*sel)->precon->nlevels; for (int i = 0; i < (*sel)->nel; ++i) { sel[i]->precon->basis[0] = sel[i]->basis; sel[i]->precon->geom[0] = sel[i]->geom; for (int j = 1; j < 2 * nlevels - 1; ++j) { const int n = sel[i]->precon->nmg[j / 2]; sel[i]->precon->basis[j] = new_gll_basis(n); compute_svv_derivative_matrix(sel[i]->precon->basis[j], sel[i]->params->svvn, sel[i]->params->svva); } for (int j = 2; j < 2 * nlevels - 1; j += 2) create_interpolation_matrices(sel[i]->precon->basis[j - 1], sel[i]->precon->basis[j]); for (int j = 1; j < nlevels; ++j) { struct basis *basis1 = sel[i]->precon->basis[j * 2]; struct basis *basis2 = sel[i]->precon->basis[j * 2 - 1]; sel[i]->precon->geom[j] = new_geometry(basis1, (*sel)->nel, (*sel)->geom->neltot); copy_geometry_connectivity(sel[i]->geom, sel[i]->precon ->geom[j]); struct trivec *grid = sel[i]->precon->geom[j]->grid; interpolate_to_grid(basis1, grid->x, basis2, sel[i]->precon->geom[j - 1]->grid->x); interpolate_to_grid(basis1, grid->y, basis2, sel[i]->precon->geom[j - 1]->grid->y); interpolate_to_grid(basis1, grid->z, basis2, sel[i]->precon->geom[j - 1]->grid->z); compute_geometry_transformations(sel[i]->precon ->geom[j], basis1); } } const int n = (*sel)->precon->nmg[0]; double ****tmp = new_4d_array(n, n, n, (*sel)->nel); for (int i = 0; i < (*sel)->nel; ++i) sel[i]->precon->inverse_mass = tmp[i]; free(tmp); for (int j = 0; j < nlevels; ++j) { const int n = sel[0]->precon->nmg[j]; double ****tmp1 = new_4d_array(n, n, n, (*sel)->nel); double ****tmp2 = new_4d_array(n, n, n, (*sel)->nel); double ****tmp3 = new_4d_array(n, n, n, (*sel)->nel); double ****tmp4 = new_4d_array(n, n, n, (*sel)->nel); for (int i = 0; i < (*sel)->nel; ++i) { sel[i]->precon->poisson_diag[j] = tmp1[i]; sel[i]->precon->helmholtz_diag[j] = tmp2[i]; sel[i]->precon->stiffsum_scale[j] = tmp3[i]; sel[i]->precon->dirichlet_mask[j] = tmp4[i]; } free(tmp1); free(tmp2); free(tmp3); free(tmp4); } for (int j = 1; j < nlevels; ++j) { (*sel)->precon->sendcounts[j] = new_int_array((*sel)->params ->nproc); (*sel)->precon->senddispls[j] = new_int_array((*sel)->params ->nproc); } }