Example #1
0
int main()
{
  int i, j, size;
  float **M;

  scanf("%d",&size);

  //forming the user matrix
  M = (float **)malloc(size * sizeof(float));
  for(i=0; i<size; i++)
    {
      M[i] = (float *)malloc(size * sizeof(float));
      for(j=0; j<size; j++)
	  scanf("%f",&M[i][j]);
    }

  iterate(M, size);

  return 0;
}
Example #2
0
int main( int argc, char *argv[] )
{
	ALCdevice *device;
	int attributeList[] = { ALC_FREQUENCY, 22050, 0 };
	time_t start;
	time_t shouldend;

	start = time( NULL );
	shouldend = time( NULL );

	device = alcOpenDevice( NULL );
	if( device == NULL ) {
		return EXIT_FAILURE;
	}

	/* Initialize ALUT. */
	context = alcCreateContext( device, attributeList );
	if( context == NULL ) {
		alcCloseDevice( device );
		return EXIT_FAILURE;
	}

	alcMakeContextCurrent( context );

	testInitWithoutContext( &argc, argv );

	init( ( const ALbyte * ) ( ( argc == 1 ) ? WAVEFILE : argv[1] ) );

	while( shouldend - start < 30 ) {
		shouldend = time( NULL );

		iterate(  );
	}

	testExit();

	alcDestroyContext( context );
	alcCloseDevice( device );

	return EXIT_SUCCESS;
}
Example #3
0
int main()
{
    vectorField V, nextV;        // Velocity fields
    scalarField P, P_rhs;        // Pressure fields
    vectorField advect;          // Advection field
    vectorField force;           // Forcing function

    const int N = 50;            // Arrays are NxNxN

    setup(N, V, nextV, P, P_rhs, advect, force);

    const int nIters = 999;

    // Stirring motion will stop at this time
    const double forceTurnOff = 25000.0;  // seconds

    for (int i=0; i < nIters; ++i)
    {
        cout << "Iteration " << i << " Time = " << time_now << " s" << endl;

        iterate(V, nextV, P, P_rhs, advect, force);

        // Update the current time, turn off the force when we pass
        // forceTurnOff

        double oldtime_now = time_now;
        time_now += delta_t;

        if ((time_now > forceTurnOff) && (oldtime_now <= forceTurnOff))
            force = 0.0;

        // Dump some state
        snapshot(V);
        snapshot(P);

        // Adjust the time step for the next iteration
        adjustTimeStep(V);
    }

    return 0;
}
Example #4
0
static int iterate_leaf_refs(struct extent_inode_elem *inode_list,
				u64 root, u64 extent_item_objectid,
				iterate_extent_inodes_t *iterate, void *ctx)
{
	struct extent_inode_elem *eie;
	int ret = 0;

	for (eie = inode_list; eie; eie = eie->next) {
		pr_debug("ref for %llu resolved, key (%llu EXTEND_DATA %llu), "
			 "root %llu\n", extent_item_objectid,
			 eie->inum, eie->offset, root);
		ret = iterate(eie->inum, eie->offset, root, ctx);
		if (ret) {
			pr_debug("stopping iteration for %llu due to ret=%d\n",
				 extent_item_objectid, ret);
			break;
		}
	}

	return ret;
}
Example #5
0
int main(){
  int i;
  init();
  GUI();
  while (!done){
    Events(1); /* Whenever there are new data the argument of 
		  Events() should be nonzero. This will set the
		  requests for data so that you can calculate them
		  on demand only. For this simple program you can
		  always set it to one. */
    DrawGraphs();
    if (!pause || sstep){
      sstep=0;
      for (i=0;i<Repeat;i++) iterate();
    } else {
      sleep(1);/*when the program is waiting it returns the 
		 CPU time to the operating system */
    }
  }
  return 0;
}
Example #6
0
	void draw(cv::Mat& destination)
	{
		cv::Mat float_destination;

		if (background)
			background->convertTo(float_destination, CV_32FC3);
		else
			destination.convertTo(float_destination, CV_32FC3);

		iterate(float_destination, drawStrategy);
		float_destination.convertTo(destination, destination.type());

		if (redraw_current_frame) {
			Frame *current_frame = trail.back();
			current_frame->getData().copyTo(destination, current_frame->getMask());
		}

		/* remember the current trail in the background image */
		if (persistent)
			float_destination.convertTo(*background, background->type());
	}
Example #7
0
static gboolean
populate_model (ClutterModel *model)
{
  gint i;

  for (i = 0; i < 10; i++)
    {
      gchar *string = g_strdup_printf ("String %d", i);

      clutter_model_append (model,
                            COLUMN_FOO, i,
                            COLUMN_BAR, string,
                            -1);
      g_free (string);
    }

  clutter_model_foreach (model, foreach_func, NULL);
  iterate (model);

  return FALSE;
}
Example #8
0
bool TestOperation::run(int iterations)
{
  m_pixmaps.clear();
  m_pixmaps.append(QPixmap::fromImage(m_image));

  if (!this->computeInitialSeeds(iterations)) {
    return false;
  }

  if (!this->initializeVectors()) {
    return false;
  }

  while (iterations-- > 0) {
    qDebug() << "Frames remaining:" << iterations + 1;
    if (!iterate()) {
      return false;
    }
  }
  return true;
}
Example #9
0
File: cord.hpp Project: det/Twil
	static void iterate(NodeT Node, std::size_t Height, FunctorT Functor)
	{
		if (Height != 0)
		{
			auto Branch = static_cast<BranchT *>(Node.Pointer);
			auto Size = Node.Size;
			std::size_t Index = 0;

			while (Size != 0)
			{
				iterate(Branch->Children[Index], Height - 1, Functor);
				Size -= Branch->Children[Index].Size;
				++Index;
			}
		}
		else
		{
			auto Leaf = static_cast<LeafT *>(Node.Pointer);
			Functor(Leaf->Buffer, Node.Size);
		}
	}
Example #10
0
Status TLSLogForwarder::send(std::vector<std::string>& log_data,
                             const std::string& log_type) {
  pt::ptree params;
  params.put<std::string>("node_key", getNodeKey("tls"));
  params.put<std::string>("log_type", log_type);

  {
    // Read each logged line into JSON and populate a list of lines.
    // The result list will use the 'data' key.
    pt::ptree children;
    iterate(log_data, ([&children](std::string& item) {
              // Enforce a max log line size for TLS logging.
              if (item.size() > FLAGS_logger_tls_max) {
                LOG(WARNING) << "Line exceeds TLS logger max: " << item.size();
                return;
              }

              pt::ptree child;
              try {
                std::stringstream input;
                input << item;
                std::string().swap(item);
                pt::read_json(input, child);
              } catch (const pt::json_parser::json_parser_error& /* e */) {
                // The log line entered was not valid JSON, skip it.
                return;
              }
              children.push_back(std::make_pair("", std::move(child)));
            }));
    params.add_child("data", std::move(children));
  }

  // The response body is ignored (status is set appropriately by
  // TLSRequestHelper::go())
  std::string response;
  if (FLAGS_logger_tls_compress) {
    params.put("_compress", true);
  }
  return TLSRequestHelper::go<JSONSerializer>(uri_, params, response);
}
Example #11
0
//----main----//
task main ()
{
	nxtDisplayCenteredTextLine(3, "Pose Test");
	wait1Msec(500);
	initialisePose(); //set up
	iterate(stepSize); //run excitation etc
	currentDirection = 0; //set initial
  currentTheta = 0;
  changeTheta = 0;

  //display data
 displayMax();
    nxtDisplayTextLine(2, "Num Act.: %3d",numActive);
    nxtDisplayTextLine(4, "Direction: %1d", currentDirection);
    nxtDisplayTextLine(5, "currentTheta:%3d", currentTheta);
    nxtDisplayTextLine(6, "changeTheta:%3d", changeTheta);
	datalogging();
  while(totalClicks<1800)
	{
		alive(); //stop NXT from sleeping
    totalClicks += clicks;
    //drive(-100,190,50);
   // drive(50,180,50);

    pose3D(changeTheta,0.5);

    displayMax();
    nxtDisplayTextLine(2, "Num Act.: %3d",numActive);
    nxtDisplayTextLine(4, "Direction: %1d", currentDirection);
    nxtDisplayTextLine(5, "currentTheta:%3d", currentTheta);
    nxtDisplayTextLine(6, "changeTheta:%3d", changeTheta);
    clearEncoders(); //clear encoder count
    changeTheta=0;
    datalogging();

  }
  PlaySound(soundFastUpwardTones);
  while(bSoundActive) {}
  SaveNxtDatalog();
}
Example #12
0
long rho(big q,big r,big m,big n)
{ /* find q^m = r^n */
    long iter,rr,i;

    char stack_mem[mr_big_reserve(6,50)];
    big ax,bx,ay,by,x,y;

    memset(stack_mem,0,mr_big_reserve(6,50));

    ax=mirvar_mem(stack_mem,0);
    bx=mirvar_mem(stack_mem,1);
    ay=mirvar_mem(stack_mem,2);
    by=mirvar_mem(stack_mem,3);
    x=mirvar_mem(stack_mem,4);
    y=mirvar_mem(stack_mem,5);

    convert(1,y);
    zero(ay); zero(by);

    iter=0L;
    rr=1L;
    do
    { /* Brent's Cycle finder */
        copy(y,x);
        copy(ay,ax);
        copy(by,bx);
        rr*=2;
        for (i=1L;i<=rr;i++)
        {
            iter++;
            iterate(y,q,r,ay,by);
            if (compare(x,y)==0) break;
        }
    } while (compare(x,y)!=0);
    subtract(ax,ay,m);
    if (size(m)<0) add(m,order,m);
    subtract(by,bx,n);
    if (size(n)<0) add(n,order,n);
    return iter;
}
Example #13
0
Status TLSLogForwarder::send(std::vector<std::string>& log_data,
                             const std::string& log_type) {
    pt::ptree params;
    params.put<std::string>("node_key", node_key_);
    params.put<std::string>("log_type", log_type);

    {
        // Read each logged line into JSON and populate a list of lines.
        // The result list will use the 'data' key.
        pt::ptree children;
        iterate(log_data,
        ([&children](std::string& item) {
            // Enforce a max log line size for TLS logging.
            if (item.size() > FLAGS_logger_tls_max) {
                LOG(WARNING) << "Line exceeds TLS logger max: " << item.size();
                return;
            }

            pt::ptree child;
            try {
                std::stringstream input;
                input << item;
                std::string().swap(item);
                pt::read_json(input, child);
            } catch (const pt::json_parser::json_parser_error& e) {
                // The log line entered was not valid JSON, skip it.
                return;
            }
            children.push_back(std::make_pair("", std::move(child)));
        }));
        params.add_child("data", std::move(children));
    }

    auto request = Request<TLSTransport, JSONSerializer>(uri_);
    request.setOption("hostname", FLAGS_tls_hostname);
    if (FLAGS_logger_tls_compress) {
        request.setOption("compress", true);
    }
    return request.call(params);
}
Example #14
0
int main( int argc, char* argv[] ) {
	ALCdevice *dev;
	int i = 5;

	dev = alcOpenDevice( NULL );
	if( dev == NULL ) {
		return 1;
	}

	/* Initialize ALUT. */
	context_id = alcCreateContext( dev, NULL );
	if(context_id == NULL) {
		alcCloseDevice( dev );

		return 1;
	}

	alcMakeContextCurrent( context_id );

	fixup_function_pointers();

	if(argc == 1) {
		init(WAVEFILE);
	} else {
		init(argv[1]);
	}

	iterate();

	while(SourceIsPlaying(multis) == AL_TRUE) {
		micro_sleep(1000000);
	}

	cleanup();

	alcCloseDevice( dev );

	return 0;
}
void iteratePrint2(const IterationRange<T1> & iteration1, const IterationRange<T2> & iteration2, const Exp & exp, const Print & print)
{
    std::cout << "        , ";
    printValues(iteration2);
    struct PrintAndIterate
    {
        PrintAndIterate(const IterationRange<T2> & iteration, const Exp & exp, const Print & print) : iteration_(iteration), exp_(exp), print_(print)
        {
        }
        void operator()(T1 val) const
        {
            PrintValue<T1>()(val);
            iterate(iteration_, makePrintExp(std::bind1st(exp_, val), print_));
            std::cout << std::endl;
        }
    private:
        IterationRange<T2> iteration_;
        Exp exp_;
        Print print_;
    };
    iterate(iteration1, PrintAndIterate(iteration2, exp, print));
}
Example #16
0
File: main.cpp Project: CCJY/coliru
    std::vector<std::vector<Color> >
    mandelbrot(const int thread_num, const int RES_X, const int RES_Y,
                    const long double MIN_X, const long double MAX_X,
                    const long double MIN_Y, const F & color)
    {
        long double MAX_Y = MIN_Y + (MAX_X - MIN_X)*(static_cast<float>(RES_Y)/RES_X);
        const auto xScale = (MAX_X - MIN_X) / RES_X;
        const auto yScale = (MAX_Y - MIN_Y) / RES_Y;

        std::vector<std::vector<Color> > image(RES_Y,std::vector<Color>(RES_X));

        for(auto i = 0; i < RES_Y; i++){
            for(auto j = 0; j < RES_X; j++){
                auto real = MIN_X + xScale * j;
                auto imag = MAX_Y - yScale * i;
                std::complex<long double> c(real,imag);
                auto iter = iterate(c);
                image[i][j] = color(iter,c);
            }
        }
        return image;
    }
Example #17
0
// A single run of optimization
Record single_run(Random& rand, Configuration& config,
                  evaluation::pointer problem, optimize::pointer solver,
                  int run) {
  size_t limit = config.get<int>("eval_limit");
  // Middle Layer's sit between the problem and the solver, tracking optimization
  shared_ptr<Middle_Layer> recorder(new Middle_Layer(config, problem(config, run)));

  // Start the clock before any evaluations can be performed
  recorder->results.start_clock();
  auto optimizer = solver(rand, std::static_pointer_cast<Evaluator>(recorder), config);
  float good_enough = config.get<float>("fitness_limit");

  // Iterate the optimizer until the solution is reached, the maximum number
  // of evaluations is performed, or the optimizer reaches stagnation
  bool improvement_possible = true;
  while (recorder->best_fitness < good_enough and recorder->evaluations < limit
      and improvement_possible) {
    improvement_possible = optimizer->iterate();
  }
  recorder->results.metadata = optimizer->finalize();
  return recorder->results;
}
Example #18
0
int main(int, char**){
  std::map<int, TreeNodeStorage> tree = readInLink();
  std::vector<int> roots;
  size_t ndim;

  inLinkToTree(tree, roots, ndim);

  std::cout<<"roots: ";
  for(size_t i=0;i<roots.size();++i)
    std::cout<<roots[i]<<' ';
  std::cout<<std::endl;

  iterate(tree, roots, ndim);

  for(auto i=tree.begin();i!=tree.end();++i){
    std::cout<<i->first<<' ';
    for(size_t j=0;j<i->second.values.size();++j)
      std::cout<<i->second.values[j]<<' ';
    std::cout<<std::endl;
  }
  return 0;
}
Example #19
0
static int
dump_database (krb5_context context, int type,
	       const char *database_name, HDB *db)
{
    krb5_error_code ret;
    struct prop_data pd;
    krb5_data data;

    pd.context      = context;
    pd.auth_context = NULL;
    pd.sock         = STDOUT_FILENO;

    ret = iterate (context, database_name, db, type, &pd);
    if (ret)
	krb5_errx(context, 1, "iterate failure");
    krb5_data_zero (&data);
    ret = krb5_write_message (context, &pd.sock, &data);
    if (ret)
	krb5_err(context, 1, ret, "krb5_write_message");

    return 0;
}
Example #20
0
void TestEcalDigi<DigiCollection>::iterator() {
    DigiCollection frames;
    for (int n=1; n<5; ++n) {
        typename DigiCollection::DetId id = DigiCollection::DetId::unhashIndex(n);
        frames.push_back(id);
        typename DigiCollection::Digi df(frames.back());
        std::copy(sv.begin(),sv.end(),df.frame().begin());
    }
    // modern
    CPPUNIT_ASSERT(std::for_each(frames.begin(),frames.end(),
                                 VerifyIter<typename DigiCollection::Digi>(this->sv)
                                ).n==4);
    // classical
    VerifyIter<typename DigiCollection::Digi> vi(sv);
    for (int n=0; n<int(frames.size()); ++n) {
        typename DigiCollection::Digi digi(frames[n]);
        vi(digi);
    }
    // alternatives
    iterate(frames);
    CPPUNIT_ASSERT(std::for_each(frames.begin(),frames.end(),VerifyFrame(sv)).n==4);
}
Example #21
0
int main(void){
    
    initscr(); //start curses mode
    signal(SIGINT, int_handler);
    
    int h, w;
    clear();
    getmaxyx(stdscr, h, w);
    if(w<W+1 || h<H){
        endwin();
        printf("Terminal too small: w=%d, W=%d   h=%d, H=%d\n", w, W, h, H);
        exit(-1);
    }

    char grid[H][W]; //Initialise grid
    char buff[H][W];
    init_rand(grid);

    clock_t t1; //Initialise clock for rate limiting
    double elapsed;
    
    disp(grid);
    while(running){
        t1 = clock();
        elapsed = 0;
        iterate(grid, buff);
        memcpy(grid, buff, sizeof(char)*H*W); 
	    disp(grid);
	    
        //if there's time left, sleep it off
        elapsed = ((double) (clock() - t1)) / CLOCKS_PER_SEC;
        if(elapsed < T_PER_FRAME) 
            msleep(T_PER_FRAME-elapsed);
    }
    endwin();
    printf("SIGINT caught, exiting\n");
    return 0;
}
Example #22
0
void cacti_setup()
{
  const char *technology = SescConf->getCharPtr("","technology");
  fprintf(stderr,"technology = [%s]\n",technology);
  tech = SescConf->getInt(technology,"tech");
  fprintf(stderr, "tech : %9.0fnm\n" , tech);
  tech /= 1000;

#ifdef SESC_SESCTHERM
  sescTherm = new ThermTrace(0); // No input trace, just read conf
#endif

  const char *proc    = SescConf->getCharPtr("","cpucore",0);
  const char *l1Cache = SescConf->getCharPtr(proc,"dataSource");

  const char *l1CacheSpace = strstr(l1Cache," ");
  char *l1Section = strdup(l1Cache);
  if (l1CacheSpace)
    l1Section[l1CacheSpace - l1Cache] = 0;

  res_memport = SescConf->getInt(l1Section,"numPorts");

  xcacti_flp xflp;
  double l1Energy = getEnergy(l1Section, &xflp);

  double WattchL1Energy = SescConf->getDouble("","wattchDataCacheEnergy");

  if (WattchL1Energy) {
    wattch2cactiFactor = WattchL1Energy/l1Energy;
    fprintf(stderr,"wattch2cacti Factor %g\n", wattch2cactiFactor);
  }else{
    fprintf(stderr,"-----WARNING: No wattch correction factor\n");
  }

  processorCore();

  iterate();
}
Example #23
0
//----handles pose thing----//
void pose3D(float deltaTheta, float translation)
{
  //initialise loop variables
  char f;
  char g;
  char h;
  memset(tempPose, 0, 2400); //a zero matrix to perform path integration on
  for(f = 0; f < sizeX; f++)
  {
    for(g = 0; g < sizeY; g++)
    {
      for(h = 0; h < sizeTheta; h++)
      {
        if(poseWorld.poseActivity[f].array2D[g][h] > 0) //if active
        {
          pathIntegrateCell(f, g, h, deltaTheta, translation);
        }
      }
    }
  }
  memcpy(poseWorld.poseActivity,tempPose,numberOfCells);
  iterate(stepSize);
}
Example #24
0
/*
  sorting function - this function should work completely abstracted from the data type to sort
//*/
void* sort(void** first)
{
  void* tmp = *first;

  char done = 0;

  while(!done){
    done = 1;
    tmp = *first;

    // while there is a next compare "tmp" and "tmp->next", in case swap
    while(!islastelement(tmp)){
      if(compare(tmp, getnextelement(tmp))){
	swap((void*) &tmp, getnextelement(tmp));
	done = 0;
      }

      tmp = iterate(tmp, first);
    }
  }

  return NULL;
}
Example #25
0
//----handles pose thing----//
void pose3D(float deltaTheta, float translation)
{
  //initialise loop variables
  char i;
  char j;
  char k;
  memset(tempPose, 0, 2400); //a zero matrix to perform path integration on
  for(i = 0; i < 10; i++)
  {
    for(j = 0; j < 10; j++)
    {
      for(k = 0; k < 6; k++)
      {
        if(poseWorld.poseActivity[i].array2D[j][k] > 0) //if active
        {
          pathIntegrateCell(i, j, k, deltaTheta, translation);
        }
      }
    }
  }
  memcpy(poseWorld.poseActivity,tempPose,numberOfCells);
  iterate(stepSize);
}
Example #26
0
int main( int argc, char *argv[] )
{
	time_t shouldend;

	/* Initialize ALUT. */
	testInit( &argc, argv );

	init( ( const ALbyte * ) ( ( argc == 1 ) ? WAVEFILE : argv[1] ) );

	alSourcePlay( movingSource );
	while( 1 ) {
		shouldend = time( NULL );
		if( ( shouldend - start ) > 40 ) {
			break;
		}

		iterate(  );
	}

	testExit(  );

	return EXIT_SUCCESS;
}
Example #27
0
long rho(big q,big r,big m,big n)
{ /* find q^m = r^n */
    long iter,rr,i;
    big ax,bx,ay,by,x,y;
    ax=mirvar(0);
    bx=mirvar(0);
    ay=mirvar(0);
    by=mirvar(0);
    x=mirvar(1);
    y=mirvar(1);
    iter=0L;
    rr=1L;
    do
    { /* Brent's Cycle finder */
        copy(y,x);
        copy(ay,ax);
        copy(by,bx);
        rr*=2;
        for (i=1L;i<=rr;i++)
        {
            iter++;
            iterate(y,q,r,ay,by);
            if (compare(x,y)==0) break;
        }
    } while (compare(x,y)!=0);
    subtract(ax,ay,m);
    if (size(m)<0) add_r(m,order,m);
    subtract(by,bx,n);
    if (size(n)<0) add_r(n,order,n);
    mirkill(y);
    mirkill(x);
    mirkill(by);
    mirkill(ay);
    mirkill(bx);
    mirkill(ax);
    return iter;
}
Example #28
0
void Vizzer::render(ApplicationData &app)
{
    timer.frame();

    for (const auto &f : iterate(state.bundler.frames))
    {
        vec3f cameraColor(0.5f, 0.5f, 0.9f);
        vec3f meshColor(1.0f, 1.0f, 1.0f);

        if (f.index == state.selectedCamera)
        {
            meshColor = vec3f(0.9f, 0.5f, 0.5f);
            cameraColor = vec3f(0.9f, 0.5f, 0.5f);
            assets.renderMesh(state.frameCloudsBig[f.index], camera.getCameraPerspective(), meshColor);
        }

        renderCamera(app, f.value.debugCamera, cameraColor);

        assets.renderMesh(state.frameCloudsSmall[f.index], camera.getCameraPerspective(), meshColor);
    }

    /*const float borderRadius = 0.01f;
    assets.renderCylinder(camera.getCameraPerspective(), vec3f(1.0f, 0.0f, 0.0f), vec3f(1.0f, 1.0f, 0.0f), borderRadius, vec3f(1.0f, 0.0f, 0.0f));
    assets.renderCylinder(camera.getCameraPerspective(), vec3f(1.0f, 1.0f, 0.0f), vec3f(0.0f, 1.0f, 0.0f), borderRadius, vec3f(1.0f, 0.0f, 0.0f));
    assets.renderCylinder(camera.getCameraPerspective(), vec3f(0.0f, 1.0f, 0.0f), vec3f(0.0f, 0.0f, 0.0f), borderRadius, vec3f(1.0f, 0.0f, 0.0f));
    assets.renderCylinder(camera.getCameraPerspective(), vec3f(0.0f, 0.0f, 0.0f), vec3f(1.0f, 0.0f, 0.0f), borderRadius, vec3f(1.0f, 0.0f, 0.0f));*/

    vector<string> text;
    text.push_back(string("FPS: ") + convert::toString(timer.framesPerSecond()));
    
    //if (rand() % 100 == 0)
    //    cout << camera.toString() << endl;

    const bool useText = true;
    if (useText)
        drawText(app, text);
}
Example #29
0
int main (int argc, char* argv[]) {
    size_t buffer_size = 0x10000;
    byte* buffer = (byte*)malloc(buffer_size);
    ssize_t len;
    while ((len = read(fileno(stdin), buffer, buffer_size)) > 0) {
        if (len < 0) {
            perror(argv[0]);
            return errno;
        }
        ssize_t error = iterate(buffer, (size_t)len);
        if (error >= 0) {
            fprintf(stderr, "Error in json stream at position: %zd\n", error);
            return 1;
        }
        ssize_t written;
        while (len > 0) {
            written = write(fileno(stdout), buffer, (size_t)len);
            if (written == 0) {
                errno = EPIPE;
                written = -1;
            }
            if (written < 0) {
                perror(argv[0]);
                return errno;
            }
            buffer += written;
            len -= written;
        }
    }
    free(buffer);
    if (len < 0) {
        perror(argv[0]);
        return errno;
    }
    return 0;
}
Example #30
0
        void run(task::TaskDAG& dag, const Arena& arena)
        {
            for (iter = 1;iter <= maxiter && !isConverged();iter++)
            {
                time::Timer timer;
                timer.start();
                iterate();
                timer.stop();
                double dt = timer.seconds(arena);

                int ndigit = (int)(ceil(-log10(convtol))+0.5);

                log(arena) << "Iteration " << iter << " took " << std::fixed <<
                              std::setprecision(3) << dt << " s" << std::endl;
                log(arena) << "Iteration " << iter <<
                              " energy = " << std::fixed << std::setprecision(ndigit) << energy <<
                              ", convergence = " << std::scientific << std::setprecision(3) << conv << std::endl;
            }

            if (!isConverged())
            {
                throw std::runtime_error(std::strprintf("Did not converge in %d iterations", maxiter));
            }
        }