Exemplo n.º 1
0
int GaussSeidelPoisson1Drb(Vector u, double tol, int maxit)
{
  int it=0, i, j;
  double max = tol+1;
  Vector b = cloneVector(u);
  Vector r = cloneVector(u);
  Vector v = cloneVector(u);
  copyVector(b, u);
  fillVector(u, 0.0);
  while (max > tol && ++it < maxit) {
    copyVector(v, u);
    copyVector(u, b);
    collectVector(v);
    for (j=0;j<2;++j) {
#pragma omp parallel for schedule(static)
      for (i=1+j;i<r->len-1;i+=2) {
        u->data[i] += v->data[i-1];
        u->data[i] += v->data[i+1];
        r->data[i] = u->data[i]-(2.0+alpha)*v->data[i];
        u->data[i] /= (2.0+alpha);
        v->data[i] = u->data[i];
      }
      if (j == 0)
        collectVector(v);
    }
    max = maxNorm(r);
  }
  freeVector(b);
  freeVector(r);
  freeVector(v);

  return it;
}
Exemplo n.º 2
0
int GaussJacobiPoisson1D(Vector u, double tol, int maxit)
{
  int it=0, i;
  Vector b = cloneVector(u);
  Vector e = cloneVector(u);
  copyVector(b, u);
  fillVector(u, 0.0);
  double max = tol+1;
  while (max > tol && ++it < maxit) {
    copyVector(e, u);
    collectVector(e);
    copyVector(u, b);
#pragma omp parallel for schedule(static)
    for (i=1;i<e->len-1;++i) {
      u->data[i] += e->data[i-1];
      u->data[i] += e->data[i+1];
      u->data[i] /= (2.0+alpha);
    }
    axpy(e, u, -1.0);
    e->data[0] = e->data[e->len-1] = 0.0;
    max = maxNorm(e);
  }
  freeVector(b);
  freeVector(e);

  return it;
}
Exemplo n.º 3
0
void Poisson1D(Vector u, Vector v)
{
  int i;
  collectVector(v);
#pragma omp parallel for schedule(static)
  for (i=1;i<u->len-1;++i) {
    u->data[i] = (2.0+alpha)*v->data[i];
    u->data[i] -= v->data[i-1];
    u->data[i] -= v->data[i+1];
  }
  u->data[0] = u->data[u->len-1] = 0.0;
  v->data[0] = v->data[v->len-1] = 0.0;
}
Exemplo n.º 4
0
Vector collectBeforePre(Vector u)
{
  collectVector(u);
  Vector result;
  if (u->comm_rank == 0) {
    result=createVector(u->len-1);
    int len=u->len-1;
    dcopy(&len, u->data+1, &u->stride, result->data, &result->stride);
  } else if (u->comm_rank == u->comm_size-1) {
    result=createVector(u->len-1);
    int len=u->len-1;
    dcopy(&len, u->data, &u->stride, result->data, &result->stride);
  } else {
    result=createVector(u->len);
    copyVector(result, u);
  }

  return result;
}
Exemplo n.º 5
0
/***********************************************
 * API to collect all data allocated by LinBox *
 **********************************************/
void LinBoxCollect(){
	collectVector();
	collectBlackbox();
	collectElement();
	collectDomain();
}