int main(int argc, char *argv[]) { if (argc < 3) { std::cout << "Usage: " << argv[0] << " input-matrix output-matrix" << std::endl; return 1; } std::string fname_mat (argv[1]); bool verbose (true); // *** reading matrix in crs format from file std::ifstream in(fname_mat.c_str(), std::ios::in | std::ios::binary); double *A(NULL); unsigned *iA(NULL), *jA(NULL), n; if (in) { if (verbose) { std::cout << "reading matrix from " << fname_mat << " ... " << std::flush; } BaseLib::RunTime timer; timer.start(); CS_read(in, n, iA, jA, A); in.close(); timer.stop(); if (verbose) { std::cout << "ok, " << timer.elapsed() << " s" << std::endl; } } else { std::cout << "error reading matrix from " << fname_mat << std::endl; } unsigned nnz(iA[n]); if (verbose) { std::cout << "Parameters read: n=" << n << ", nnz=" << nnz << std::endl; } MathLib::CRSMatrix<double, unsigned> *mat (new MathLib::CRSMatrix<double, unsigned>(n, iA, jA, A)); const unsigned n_rows_cols_to_erase(300); unsigned *rows_cols_to_erase(new unsigned[n_rows_cols_to_erase]); for (unsigned k(0); k<n_rows_cols_to_erase; k++) { rows_cols_to_erase[k] = (k+1)*2; } BaseLib::RunTime timer; std::cout << "erasing " << n_rows_cols_to_erase << " rows and columns ... " << std::flush; timer.start(); mat->eraseEntries(n_rows_cols_to_erase, rows_cols_to_erase); timer.stop(); std::cout << "ok, " << timer.elapsed() << " s" << std::endl; delete[] rows_cols_to_erase; fname_mat = argv[2]; std::ofstream out (fname_mat.c_str(), std::ios::binary); CS_write (out, mat->getNRows(), mat->getRowPtrArray(), mat->getColIdxArray(), mat->getEntryArray()); out.close(); std::cout << "wrote " << fname_mat << " with " << mat->getNRows() << " rows and " << mat->getRowPtrArray()[mat->getNRows()] << " entries" << std::endl; delete mat; }
/** * @brief * -DIS_tcp_wflush - flush tcp/dis write buffer * * @par Functionality: * Writes "committed" data in buffer to file discriptor, * packs remaining data (if any), resets pointers * * @return int * @retval 0 success * @retval -1 error * */ int DIS_tcp_wflush(int fd) { size_t ct; int i; int j; char *pb; struct tcpdisbuf *tp; struct pollfd pollfds[1]; pbs_tcp_errno = 0; tp = tcp_get_writebuf(fd); pb = tp->tdis_thebuf; ct = tp->tdis_trail; if (ct == 0) return 0; while ((i = CS_write(fd, pb, ct)) != ct) { if (i == CS_IO_FAIL) { if (errno == EINTR) { continue; } if (errno != EAGAIN) { /* fatal error on write, abort output */ pbs_tcp_errno = errno; return (-1); } /* write would have blocked (EAGAIN returned) */ /* poll for socket to be ready to accept, if */ /* not ready in TIMEOUT_SHORT seconds, fail */ /* redo the poll if EINTR */ do { pollfds[0].fd = fd; pollfds[0].events = POLLOUT; pollfds[0].revents = 0; j = poll(pollfds, 1, PBS_DIS_TCP_TIMEOUT_SHORT * 1000); } while ((j == -1) && (errno == EINTR)); if (j == 0) { /* never came ready, return error */ /* pbs_tcp_errno will add to log message */ pbs_tcp_errno = EAGAIN; return (-1); } else if (j == -1) { /* some other error - fatal */ pbs_tcp_errno = errno; return (-1); } continue; /* socket ready, retry write */ } /* write succeeded, do more if needed */ ct -= i; pb += i; } tp->tdis_eod = tp->tdis_lead; tcp_pack_buff(tp); return 0; }