/* * When the path is realloc'd, have to fix all of the pointers in structures * already returned. */ static void wi_fts_padjust(WI_FTS *sp, WI_FTSENT *head) { WI_FTSENT *p; char *addr = sp->fts_path; /* Adjust the current set of children. */ for (p = sp->fts_child; p; p = p->fts_link) ADJUST(p); /* Adjust the rest of the tree, including the current level. */ for (p = head; p->fts_level >= WI_FTS_ROOTLEVEL;) { ADJUST(p); p = p->fts_link ? p->fts_link : p->fts_parent; } }
void rect2di::set(VECT2DI *p_vect, int num) { VECT2DI min,max; ADJUST_PREP_INT(min.x,max.x); ADJUST_PREP_INT(min.y,max.y); int i; for(i = 0; i < num; i++) { ADJUST(min.x,max.x,p_vect[i].x); ADJUST(min.y,max.y,p_vect[i].y); } set(&min,&max); }
//initializes the root directory void init_root_dir(){ dir_entry_t *buffer = malloc(ADJUST(MAX_FILES*sizeof(dir_entry_t))); if(buffer == NULL){ return; } int i; for(i = 0; i < MAX_FILES; i++){ //set up directory values buffer[i] = (dir_entry_t){.name = "\0",.inode_idx = LIMIT}; } write_blocks(2, DIRECTORY_SIZE, buffer); free(buffer); return; } //method to create "free" list void init_free_list(){ unsigned int *buffer = malloc(BLOCK_SIZE); if (buffer == NULL){ return; } int i; for(i = 0; i < (BLOCK_SIZE)/sizeof(unsigned int); i++){ //sets all bits to 1 buffer[i] = ~0; } write_blocks(1, FREELIST_SIZE, buffer); free(buffer); return; }
/* * When the path is realloc'd, have to fix all of the pointers in structures * already returned. */ static void fts_padjust(FTS * sp) { FTSENT *p; char *addr = sp->fts_path; #define ADJUST1(p) { \ if ((p)->fts_accpath == (p)->fts_path) \ (p)->fts_accpath = (addr); \ (p)->fts_path = addr; \ } /* Adjust the current set of children. */ for (p = sp->fts_child; p; p = p->fts_link) ADJUST(p, addr); /* Adjust the rest of the tree. */ for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { ADJUST(p, addr); p = p->fts_link ? p->fts_link : p->fts_parent; } }
/* * When the path is realloc'd, have to fix all of the pointers in structures * already returned. */ static void fts_padjust(FTS *sp, FTSENT *head) { FTSENT *p; char *addr = sp->fts_path; #define ADJUST(p) do { \ if ((p)->fts_accpath != (p)->fts_name) { \ (p)->fts_accpath = \ (char *)addr + ((p)->fts_accpath - (p)->fts_path); \ } \ (p)->fts_path = addr; \ } while (0) /* Adjust the current set of children. */ for (p = sp->fts_child; p; p = p->fts_link) ADJUST(p); /* Adjust the rest of the tree, including the current level. */ for (p = head; p->fts_level >= FTS_ROOTLEVEL;) { ADJUST(p); p = p->fts_link ? p->fts_link : p->fts_parent; } }
//creates and initializes the inode table void init_inode_table(){ inode_t *buffer = malloc(ADJUST((MAX_FILES+1)*sizeof(inode_t))); if(buffer == NULL){ return; } int i; //set up inode table for(i = 0; i < MAX_FILES+1; i++){ buffer[i].exists = 0; // existence check buffer[i].link_cnt = 0; // link count buffer[i].size = 0; // size buffer[i].ref_ptr = LIMIT; // indirect pointer int j; for(j = 0; j < 12; j++){ buffer[i].data_ptrs[j] = LIMIT; //data/direct pointers } } write_blocks(INODE_TABLE, INODE_TABLE_SIZE, buffer); free(buffer); return; }
int main(void) { Seawolf_loadConfig("../conf/seawolf.conf"); Seawolf_init("Thruster Controller"); initscr(); cbreak(); noecho(); keypad(stdscr, TRUE); int c; char* display = " \n\ Thruster Controller \n\ \n\ Bow: %3.2f \n\ Port: %3.2f \n\ Star: %3.2f \n\ Stern: %3.2f \n\ StrafeT: %3.2f \n\ StrafeB: %3.2f \n\ "; float bow=0.0, stern=0.0, port=0.0, star=0.0, strafet=0.0, strafeb=0.0; int addsub = 1; /* Turn off drivers */ Var_set("Port", 0.0); Var_set("Star", 0.0); Var_set("Bow", 0.0); Var_set("Stern", 0.0); Var_set("StrafeT", 0.0); Var_set("StrafeB", 0.0); while(true) { printw(display, bow, port, star, stern, strafet, strafeb); refresh(); c = getch(); clear(); addsub = -1; if(isupper(c)) { addsub = 1; } c = tolower(c); switch(c) { case 'w': bow = ADJUST(bow + (addsub * STEP)); Var_set("Bow", bow); break; case 's': stern = ADJUST(stern + (addsub * STEP)); Var_set("Stern", stern); break; case 'a': port = ADJUST(port + (addsub * STEP)); Var_set("Port", port); break; case 'd': star = ADJUST(star + (addsub * STEP)); Var_set("Star", star); break; case 'z': strafet = ADJUST(strafet + (addsub * STEP)); Var_set("StrafeT", strafet); break; case 'x': strafeb = ADJUST(strafeb + (addsub * STEP)); Var_set("StrafeB", strafeb); break; } if(c == 'q') { break; } } endwin(); /* Turn off drivers */ Var_set("Port", 0); Var_set("Star", 0); Var_set("Bow", 0); Var_set("Stern", 0); Var_set("StrafeT", 0); Var_set("StrafeB", 0); Seawolf_close(); return 0; }
void mksfs(int fresh){ //Implement mksfs here if (fresh == 1){ //deletes fs if it already exists if(access(DISK_FILE, F_OK) != -1){ unlink(DISK_FILE); } //fs creation printf("Initalizing sfs\n"); init_fresh_disk(DISK_FILE, BLOCK_SIZE, MAX_BLOCKS); //zero_everything(); // writes superblock to the first block printf("Writing superblocks\n"); init_superblock(); write_blocks(0, 1, &sb); // write the inode table to the 2nd block printf("Writing inode table\n"); init_inode_table(); //add_root_dir_inode(); //add_dummy_file_inode(); //write_blocks(1, 1, &inode_table); // creates free list init_free_list(); // write root directory data to the 3rd block printf("Writing root dir\n"); init_root_dir(); //allocate memory for directory inode inode_t *inode = malloc(ADJUST((MAX_FILES+1)*sizeof(inode_t))); read_blocks(INODE_TABLE, INODE_TABLE_SIZE, inode); if(inode == NULL){ return; } //set first inode to point to directory inode[0].size = DIRECTORY_SIZE*BLOCK_SIZE; inode[0].link_cnt = DIRECTORY_SIZE; inode[0].exists = 1; //check to see if we need to use ref_ptr //if(DIRECTORY_SIZE > 12){ //inode[0].ref_ptr = search(); //setAlloc(inode[0].ref_ptr); //unsigned int *buffer = malloc(BLOCK_SIZE); //write_blocks(19 + inode[0].ref_ptr, 1, buffer); //free(buffer); //assign the pointers the location of directory files int i; for(i = 0; i < DIRECTORY_SIZE; i++){ if(i > 11){ unsigned int *buffer = malloc(BLOCK_SIZE); read_blocks(19+ inode[0].ref_ptr, 1, buffer); buffer[i - 12] = 2 + i; write_blocks(19+ inode[0].ref_ptr, 1, buffer); free(buffer); } else{ inode[0].data_ptrs[i] = 2 + i; } } //update inode and free memory write_blocks(INODE_TABLE, INODE_TABLE_SIZE, inode); free(inode); } else if (fresh == 0){ if(init_disk(DISK_FILE, BLOCK_SIZE, MAX_BLOCKS) != 0){ printf("Error initializing disk\n"); return; } } //allocate main memory for filesystem data structures int *superblock = malloc(BLOCK_SIZE*SUPERBLOCK_SIZE); if(superblock == NULL){ printf("Error allocating memory for superblock\n"); return; } read_blocks(0, SUPERBLOCK_SIZE, superblock); //allocate main memory for directory root_dir = malloc(ADJUST(sizeof(dir_entry_t)*MAX_FILES)); if(root_dir == NULL){ printf("Error allocating memory for root directory\n"); return; } read_blocks(2, DIRECTORY_SIZE, root_dir); //allocate memory for inode table inode_table = malloc(ADJUST(sizeof(inode_t)*(MAX_FILES+1))); if(inode_table == NULL){ printf("Error allocating memory for inode table"); return; } read_blocks(INODE_TABLE, INODE_TABLE_SIZE, inode_table); fileCount = 0; fd_table = NULL; return; }
/****************************************************************************** * hypre_BoomerAMGFitInterpVectors * This routine for updating the interp operator to interpolate the supplied smooth vectors with a L.S. fitting. This code (varient 0) was used for the Baker, Kolev and Yang elasticity paper in section 3 to evaluate the least squares fitting methed proposed by Stuben in his talk (see paper for details). So this code is basically a post-processing step that performs the LS fit (the size and sparsity of P do not change). Note: truncation only works correctly for 1 processor - needs to just use the other truncation rouitne Variant = 0: do L.S. fit to existing interp weights (default) Variant = 1: extends the neighborhood to incl. other unknowns on the same node - ASSUMES A NODAL COARSENING, ASSUMES VARIABLES ORDERED GRID POINT, THEN UNKNOWN (e.g., u0, v0, u1, v1, etc. ), AND AT MOST 3 FCNS (NOTE: **only** works with 1 processor) This code is not compiled or accessible through hypre at this time (it was not particularly effective - compared to the LN and GM approaches), but is checked-in in case there is interest in the future. ******************************************************************************/ HYPRE_Int hypre_BoomerAMGFitInterpVectors( hypre_ParCSRMatrix *A, hypre_ParCSRMatrix **P, HYPRE_Int num_smooth_vecs, hypre_ParVector **smooth_vecs, hypre_ParVector **coarse_smooth_vecs, double delta, HYPRE_Int num_functions, HYPRE_Int *dof_func, HYPRE_Int *CF_marker, HYPRE_Int max_elmts, double trunc_factor, HYPRE_Int variant, HYPRE_Int level) { HYPRE_Int i,j, k; HYPRE_Int one_i = 1; HYPRE_Int info; HYPRE_Int coarse_index;; HYPRE_Int num_coarse_diag; HYPRE_Int num_coarse_offd; HYPRE_Int num_nonzeros = 0; HYPRE_Int coarse_point = 0; HYPRE_Int k_size; HYPRE_Int k_alloc; HYPRE_Int counter; HYPRE_Int *piv; HYPRE_Int tmp_int; HYPRE_Int num_sends; double *alpha; double *Beta; double *w; double *w_old; double *B_s; double tmp_double; double one = 1.0; double mone = -1.0;; double *vec_data; hypre_CSRMatrix *P_diag = hypre_ParCSRMatrixDiag(*P); hypre_CSRMatrix *P_offd = hypre_ParCSRMatrixOffd(*P); double *P_diag_data = hypre_CSRMatrixData(P_diag); HYPRE_Int *P_diag_i = hypre_CSRMatrixI(P_diag); HYPRE_Int *P_diag_j = hypre_CSRMatrixJ(P_diag); double *P_offd_data = hypre_CSRMatrixData(P_offd); HYPRE_Int *P_offd_i = hypre_CSRMatrixI(P_offd); HYPRE_Int *P_offd_j = hypre_CSRMatrixJ(P_offd); HYPRE_Int num_rows_P = hypre_CSRMatrixNumRows(P_diag); HYPRE_Int P_diag_size = P_diag_i[num_rows_P]; HYPRE_Int P_offd_size = P_offd_i[num_rows_P]; HYPRE_Int num_cols_P_offd = hypre_CSRMatrixNumCols(P_offd); HYPRE_Int *col_map_offd_P; hypre_CSRMatrix *A_offd = hypre_ParCSRMatrixOffd(A); HYPRE_Int num_cols_A_offd = hypre_CSRMatrixNumCols(A_offd); hypre_ParCSRCommPkg *comm_pkg = hypre_ParCSRMatrixCommPkg(*P); hypre_ParCSRCommHandle *comm_handle; MPI_Comm comm; double *dbl_buf_data; double *smooth_vec_offd = NULL; double *offd_vec_data; HYPRE_Int index, start; HYPRE_Int *P_marker; HYPRE_Int num_procs; hypre_ParVector *vector; HYPRE_Int new_nnz, orig_start, j_pos, fcn_num, num_elements; HYPRE_Int *P_diag_j_new; double *P_diag_data_new; HYPRE_Int adjust_3D[] = {1, 2, -1, 1, -2, -1}; HYPRE_Int adjust_2D[] = {1, -1}; HYPRE_Int *adjust_list; if (variant ==1 && num_functions > 1) { /* First add new entries to P with value 0.0 corresponding to weights from other unknowns on the same grid point */ /* Loop through each row */ new_nnz = P_diag_size*num_functions; /* this is an over-estimate */ P_diag_j_new = hypre_CTAlloc(HYPRE_Int, new_nnz); P_diag_data_new = hypre_CTAlloc (double, new_nnz); if (num_functions ==2) adjust_list = adjust_2D; else if (num_functions ==3) adjust_list = adjust_3D; j_pos = 0; orig_start = 0; /* loop through rows */ for (i=0; i < num_rows_P; i++) { fcn_num = (HYPRE_Int) fmod(i, num_functions); if (fcn_num != dof_func[i]) printf("WARNING - ROWS incorrectly ordered!\n"); /* loop through elements */ num_elements = P_diag_i[i+1] - orig_start; /* add zeros corrresponding to other unknowns */ if (num_elements > 1) { for (j=0; j < num_elements; j++) { P_diag_j_new[j_pos] = P_diag_j[orig_start+j]; P_diag_data_new[j_pos++] = P_diag_data[orig_start+j]; for (k=0; k < num_functions-1; k++) { P_diag_j_new[j_pos] = P_diag_j[orig_start+j]+ ADJUST(fcn_num,k); P_diag_data_new[j_pos++] = 0.0; } } } else if (num_elements == 1)/* only one element - just copy to new */ { P_diag_j_new[j_pos] = P_diag_j[orig_start]; P_diag_data_new[j_pos++] = P_diag_data[orig_start]; } orig_start = P_diag_i[i+1]; if (num_elements > 1) P_diag_i[i+1] = P_diag_i[i] + num_elements*num_functions; else P_diag_i[i+1] = P_diag_i[i] + num_elements; if (j_pos != P_diag_i[i+1]) printf("Problem!\n"); }/* end loop through rows */ /* modify P */ hypre_TFree(P_diag_j); hypre_TFree(P_diag_data); hypre_CSRMatrixJ(P_diag) = P_diag_j_new; hypre_CSRMatrixData(P_diag) = P_diag_data_new; hypre_CSRMatrixNumNonzeros(P_diag) = P_diag_i[num_rows_P]; P_diag_j = P_diag_j_new; P_diag_data = P_diag_data_new; /* check if there is already a comm pkg - if so, destroy*/ if (comm_pkg) { hypre_MatvecCommPkgDestroy(comm_pkg ); comm_pkg = NULL; } } /* end variant == 1 and num functions > 0 */