void RpalParser::Bt() { pushProc("Bt()"); Bs(); while (_nt == "&") { read_token("&"); Bs(); build("&", 2); } popProc("Bt()"); }
int getuserid(bytes header) { bytes cookie = http_extract_param(header, Bs("Cookie")); bfound f = bfind(cookie, Bs("session=")); f = bfind(f.after, Bs(";")); int64_t session = btoi64(f.before); debug("User session: %ld", session); sqlite3_reset(selectuserid); sqlite3_bind_int64(selectuserid, 1, session); if(sqlite3_step(selectuserid) != SQLITE_ROW) return 0; return sqlite3_column_int(selectuserid, 0); }
int Ifpack_ShyLU::JustTryIt() { // Dummy function, To show the error in AztecOO, This works //cout << "Entering JustTryIt" << endl; AztecOO *solver; solver = slu_data_.innersolver; //cout << solver_ << endl; Epetra_Map BsMap(-1, slu_data_.Snr, slu_data_.SRowElems, 0, A_->Comm()); Epetra_MultiVector Xs(BsMap, 1); Epetra_MultiVector Bs(BsMap, 1); Xs.PutScalar(0.0); solver->SetLHS(&Xs); solver->SetRHS(&Bs); solver->Iterate(30, 1e-10); return 0; }
Bs Object::update() { return Bs(); }
int main(int argc, char** argv) { int rv = MPI_Init(&argc, &argv); assert(rv == MPI_SUCCESS); int size; rv = MPI_Comm_size(MPI_COMM_WORLD, &size); assert(rv == MPI_SUCCESS); int rank; rv = MPI_Comm_rank(MPI_COMM_WORLD, &rank); assert(rv == MPI_SUCCESS); MPI_Status status; assert(size == 2); assert(M % 2 == 0); double start_time = MPI_Wtime(); std::vector<Value> A(M + 1); std::vector<Value> B(M + 1); std::vector<Value> C(M + 1); std::vector<Value> F(M + 1); A[0] = Value(0.0, 0.0); // Not used. for (int m = 1; m <= M - 1; m++) { A[m] = Value(d / h / h, D / h / h); } A[M] = Value(1.0, 1.0); B[0] = Value(1.0, 1.0); for (int m = 1; m <= M - 1; m++) { B[m] = Value(-2.0 * d / h / h - 1.0 / tau, -2.0 * D / h / h - 1.0 / tau); } B[M] = Value(-1.0, -1.0); C[0] = Value(-1.0, -1.0); for (int m = 1; m <= M - 1; m++) { C[m] = Value(d / h / h, D / h / h); } C[M] = Value(0.0, 0.0); // Not used. std::vector<Value> As(M + 1); std::vector<Value> Bs(M + 1); std::vector<Value> Cs(M + 1); std::vector<Value> Fs(M + 1); As[0] = Value(0.0, 0.0); for (int m = 1; m <= M; m++) { As[m] = -A[m] * A[m - 1] / B[m - 1]; } Bs[0] = B[0] - C[0] * A[1] / B[1]; for (int m = 1; m <= M - 1; m++) { Bs[m] = B[m] - A[m] * C[m - 1] / B[m - 1] - C[m] * A[m + 1] / B[m + 1]; } Bs[M] = B[M] - A[M] * C[M - 1] / B[M - 1]; for (int m = 0; m <= M - 1; m++) { Cs[m] = -C[m] * C[m + 1] / B[m + 1]; } Cs[M] = Value(0.0, 0.0); std::vector<Value> prev_values(M + 1); std::vector<Value> curr_values(M + 1); InitializeValues(curr_values); std::vector<Value> P(M + 1); std::vector<Value> Q(M + 1); for (int n = 0; n < N; n++) { prev_values.swap(curr_values); F[0] = Value(0.0, 0.0); for (int m = 1; m <= M - 1; m++) { if (m % 2 == rank) { F[m].u = -prev_values[m].u / tau - f(prev_values[m]); F[m].v = -prev_values[m].v / tau - g(prev_values[m]); } } F[M] = Value(0.0, 0.0); for (int m = 1; m <= M - 1; m++) { if (m % 2 == rank) { rv = MPI_Send(&F[m].u, 1, MPI_DOUBLE, (rank + 1) % 2, m, MPI_COMM_WORLD); assert(rv == MPI_SUCCESS); rv = MPI_Send(&F[m].v, 1, MPI_DOUBLE, (rank + 1) % 2, m, MPI_COMM_WORLD); assert(rv == MPI_SUCCESS); } else { rv = MPI_Recv(&F[m].u, 1, MPI_DOUBLE, (rank + 1) % 2, m, MPI_COMM_WORLD, &status); assert(rv == MPI_SUCCESS); rv = MPI_Recv(&F[m].v, 1, MPI_DOUBLE, (rank + 1) % 2, m, MPI_COMM_WORLD, &status); assert(rv == MPI_SUCCESS); } } Fs[0] = F[0] - C[0] / B[1] * F[1]; for (int m = 1; m <= M - 1; m++) { if (m % 2 == rank) { Fs[m] = F[m] - A[m] / B[m - 1] * F[m - 1] - C[m] / B[m + 1] * F[m + 1]; } } Fs[M] = F[M] - A[M] / B[M - 1] * F[M - 1]; if (rank == 0) { P[0] = -Cs[0] / Bs[0]; Q[0] = Fs[0] / Bs[0]; } else { P[1] = -Cs[1] / Bs[1]; Q[1] = Fs[1] / Bs[1]; } for (int m = 2; m <= M; m++) { if (m % 2 == rank) { P[m] = -Cs[m] / (As[m] * P[m - 2] + Bs[m]); Q[m] = (Fs[m] - As[m] * Q[m - 2]) / (As[m] * P[m - 2] + Bs[m]); } } if (M % 2 == rank) { curr_values[M] = Q[M]; } else { curr_values[M - 1] = Q[M - 1]; } for (int m = M - 2; m >= 0; m--) { if (m % 2 == rank) { curr_values[m] = P[m] * curr_values[m + 2] + Q[m]; } } } for (int m = 0; m <= M; m++) { if (m % 2 == rank) { rv = MPI_Send(&curr_values[m].u, 1, MPI_DOUBLE, (rank + 1) % 2, m, MPI_COMM_WORLD); assert(rv == MPI_SUCCESS); rv = MPI_Send(&curr_values[m].v, 1, MPI_DOUBLE, (rank + 1) % 2, m, MPI_COMM_WORLD); assert(rv == MPI_SUCCESS); } else { rv = MPI_Recv(&curr_values[m].u, 1, MPI_DOUBLE, (rank + 1) % 2, m, MPI_COMM_WORLD, &status); assert(rv == MPI_SUCCESS); rv = MPI_Recv(&curr_values[m].v, 1, MPI_DOUBLE, (rank + 1) % 2, m, MPI_COMM_WORLD, &status); assert(rv == MPI_SUCCESS); } } if (rank == 0) { printf("%lf\n", MPI_Wtime() - start_time); /* for (int m = 0; m < M; m++) { double coord = X * m / M; printf("%lf %lf %lf\n", coord, curr_values[m].u, curr_values[m].v); } */ } rv = MPI_Finalize(); assert(rv == MPI_SUCCESS); return EXIT_SUCCESS; }
void MainWindow::on_actionBrightness_quantization_triggered() { QPixmap pixmap = pixmapItem->pixmap().copy(); QImage image = pixmap.toImage(); int width = image.width(); int height = image.height(); if (width == 0 || height == 0) { ui->statusBar->showMessage( tr("Error. Image bad size"), 3000 ); return; } std::vector<int> grays(width * height); for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { QRgb oldColor = image.pixel(x, y); int gray = qPow( 0.2126 * qPow(qRed(oldColor), 2.2) + 0.7152 * qPow(qGreen(oldColor), 2.2) + 0.0722 * qPow(qBlue(oldColor), 2.2), 1/2.2 ); grays[x + y * width] = gray; } std::vector<unsigned int> Rs(256, 0); std::vector<unsigned int> Gs(256, 0); std::vector<unsigned int> Bs(256, 0); std::vector<int> hist(256, 0); for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { int num = grays[x + y * width]; Rs[num] += qRed( image.pixel(x, y) ); Gs[num] += qGreen( image.pixel(x, y) ); Bs[num] += qBlue( image.pixel(x, y) ); ++hist[num]; } int quantsCountMaximum = 0; std::map<int, QRgb> colors; for (int i = 0; i < 256; ++i) { if (hist[i] == 0) continue; Rs[i] /= hist[i]; Gs[i] /= hist[i]; Bs[i] /= hist[i]; colors[i] = qRgb(Rs[i], Gs[i], Bs[i]); ++quantsCountMaximum; } DialogQuantization dialog; dialog.setQuantCountMaximum(quantsCountMaximum); if (dialog.exec() == QDialog::Rejected) return; int quantsCount = dialog.quantsCount(); double shift = 256 / quantsCount; double cur = 0.0; double next = 0.0; for (int i = 0; i < quantsCount; ++i) { next += shift; int c = qFloor(cur); int n = qFloor(next); int minC = 256; for (std::map<int, QRgb>::iterator it = colors.begin(); it != colors.end(); ++it) if (c <= (it->first) && (it->first) < n) if (it->first < minC) minC = it->first; QRgb newColor = colors[minC]; for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) { int num = grays[x + y * width]; if (c <= num && num < n) image.setPixel(x, y, newColor); else continue; } cur = next; } pixmap.convertFromImage(image); pixmapItem_2->setPixmap(pixmap); scene_2->setSceneRect(QRectF(pixmap.rect())); //ui->graphicsView_2->fitInView(scene_2->itemsBoundingRect(), Qt::KeepAspectRatio); calcHist(pixmap, hist_2, maxLevel_2); drawHist(pixmapItem_4, hist_2, maxLevel_2); }
int shylu_dist_solve<Epetra_CrsMatrix,Epetra_MultiVector>( shylu_symbolic<Epetra_CrsMatrix,Epetra_MultiVector> *ssym, shylu_data<Epetra_CrsMatrix,Epetra_MultiVector> *data, shylu_config<Epetra_CrsMatrix,Epetra_MultiVector> *config, const Epetra_MultiVector& X, Epetra_MultiVector& Y ) { int err; AztecOO *solver = 0; assert(X.Map().SameAs(Y.Map())); //assert(X.Map().SameAs(A_->RowMap())); const Epetra_MultiVector *newX; newX = &X; //rd_->redistribute(X, newX); int nvectors = newX->NumVectors(); // May have to use importer/exporter Epetra_Map BsMap(-1, data->Snr, data->SRowElems, 0, X.Comm()); Epetra_Map BdMap(-1, data->Dnr, data->DRowElems, 0, X.Comm()); Epetra_MultiVector Bs(BsMap, nvectors); Epetra_Import BsImporter(BsMap, newX->Map()); assert(BsImporter.SourceMap().SameAs(newX->Map())); assert((newX->Map()).SameAs(BsImporter.SourceMap())); Bs.Import(*newX, BsImporter, Insert); Epetra_MultiVector Xs(BsMap, nvectors); Epetra_SerialComm LComm; // Use Serial Comm for the local vectors. Epetra_Map LocalBdMap(-1, data->Dnr, data->DRowElems, 0, LComm); Epetra_MultiVector localrhs(LocalBdMap, nvectors); Epetra_MultiVector locallhs(LocalBdMap, nvectors); Epetra_MultiVector Z(BdMap, nvectors); Epetra_MultiVector Bd(BdMap, nvectors); Epetra_Import BdImporter(BdMap, newX->Map()); assert(BdImporter.SourceMap().SameAs(newX->Map())); assert((newX->Map()).SameAs(BdImporter.SourceMap())); Bd.Import(*newX, BdImporter, Insert); int lda; double *values; err = Bd.ExtractView(&values, &lda); assert (err == 0); int nrows = ssym->C->RowMap().NumMyElements(); // copy to local vector //TODO: OMP ? assert(lda == nrows); for (int v = 0; v < nvectors; v++) { for (int i = 0; i < nrows; i++) { err = localrhs.ReplaceMyValue(i, v, values[i+v*lda]); assert (err == 0); } } // TODO : Do we need to reset the lhs and rhs here ? if (config->amesosForDiagonal) { ssym->LP->SetRHS(&localrhs); ssym->LP->SetLHS(&locallhs); ssym->Solver->Solve(); } else { ssym->ifSolver->ApplyInverse(localrhs, locallhs); } err = locallhs.ExtractView(&values, &lda); assert (err == 0); // copy to distributed vector //TODO: OMP ? assert(lda == nrows); for (int v = 0; v < nvectors; v++) { for (int i = 0; i < nrows; i++) { err = Z.ReplaceMyValue(i, v, values[i+v*lda]); assert (err == 0); } } Epetra_MultiVector temp1(BsMap, nvectors); ssym->R->Multiply(false, Z, temp1); Bs.Update(-1.0, temp1, 1.0); Xs.PutScalar(0.0); Epetra_LinearProblem Problem(data->Sbar.get(), &Xs, &Bs); if (config->schurSolver == "Amesos") { Amesos_BaseSolver *solver2 = data->dsolver; data->LP2->SetLHS(&Xs); data->LP2->SetRHS(&Bs); //cout << "Calling solve *****************************" << endl; solver2->Solve(); //cout << "Out of solve *****************************" << endl; } else { if (config->libName == "Belos") { solver = data->innersolver; solver->SetLHS(&Xs); solver->SetRHS(&Bs); } else { // See the comment above on why we are not able to reuse the solver // when outer solve is AztecOO as well. solver = new AztecOO(); //solver.SetPrecOperator(precop_); solver->SetAztecOption(AZ_solver, AZ_gmres); // Do not use AZ_none solver->SetAztecOption(AZ_precond, AZ_dom_decomp); //solver->SetAztecOption(AZ_precond, AZ_none); //solver->SetAztecOption(AZ_precond, AZ_Jacobi); ////solver->SetAztecOption(AZ_precond, AZ_Neumann); //solver->SetAztecOption(AZ_overlap, 3); //solver->SetAztecOption(AZ_subdomain_solve, AZ_ilu); //solver->SetAztecOption(AZ_output, AZ_all); //solver->SetAztecOption(AZ_diagnostics, AZ_all); solver->SetProblem(Problem); } // What should be a good inner_tolerance :-) ? solver->Iterate(config->inner_maxiters, config->inner_tolerance); } Epetra_MultiVector temp(BdMap, nvectors); ssym->C->Multiply(false, Xs, temp); temp.Update(1.0, Bd, -1.0); //Epetra_SerialComm LComm; // Use Serial Comm for the local vectors. //Epetra_Map LocalBdMap(-1, data->Dnr, data->DRowElems, 0, LComm); //Epetra_MultiVector localrhs(LocalBdMap, nvectors); //Epetra_MultiVector locallhs(LocalBdMap, nvectors); //int lda; //double *values; err = temp.ExtractView(&values, &lda); assert (err == 0); //int nrows = data->Cptr->RowMap().NumMyElements(); // copy to local vector //TODO: OMP ? assert(lda == nrows); for (int v = 0; v < nvectors; v++) { for (int i = 0; i < nrows; i++) { err = localrhs.ReplaceMyValue(i, v, values[i+v*lda]); assert (err == 0); } } if (config->amesosForDiagonal) { ssym->LP->SetRHS(&localrhs); ssym->LP->SetLHS(&locallhs); ssym->Solver->Solve(); } else { ssym->ifSolver->ApplyInverse(localrhs, locallhs); } err = locallhs.ExtractView(&values, &lda); assert (err == 0); // copy to distributed vector //TODO: OMP ? assert(lda == nrows); for (int v = 0; v < nvectors; v++) { for (int i = 0; i < nrows; i++) { err = temp.ReplaceMyValue(i, v, values[i+v*lda]); assert (err == 0); } } // For checking faults //if (NumApplyInverse_ == 5) temp.ReplaceMyValue(0, 0, 0.0); Epetra_Export XdExporter(BdMap, Y.Map()); Y.Export(temp, XdExporter, Insert); Epetra_Export XsExporter(BsMap, Y.Map()); Y.Export(Xs, XsExporter, Insert); if (config->libName == "Belos" || config->schurSolver == "Amesos") { // clean up } else { delete solver; } return 0; }//end shylu_dist_solve <epetra,epetra>