void
doNameAnnotations(iface::cellml_api::Model* aModel,
                  iface::cellml_services::CodeGenerator* aCG)
{
  // Make an annotation set...
  iface::cellml_services::AnnotationToolService* ats
    (CreateAnnotationToolService());
  iface::cellml_services::AnnotationSet* as(ats->createAnnotationSet());
  ats->release_ref();

  aCG->useAnnoSet(as);

  // Now we go through all variables in the model and set their annotations...
  iface::cellml_api::CellMLComponentSet* ccs = aModel->allComponents();

  iface::cellml_api::CellMLComponentIterator* cci = ccs->iterateComponents();
  ccs->release_ref();

  iface::cellml_api::CellMLComponent* comp;
  while ((comp = cci->nextComponent()) != NULL)
  {
    iface::cellml_api::CellMLVariableSet* vs(comp->variables());
    std::wstring compname = comp->name();
    comp->release_ref();
    iface::cellml_api::CellMLVariableIterator* vi(vs->iterateVariables());
    vs->release_ref();

    iface::cellml_api::CellMLVariable* v;
    while ((v = vi->nextVariable()) != NULL)
    {
      std::wstring name = v->name();
      std::wstring varn = compname;
      varn += L"_";
      varn += name;
      std::wstring raten = L"rate_";
      raten += varn;
      as->setStringAnnotation(v, L"expression", varn.c_str());
      as->setStringAnnotation(v, L"expression_d1", raten.c_str());
      v->release_ref();
    }

    vi->release_ref();
  }

  cci->release_ref();

  as->release_ref();
}
bool TraceLog::activateTraceLog( bool isActive ){
	if ( isActive ){
        try{

            std::string traceFileName = "traceLog"+getTime()+".log";
            out.open(traceFileName.c_str() );
            std::streambuf *countbuf = std::cout.rdbuf();
            std::cout.rdbuf ( out.rdbuf() ) ;
            AddTimeStamp ats( cout );

            std::cout<<"buffer pointed\n";
                }
		catch ( std::exception &e ){
			std::cerr<<"exception caight\n";
			return false;
		}
		return true;

	}
	else{ //have to do some logic thus std::cout<<"print data\n" won;t print any thing to standard output.
    }
}
Exemple #3
0
int main () {
  const int n_thre = omp_get_max_threads();

  fill_initial_condition();

#pragma omp parallel
  {
    int tid=2*omp_get_thread_num();
    for(int x=0;x<SX;++x) {
      for(int y=0;y<SY;++y) {
        for(int z=0;z<SZ;++z) {
          double u,v; get_solution_at(0,x,y,z, u,v);
          ats(sU0,tid,x,y,z)=u;
	  ats(sV0,tid,x,y,z)=v;
        }
      }
    }
  }

  std::cerr << "Setting up wall values..." << std::endl;
  for(int t = 0;t<T_MAX;++t){
    /*
#pragma omp parallel
    {
      int tid=2*omp_get_thread_num();
      for(int x=SX-2;x<SX;++x) {
        for(int y=0;y<SY;++y) {
          for(int z=0;z<SZ;++z) {
            double u,v; get_solution_at(t,x+t,y+t,z+t, u,v);
            Uwx[tid][t][x-(SX-2)][y][z] = u;
            Vwx[tid][t][x-(SX-2)][y][z] = v;
          }
        }
      }
      for(int x=0;x<SX;++x) {
        for(int y=SY-2;y<SY;++y) {
          for(int z=0;z<SZ;++z) {
            double u,v; get_solution_at(t,x+t,y+t,z+t, u,v);
            Uwy[tid][t][x][y-(SY-2)][z] = u;
            Vwy[tid][t][x][y-(SY-2)][z] = v;
          }
        }
      }
      for(int x=0;x<SX;++x) {
        for(int y=0;y<SY;++y) {
          for(int z=SZ-2;z<SZ;++z) {
            double u,v; get_solution_at(t,x+t,y+t,z+t, u,v);
            Uwz[tid][t][x][y][z-(SZ-2)] = u;
            Vwz[tid][t][x][y][z-(SZ-2)] = v;
          }
        }
      }
    */
  }

  for(int trial=0;trial<10;++trial) {
    std::cerr << "Carrying out simulation..." << std::endl;
    // set initial condition
#pragma omp parallel
    {
      const int tid=2*omp_get_thread_num();
      for(int x=0;x<SX;++x) {
        for(int y=0;y<SY;++y) {
          for(int z=0;z<SZ;++z) {
            ats(sU,tid,x,y,z)=ats(sU0,tid,x,y,z);
            ats(sV,tid,x,y,z)=ats(sV0,tid,x,y,z);
          }
        }
      }
    }
    double time_comp=0, time_comm=0, time_begin, time_end;

    //for(int heating=0;heating<10;++heating) {
      time_begin = wctime();
#pragma omp parallel 
      for (int tid=0;tid<n_thre;++tid) {
        //const int tid=2*omp_get_thread_num();
        for(int t = 0; t < T_MAX; ++t){

          // destructively update the state
          /*
          const auto lap = [](Real ar[SX][SY][SZ],int x, int y, int z) {
            auto ret = ar[x][y+1][z+1] + ar[x+2][y+1][z+1]
            + ar[x+1][y][z+1] + ar[x+1][y+2][z+1]
            + ar[x+1][y+1][z] + ar[x+1][y+1][z+2]
            - 6*ar[x+1][y+1][z+1];
            return ret / dx / dx;
            };*/

#define lap(ar,b,x,y,z)			       \
          (ats(ar,b,x,y+1,z+1) + ats(ar,b,x+2,y+1,z+1) \
            + ats(ar,b,x+1,y,z+1) + ats(ar,b,x+1,y+2,z+1) \
            + ats(ar,b,x+1,y+1,z) + ats(ar,b,x+1,y+1,z+2) \
              - 6*ats(ar,b,x+1,y+1,z+1)) / dx / dx


#pragma omp for collapse(2)
          for(int x=0;x<SX-2;++x) {
            for(int y=0;y<SY-2;++y) {
#pragma omp simd
              for(int z=0;z<SZ-2;++z) {
                Real u=ats(sU,tid,x+1,y+1,z+1) ;
                Real v=ats(sV,tid,x+1,y+1,z+1) ;

                auto du_dt = -Fe * u*v*v + Fu*(1-u) + Du * lap(sU,tid,x,y,z);
		auto dv_dt =  Fe * u*v*v - Fv*v     + Dv * lap(sV,tid,x,y,z);
                ats(sU,tid,x,y,z) = u+dt*du_dt;
		ats(sV,tid,x,y,z) = v+dt*dv_dt;
              }
            }
          }
        }
      }
      time_end = wctime();
      //}

    double flop = 29.0 * (SX-2)*(SY-2)*(SZ-2) *T_MAX * n_thre;
    double bw_gb= 8.0 * 2 * 7 * (SX-2)*(SY-2)*(SZ-2) *T_MAX * n_thre;
    double time_elapse = time_end-time_begin;

    {
      const int t = T_MAX;
      double num[BANK]={0},den[BANK]={0};
#pragma omp parallel
      {
        int tid=2*omp_get_thread_num();

        for(int x=0;x<SX-2;++x) {
          for(int y=0;y<SY-2;++y) {
            for(int z=0;z<SZ-2;++z) {
              double u,v; get_solution_at(t,x+t,y+t,z+t, u,v);
              num[tid] += std::abs(u-ats(sU,tid,x,y,z));
              den[tid] += 1;
            }
          }
        }
      }
      double sum_num = 0, sum_den = 0;
      for(int i=0;i<BANK;++i){
        sum_num += num[i];
        sum_den += den[i];
      }

      std::ostringstream msg;
      msg << n_thre << "  " << SX << " " << SY << " " << SZ << " " << T_MAX << " "
          << " t: " << time_elapse << " " << time_comm << " " << time_comp << " GFlops: " << flop/time_elapse/1e9<<  " GBps: " << bw_gb/time_elapse/1e9<< " error: " << (sum_num/sum_den);
      std::ofstream log_file("benchmark-standalone.txt", std::ios::app);
      std::cout << msg.str() << std::endl;
      log_file << msg.str() << std::endl;
    }
  }
}