Example #1
0
bool SparseMatrix::multiply (const SystemVector& B, SystemVector& C) const
{
  C.resize(nrow,true);
  if (B.dim() < ncol) return false;

  const StdVector* Bptr = dynamic_cast<const StdVector*>(&B);
  if (!Bptr) return false;
  StdVector*       Cptr = dynamic_cast<StdVector*>(&C);
  if (!Cptr) return false;

  if (editable)
    for (const auto& it : elem)
      (*Cptr)(it.first.first) += it.second*(*Bptr)(it.first.second);
  else if (solver == SUPERLU) {
#ifdef notyet_USE_OPENMP // TODO: akva needs to fix this, gives wrong result!
    if (omp_get_max_threads() > 1) {
      std::vector<Vector> V(omp_get_max_threads());
#pragma omp parallel for schedule(static)
      for (size_t j = 1; j <= ncol; j++) {
        Vector& myV = V[omp_get_thread_num()];
        if (myV.empty())
          myV.resize(nrow);
        for (int i = IA[j-1]; i < IA[j]; i++)
          myV(JA[i]+1) += A[i]*(*Bptr)(j);
      }
      for (int j = 0; j < omp_get_max_threads(); j++)
        for (size_t i = 1; i <= V[j].size(); i++)
          (*Cptr)(i) += V[j](i);
    } else
#endif
    // Column-oriented format with 0-based indices
    for (size_t j = 1; j <= ncol; j++)
      for (int i = IA[j-1]; i < IA[j]; i++)
        (*Cptr)(JA[i]+1) += A[i]*(*Bptr)(j);
  }
  else // Row-oriented format with 1-based indices
    for (size_t i = 1; i <= nrow; i++)
      for (int j = IA[i-1]; j < IA[i]; j++)
        (*Cptr)(i) += A[j-1]*(*Bptr)(JA[j-1]);

  return true;
}
Example #2
0
int main(int argc, char **argv)
{
    std::vector<int> V; // create empty vector int type
    V.reserve(10);      // reserve mem for 10 elements int type

    /* equal: */
    std::vector<int> myVector(10); // allocate vector, init zeroes

    std::cout << "Original array: ";
    std::vector<int> myV(10); // create empty vector int type

    for (uint i = 0; i < myV.size(); ++i) {
        myV[i] = i;
        std::cout << myV[i] << ' ';
    }

    std::cout << "\nCopied array: ";
    std::vector<int> cpV(myV); // Init with copy
    for (uint i = 0; i < cpV.size(); ++i)
        std::cout << cpV[i] << ' ';

    std::cout << std::endl;
    return 0;
}