static void block_cut() { EditLine *ed,*ed_next; int x_st, x_ed; char buf[MAXEDITLINE+1]; if (bkm.blkm==BLKM_y && bkm.y_st<GetLastNumber()) lists_delete(bkm.y_st, bkm.y_ed-1);else { ed=GetList(bkm.y_st); block_range(bkm.y_st, &bkm, &x_st, &x_ed); strcpy(buf, ed->buffer); buf[x_st]='\0'; ed_next=GetList(bkm.y_ed); block_range(bkm.y_ed, &bkm, &x_st, &x_ed); strcat(buf, ed_next->buffer+x_ed); Realloc(ed, buf); if (bkm.y_st+1<=bkm.y_ed) lists_delete(bkm.y_st+1, bkm.y_ed); } SetFileChangeFlag(); csr_lenew(); csr_setdy(GetRow()+bkm.y_st-GetLineOffset()); csr_setly(bkm.y_st); if (bkm.blkm==BLKM_x) csr_setlx(bkm.x_st); }
/** * @brief Locate blocks of contiguous free space of a given amount. * @param blocks The number of contiguous blocks to search for. * @return The index of the first block of the contiguous free memory, or -1 if not found. */ static int32_t locate_free(heap_state_t* heap_state, int32_t blocks) { int32_t n; int32_t heap_blocks; int32_t block=block_range(heap_state,&heap_blocks); uint32_t page=0; while(block < heap_blocks) { page = heap_state->heap_free_bitmap[block_offset(block)]; if ( ((page & ALL_BITS) != ALL_BITS) ) /* look at 32 blocks at a time... */ { /* out of the next 32 bits, see if we can start the sequence */ for(n=0; n < HEAP_BLOCKS_PER_PAGE; n++) { /* try each bit */ if (is_free_sequence(heap_state,block+n,blocks)) { return block+n; } } } block += HEAP_BLOCKS_PER_PAGE; /* we've looked at 32 blocks, skip past them */ } return -1; }
static bool bstack_copy() { EditLine *ed; char *p; long n; int x_st, x_ed; char buf[MAXEDITLINE+1]; if (bstack_nums>=MAX_bstack) { if (!keysel_ynq("ブロックバッファが一杯です。削除しますか?")) return FALSE; bstack_clear(); } bstack[bstack_nums].s= p= (char *)mem_alloc(block_size(&bkm)+1); bstack[bstack_nums].blkm= bkm.blkm; ++bstack_nums; *p='\0'; n= bkm.y_st; ed=GetList(n); while (block_range(n, &bkm, &x_st, &x_ed)) { if (ed->next==NULL) strcpy(buf,ed->buffer); else sprintf(buf,"%s\n",ed->buffer); buf[x_ed]='\0'; strcat(p, buf+x_st); ed=ed->next; ++n; } return TRUE; }
static int block_size(block_t *bp) { int ln; int x_st, x_ed; long n; ln=0; n=min(bp->y_st, bp->y_ed); while (block_range(n, &bkm, &x_st, &x_ed)) ln += x_ed-x_st, ++n; return ln; }
void FsStat::attr_stat(const SuperBlock * SB, VFile * vfile, Attributes * attr) { _gd_table = getGroupDescriptor(SB->block_size(), vfile, SB->offset()); bool sparse = SB->useRoFeatures(SuperBlock::_SPARSE_SUPERBLOCK, SB->ro_features_flags()); std::map<std::string, Variant_p > l; std::map<std::string, Variant_p > m; std::map<std::string, Variant_p > details; for (unsigned int i = 0; i < SB->group_number(); ++i) { std::ostringstream oss; std::string key; m.clear(); details.clear(); key = __build_range(inode_range(SB->inodes_in_group_number(), i)); m["Inode range"] = Variant_p(new Variant(key)); key = __build_range(block_range(i, SB->block_in_groups_number(), SB->blocks_number())); m["Block range"] = Variant_p(new Variant(key)); m["Directories number"] = Variant_p(new Variant(_gd_table[i].dir_nbr)); key = unallocated_blocks(SB->block_in_groups_number(), i, SB->blocks_number(), false); m["Unallocated blocks"] = Variant_p(new Variant(key)); key = unallocated_inodes(SB->inodes_in_group_number(), i, false); m["Unallocated inodes"] = Variant_p(new Variant(key)); oss << i; std::pair<uint32_t, uint32_t> sb_gd_bkp = sb_gd_backups(sparse, i, SB->block_in_groups_number()); if (sb_gd_bkp.first != sb_gd_bkp.second) { details["Superblock"] = Variant_p(new Variant(sb_gd_bkp.first)); details["Group descriptor"] = Variant_p(new Variant(sb_gd_bkp.second)); } details["Block bitmap"] = Variant_p(new Variant(_gd_table[i].block_bitmap_addr)); details["Inode bitmap"] = Variant_p(new Variant(_gd_table[i].inode_bitmap_addr)); std::pair<uint32_t, uint32_t> it_range = inode_table_range(i, (SuperBlock *)SB); key = __build_range(it_range); details["Inode table block range"] = Variant_p(new Variant(key)); key = __build_range(d_range(i, SB->block_in_groups_number(), it_range.second + 1)); details["Data blocks range"] = Variant_p(new Variant(key)); m["Details"] = Variant_p(new Variant(details)); l[std::string("Group ") + oss.str()] = Variant_p(new Variant(m)); } (*attr)[std::string("File system layout")] = Variant_p(new Variant(l)); }
void FsStat::groupInformations(SuperBlock * SB, VFile * vfile) { _gd_table = getGroupDescriptor(SB->block_size(), vfile, SB->offset()); bool sparse = SB->useRoFeatures(SuperBlock::_SPARSE_SUPERBLOCK, SB->ro_features_flags()); std::cout << "-------- GROUPS --------" << std::endl; for (unsigned int i = 0; i < SB->group_number(); ++i) { std::cout << "Group " << i << std::endl; std::pair<uint32_t, uint32_t> i_range = inode_range(SB->inodes_in_group_number(), i); std::cout << "Inode range : " << i_range.first << " -> " << i_range.second << std::endl; std::pair<uint32_t, uint32_t> b_range = block_range(i, SB->block_in_groups_number(), SB->blocks_number()); std::cout << "Blocks range : " << b_range.first << " -> " << b_range.second << std::endl; sparse_option(sparse, i, SB->block_in_groups_number()); std::cout << "\tBlock bitmap : " << _gd_table[i].block_bitmap_addr << std::endl; std::cout << "\tInode bitmap : " << _gd_table[i].inode_bitmap_addr << std::endl; std::pair<uint32_t, uint32_t> it_range = inode_table_range(i, SB); std::cout << "\tInode table : " << it_range.first << " -> " << it_range.second << std::endl; std::pair<uint32_t, uint32_t> data_range = d_range(i, SB->block_in_groups_number(), it_range.second + 1); std::cout << "\tData range : " << data_range.first << " -> " << data_range.second << std::endl; std::cout << "Directories number : " << _gd_table[i].dir_nbr << std::endl; unallocated_inodes(SB->inodes_in_group_number(), i); unallocated_blocks(SB->block_in_groups_number(), i, SB->blocks_number()); std::cout << std::endl; } }
void lu_factorize(matrix<SCALARTYPE, viennacl::row_major> & A) { typedef matrix<SCALARTYPE, viennacl::row_major> MatrixType; std::size_t max_block_size = 32; std::size_t num_blocks = (A.size2() - 1) / max_block_size + 1; std::vector<SCALARTYPE> temp_buffer(A.internal_size2() * max_block_size); // Iterate over panels for (std::size_t panel_id = 0; panel_id < num_blocks; ++panel_id) { std::size_t row_start = panel_id * max_block_size; std::size_t current_block_size = std::min<std::size_t>(A.size1() - row_start, max_block_size); viennacl::range block_range(row_start, row_start + current_block_size); viennacl::range remainder_range(row_start + current_block_size, A.size1()); // // Perform LU factorization on panel: // // Read from matrix to buffer: viennacl::backend::memory_read(A.handle(), sizeof(SCALARTYPE) * row_start * A.internal_size2(), sizeof(SCALARTYPE) * current_block_size * A.internal_size2(), &(temp_buffer[0])); // Factorize (kij-version): for (std::size_t k=0; k < current_block_size - 1; ++k) { for (std::size_t i=k+1; i < current_block_size; ++i) { temp_buffer[row_start + i * A.internal_size2() + k] /= temp_buffer[row_start + k * A.internal_size2() + k]; // write l_ik SCALARTYPE l_ik = temp_buffer[row_start + i * A.internal_size2() + k]; for (std::size_t j = row_start + k + 1; j < A.size1(); ++j) temp_buffer[i * A.internal_size2() + j] -= l_ik * temp_buffer[k * A.internal_size2() + j]; // l_ik * a_kj } } // Write back: viennacl::backend::memory_write(A.handle(), sizeof(SCALARTYPE) * row_start * A.internal_size2(), sizeof(SCALARTYPE) * current_block_size * A.internal_size2(), &(temp_buffer[0])); if (remainder_range.size() > 0) { // // Compute L_12 = [ (U_11)^{T}^{-1} A_{21}^T ]^T // viennacl::matrix_range<MatrixType> U_11(A, block_range, block_range); viennacl::matrix_range<MatrixType> A_21(A, remainder_range, block_range); viennacl::linalg::inplace_solve(trans(U_11), trans(A_21), viennacl::linalg::lower_tag()); // // Update remainder of A // viennacl::matrix_range<MatrixType> L_21(A, remainder_range, block_range); viennacl::matrix_range<MatrixType> U_12(A, block_range, remainder_range); viennacl::matrix_range<MatrixType> A_22(A, remainder_range, remainder_range); A_22 -= viennacl::linalg::prod(L_21, U_12); } } }
void lu_factorize(matrix<SCALARTYPE, viennacl::column_major> & A) { typedef matrix<SCALARTYPE, viennacl::column_major> MatrixType; std::size_t max_block_size = 32; std::size_t num_blocks = (A.size1() - 1) / max_block_size + 1; std::vector<SCALARTYPE> temp_buffer(A.internal_size1() * max_block_size); // Iterate over panels for (std::size_t panel_id = 0; panel_id < num_blocks; ++panel_id) { std::size_t col_start = panel_id * max_block_size; std::size_t current_block_size = std::min<std::size_t>(A.size1() - col_start, max_block_size); viennacl::range block_range(col_start, col_start + current_block_size); viennacl::range remainder_range(col_start + current_block_size, A.size1()); // // Perform LU factorization on panel: // // Read from matrix to buffer: viennacl::backend::memory_read(A.handle(), sizeof(SCALARTYPE) * col_start * A.internal_size1(), sizeof(SCALARTYPE) * current_block_size * A.internal_size1(), &(temp_buffer[0])); // Factorize (kji-version): for (std::size_t k=0; k < current_block_size; ++k) { SCALARTYPE a_kk = temp_buffer[col_start + k + k * A.internal_size1()]; for (std::size_t i=col_start+k+1; i < A.size1(); ++i) temp_buffer[i + k * A.internal_size1()] /= a_kk; // write l_ik for (std::size_t j=k+1; j < current_block_size; ++j) { SCALARTYPE a_kj = temp_buffer[col_start + k + j * A.internal_size1()]; for (std::size_t i=col_start+k+1; i < A.size1(); ++i) temp_buffer[i + j * A.internal_size1()] -= temp_buffer[i + k * A.internal_size1()] * a_kj; // l_ik * a_kj } } // Write back: viennacl::backend::memory_write(A.handle(), sizeof(SCALARTYPE) * col_start * A.internal_size1(), sizeof(SCALARTYPE) * current_block_size * A.internal_size1(), &(temp_buffer[0])); if (remainder_range.size() > 0) { // // Compute U_12: // viennacl::matrix_range<MatrixType> L_11(A, block_range, block_range); viennacl::matrix_range<MatrixType> A_12(A, block_range, remainder_range); viennacl::linalg::inplace_solve(L_11, A_12, viennacl::linalg::unit_lower_tag()); // // Update remainder of A // viennacl::matrix_range<MatrixType> L_21(A, remainder_range, block_range); viennacl::matrix_range<MatrixType> U_12(A, block_range, remainder_range); viennacl::matrix_range<MatrixType> A_22(A, remainder_range, remainder_range); A_22 -= viennacl::linalg::prod(L_21, U_12); } } }