Ejemplo n.º 1
0
void Communicator::sendDiffusionToNeighbor(const char *out_blip,
					   int nrow, int ncol)
{
  int nsi = siteIndexOf(nrow, ncol);
  if ( nsi != -1 )
  {
    int nr = rankOfSite(nsi);
	  // take out the amount diffused away
    // local indexes may have changed
    subtractDiffusion( out_blip, parameters.rank() );
    if ( nr == parameters.rank() )
    {   // if the other site is on the same processor
      if ( parameters.outputMPIMessages() )
      {
	site->node->outputcontroller->log(
		"give diffusion directly to [%i][%i]\n", nr, nsi);
      }
      Communicator *nc = communicatorForSite(nsi);
      nc->addDiffusion(out_blip, nr);
    }
#ifdef MPI
    else
    {
      if (parameters.outputMPIMessages)
      {
	site->node->outputcontroller->log(
          "send diffusion to [%i][%i]\n", nr, nsi);
      }
      sendDiffusionBlip(out_blip, nr);
    }
#endif //MPI
  } // end if not off the edge of the grid
}
Ejemplo n.º 2
0
int main(int argc, char* argv[]) {
  struct sigaction sa;
  sigemptyset(&sa.sa_mask);
  sa.sa_handler = SIG_IGN;
  sa.sa_flags = 0;
  sigaction( SIGPIPE, &sa, 0 );

  Communicator* comm = Communicator::instance();
  if (comm->init() == -1)
    return -1;

  // Identity's arg must correspond to the class name in Hello.idl
  // Endpoind's arg: protocal, ip, port of the server end
  // in case of async call, timeout option is not needed
  Reference ref (comm, Identity("MyHello"), Endpoint("TCP", "127.0.0.1", 3000));
  IcmProxy::demo::MyHello myHello;
  myHello.setReference (&ref);

  unsigned long u =  1024ul * 1024 * 1024 * 12;

  // invoke async calls
  myHello.sayHello_async(new AMI_MyHello_sayHelloI, "Hello, async", u);
  myHello.sayBye_async(new AMI_MyHello_sayByeI, "Bye, async");

  // run() will enter a cycle to wait and process server reply, callback classes's response() will be invoked automatically
  // so usually this can be put into a new created thread 
  comm->run();

  return 0;
}
Ejemplo n.º 3
0
void mpsxx::DMRGInput::parse (const std::string& fname)
{
  if(fname.size() == 0) return;

  Communicator world;

  if(world.rank() == 0) {
    std::ifstream fin(fname.c_str());
    std::string entry;
    while(fin >> entry) {
      if(entry == "restart")
        this->restart = true;
      if(entry == "N")
        fin >> this->N_sites;
      if(entry == "spin")
        fin >> this->N_spins;
      if(entry == "elec")
        fin >> this->N_elecs;
      if(entry == "M" || entry == "max_states")
        fin >> this->N_max_states;
      if(entry == "nroots")
        fin >> this->N_roots;
      if(entry == "tole" || entry == "tolerance")
        fin >> this->tolerance;
      if(entry == "noise")
        fin >> this->noise;
      if(entry == "onesite" || entry == "onedot")
        this->algorithm = mpsxx::ONESITE;
      if(entry == "twosite" || entry == "twodot")
        this->algorithm = mpsxx::TWOSITE;
      if(entry == "maxiter")
        fin >> this->N_max_sweep_iter;
    }
  }
Ejemplo n.º 4
0
int
main (int argc, char* argv[])
{
  Communicator* comm = Communicator::instance();
  if (comm->init (true) == -1)
    return -1;

  Reference ref (comm, Identity("MyHello"), Endpoint("TCP", "127.0.0.1", 3000));
  IcmProxy::demo::MyHello myHello;
  myHello.setReference (&ref);

  for (int i = 0; i < 10; i++) {
    Short u = 10 + i;
    Long v = 1000 + i;
    std::ostringstream ss;
    ss << "hello, world from " << i;
    string ret = myHello.sayHello (ss.str(), u, v);
	if ( IcmProxy::IsCallSuccess() ) { 
		std::cout<<"call success. errno:"<<errno<<std::endl;
	} else {
		std::cout<<"call failed. errno:"<<errno<<std::endl;
	}
    if (ret != "") {
      std::cout << "ret:" << ret << std::endl;
    } else {
      //err process
    }
  }

  return 0;
}
Ejemplo n.º 5
0
void * clientThread(void * param) {
	int clientSocket = *(unsigned int *)param;

	Communicator communicator;
	communicator.handleClientConnection(clientSocket);

	pthread_exit(NULL);
}
Ejemplo n.º 6
0
void Server::incomingConnection(qintptr handle)
{
    Communicator *newCall = new Communicator(handle, localPort, &badWords, this);

    connect(newCall, SIGNAL(finished()), newCall, SLOT(quit()));
    connect(newCall,SIGNAL(finished()),newCall,SLOT(deleteLater()));

    newCall->start();
}
Ejemplo n.º 7
0
int physics_init()
{
  // 2D initial profiles
  Field2D rho0, p0;
  Vector2D v0, B0;

  // read options
  options.setSection("mhd");
  OPTION(gamma,          5.0/3.0);
  OPTION(include_viscos, false);
  OPTION(viscos,         0.1);


  // Read 2D initial profiles
  GRID_LOAD(rho0);
  GRID_LOAD(p0);
  v0.covariant = true; // Read covariant components of v0
  GRID_LOAD(v0);
  B0.covariant = false; // Read contravariant components of B0
  GRID_LOAD(B0);

  // tell BOUT which variables to evolve
  
  bout_solve(rho, F_rho, "density");
  bout_solve(p, F_p, "pressure");
  v.covariant = true; // evolve covariant components
  bout_solve(v, F_v, "v");
  B.covariant = false; // evolve contravariant components
  bout_solve(B, F_B, "B");

  output.write("dx[0,0] = %e, dy[0,0] = %e, dz = %e\n", dx[0][0], dy[0][0], dz);

  dump.add(divB, "divB", 1);

  if(!restarting) {
    // Set variables to these values (+ the initial perturbation)
    // NOTE: This must be after the calls to bout_solve
    rho += rho0;
    p += p0;
    v += v0;
    B += B0;
    
    // Added this for modifying the Orszag-Tang vortex problem
    real v_fact;
    options.get("v_fact",         v_fact,         1.0);
    v *= v_fact;
  }

  // Set communications
  
  comms.add(rho);
  comms.add(p);
  comms.add(v);
  comms.add(B);

  return 0;
}
Ejemplo n.º 8
0
int physics_init()
{
  real v0_multiply;

  // Read initial conditions

  grid_load2d(N0, "density");
  grid_load2d(P0, "pressure");
  V0.covariant = false; // Read contravariant components
  V.covariant = false; // Evolve contravariant components
  grid_load2d(V0, "v");
  g.covariant = false;
  grid_load2d(g, "g");
  
  // read options
  
  options.setSection("gas");
  
  options.get("gamma",  gamma_ratio, 5.0/3.0);
  options.get("viscosity", nu, 0.1);
  options.get("include_viscosity", include_viscosity, false);
  options.get("v0_multiply", v0_multiply, 1.0);
  options.get("sub_initial", sub_initial, false);

  V0 *= v0_multiply;

  // Set evolving variables
  
  bout_solve(N, F_N, "density");
  bout_solve(P, F_P, "pressure");
  bout_solve(V, F_V, "v");

  if(!restarting) {
    // Apply boundary conditions
    apply_boundary(N, "density");
    apply_boundary(P, "pressure");
    V.to_contravariant();
    apply_boundary(V, "v");

    // Set variables to these values (+ the initial perturbation)
    // NOTE: This must be after the calls to bout_solve
    N += N0;
    P += P0;
    V += V0;

  }

  // set communications
  comms.add(N);
  comms.add(P);
  comms.add(V);
  
  return 0;
}
Ejemplo n.º 9
0
void MultiReferenceBase::calculateAllDistances( const Pbc& pbc, const std::vector<Value*> & vals, Communicator& comm, Matrix<double>& distances, const bool& squared ) {
  distances=0.0;
  unsigned k=0, size=comm.Get_size(), rank=comm.Get_rank();
  for(unsigned i=1; i<frames.size(); ++i) {
    for(unsigned j=0; j<i; ++j) {
      if( (k++)%size!=rank ) continue;
      distances(i,j) = distances(j,i) = distance( pbc, vals, frames[i], frames[j], squared );
    }
  }
  comm.Sum( distances );
}
Ejemplo n.º 10
0
int main (int argc, char* argv[])
{
  using std::cout;
  using std::endl;
  using std::setw;
  using std::fixed;

#ifndef _SERIAL
  boost::mpi::environment env(argc,argv);
#endif
  Communicator world;

  std::string f_inp = "dmrg.conf";
  std::string f_out;
  std::string prefx = ".";

  for(int iarg = 0; iarg < argc; ++iarg) {
    if(strcmp(argv[iarg],"-i") == 0) f_inp = argv[++iarg];
    if(strcmp(argv[iarg],"-o") == 0) f_out = argv[++iarg];
    if(strcmp(argv[iarg],"-s") == 0) prefx = argv[++iarg];
  }

  mpsxx::DMRGInput input(f_inp); input.prefix = prefx;

  //
  // assign cout as alias to fout
  //
  std::streambuf *backup;
  backup = cout.rdbuf();
  std::ofstream fout;
  if(f_out.size() > 0) {
    std::ostringstream oss;
    oss << f_out << "." << world.rank();
    fout.open(oss.str().c_str());
    cout.rdbuf(fout.rdbuf());
  }

  time_stamp ts;

  //
  // dmrg optimization
  //
  input.energy = mpsxx::dmrg(input);

  pout << endl;
  pout.precision(2);
  pout << "\t\t\tTotal elapsed time: " << setw(8) << fixed << ts.elapsed() << endl;

  cout.rdbuf(backup);
  fout.close();

  return 0;
}
Ejemplo n.º 11
0
int main(int argc, char** argv) { 
	MPI_Init(&argc, &argv);
	int dim_num = 6;
	int dim_partition_size = 2;
	int number_of_partitions = 8;
	Communicator world;
	int size = world.size() - 1;
	IntegratorMain::Root root;
	root.main(dim_num, dim_partition_size, number_of_partitions, size);
	
	MPI_Finalize();
	return 0;
}
Ejemplo n.º 12
0
int
main (int argc, char* argv[])
{
  Communicator* comm = Communicator::instance();
  if (comm->init () == -1)
    return -1;
  
  Endpoint endpoint ("TCP", "", 3000);
  ObjectAdapter* oa = comm->createObjectAdapterWithEndpoint ("MyHello", &endpoint);
  Object* object = new demo::MyHelloI;
  oa->add (object, "MyHello");

  comm->run ();

  return 0;
}
Ejemplo n.º 13
0
static void *FramebufferDispenser(void *_args) {
    cout << "DISPENSER" << endl;
    Communicator *s = ((DispenserArgs *) _args)->mpCommunicator;
    int size = ((DispenserArgs *) _args)->mSize;
    DispenserArgs *args = (DispenserArgs *) _args;
    try {
        Communicator *c = const_cast<Communicator *> (s->Accept());
        char token;
        while (true) {
            c->Read(&token, 1);
            args->mpHandler->RequestUpdate();
            XRenderComposite(args->mpDpy, PictOpSrc, args->mSrc, None,
                    args->mDst, 0, 0, 0, 0, 0, 0, args->mWidth, args->mHeight);
            args->mpImage = XGetSubImage(args->mpDpy, args->mPixmap, 0, 0,
                    args->mWidth, args->mHeight, XAllPlanes(), ZPixmap,
                    args->mpImage, 0, 0);
            if (!args->mUseShm)
                c->Write((const char *) args->mpImage->data, size);
            else
                c->Write((const char *) &token, 1);
            c->Sync();
        }
    } catch (const char *ex) {
        cout << "FramebufferDispenser" << endl;
        cout << ex << endl;
        cout << strerror(errno) << endl;
    }
    return NULL;
}
Ejemplo n.º 14
0
void MainWindow::ok_presed()
{
Communicator m;

Request r;
r.setHost("vkontakte.ru");
r.setPath("login.php");/*vkontakte.ru/*/
r.setParam("act","login");
r.setParam("email","*****@*****.**");
r.setParam("pass","ctfface3");
r.setoHeader("User-Agent","Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.9b5) Gecko/2008050509 Firefox/3.0b5");
r.setoHeader("Accept","text/html");
m_ui->label->setText(r.toString());
Answer *a=m.get(r);
m_ui->label_2->setText(a->redirectLocate());


}
Ejemplo n.º 15
0
// short test to see if MPI surrogate function do what they should
void small_test_mpi() {
  Communicator comm;
  Vector x0(1,2,3),x=x0;
  Vector y0(4,5,6),y=y0;
  
  plumed_assert(x[0]==x0[0] && x[1]==x0[1] && x[2]==x0[2]);
  plumed_assert(y[0]==y0[0] && y[1]==y0[1] && y[2]==y0[2]);
  comm.Sum(x);
  plumed_assert(x[0]==x0[0] && x[1]==x0[1] && x[2]==x0[2]);
  plumed_assert(y[0]==y0[0] && y[1]==y0[1] && y[2]==y0[2]);
  comm.Allgather(x,y);
  plumed_assert(x[0]==x0[0] && x[1]==x0[1] && x[2]==x0[2]);
  plumed_assert(y[0]==x0[0] && y[1]==x0[1] && y[2]==x0[2]);
  std::vector<int> count(1,3);
  std::vector<int> displ(1,0);
  x=x0;
  y=y0;
  comm.Allgatherv(y,x,count.data(),displ.data());
  plumed_assert(x[0]==y0[0] && x[1]==y0[1] && x[2]==y0[2]);
  plumed_assert(y[0]==y0[0] && y[1]==y0[1] && y[2]==y0[2]);
}
Ejemplo n.º 16
0
int main(int argc, char** argv) { 
	MPI_Init(&argc, &argv);
	Communicator world;
	if(world.size() == 1) {
		std::cerr << ">1 process please." << std::endl;
		return 1;
	}
	if(world.rank() == 0) {
		int dim_num = 6;
		int dim_partition_size = 2;
		int number_of_partitions = 8;
		int size = world.size() - 1;
		IntegratorMain::Root root;
		root.main(dim_num, dim_partition_size, number_of_partitions, size);
		MPI_Finalize();
		return 0;
	}
	else {
		int it_max = 5;
		double tol = 0.000001;

		int dim_num = 6;
		int dim_partition_size = 2;
		int number_of_partitions = 8;

		int size = world.size() - 1;
		int i = world.rank() - 1;
		std::cout << "Createing Peer(" << i << "," << size << ")" << std::endl;
		IntegratorMain::Peer peer(i, size);
		peer.main(it_max, tol, dim_num, dim_partition_size, number_of_partitions);
		MPI_Finalize();

		return 0;
	}
}
Ejemplo n.º 17
0
int main(){
	Communicator* comm = new Communicator(512, "192.168.2.1", 9000, "*", 9001);

	//initialize camera
    VideoCapture cap(0);
    if(!cap.isOpened()){
        cout << "No camera found." << endl;
        return -1;
    }

    cap.set(CV_CAP_PROP_FRAME_WIDTH,320);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT,240);
    cap.set(CV_CAP_PROP_FPS, 30);

    //initialize frame
    Mat frame; Mat grayFrame;
    cap >> frame;
    
    //give information to PC about frame size
    char frameWidthBuf[3];
    char frameHeightBuf[3];
    sprintf(frameWidthBuf, "%d", frame.rows);
    sprintf(frameHeightBuf, "%d", frame.cols);
    comm->send(frameWidthBuf, 3, 0);
    comm->send(frameHeightBuf, 3, 0);
    int frameSize = frame.rows*frame.cols;

    //for encoding the frame
    vector<uchar> enc;

    while(1){
    	// capture gray image
        cap >> frame;
    	cvtColor(frame, grayFrame, CV_BGR2GRAY);

        // send encoded image
    	comm->send(grayFrame.data, frameSize, 0);
    }
}
bool Service::requestService(string SPaddress, string SPport) {
	Communicator comm;
	Socket serviceProvider;
	if (!comm.connectTo(SPaddress, SPport, serviceProvider)) {
		cerr << "Impossibile connettersi al Service Provider\n";
		return false;
	}
	// Questo invio serve al Service Provider per sapere quale servizio viene richiesto
	if (!serviceProvider.sendString(name)) {
		cerr << "Errore nell'invio del nome del servizio richiesto\n";
		return false;
	}
	// Questo invio serve a controllare che il nome del servizio sia corretto
	if (!serviceProvider.sendString(name)) {
		cerr << "Errore nell'invio del nome del servizio richiesto\n";
		return false;
	}
	if (!sendParameters(serviceProvider, inParameters)) {
		cerr << "Errore nell'invio dei parametri di ingresso del servizio\n";
		return false;
	}
	if (!sendParameters(serviceProvider, outParameters)) {
		cerr << "Errore nell'invio dei parametri di uscita del servizio\n";
		return false;
	}
	Response response;
	if (!receiveResponse(serviceProvider, response)) {
		cerr << "Errore nella ricezione della risposta\n";
		return false;
	}
	if (!response.getResult()) {
		cerr << response.getMessage() << endl;
		return false;
	}
	outParameters = response.getParameters();
	comm.closeAllCommunications();
	return true;
}
Ejemplo n.º 19
0
int
Subscriber::run(int argc, char* argv[]) {
  Communicator* comm = Communicator::instance();
  if (comm->init (true) == -1)
    return -1;

  Reference ref (comm, Identity("TopicManager"), Endpoint("TCP", "127.0.0.1", 5555));
  IcmProxy::IcmMsg::TopicManager topicManager;
  topicManager.setReference (&ref);

  ObjectAdapter* adapter = comm->createObjectAdapterWithEndpoint("Subscriber", "127.0.0.1 8888");
  IcmProxy::Object* networkProxy = adapter->add(new NetworkI(), "NetworkTopic");

  ::IcmProxy::IcmMsg::Topic* topic = topicManager.retrieve("NetworkTopic");
  if(topic == 0)
	  topic = topicManager.create("NetworkTopic");
  if (topic == 0)
    return -1;
  topic->subscribe(networkProxy);

  comm->run();

  return 0;
}
Ejemplo n.º 20
0
int
main (int argc, char* argv[])
{
  Communicator* comm = Communicator::instance();
  if (comm->init () == -1)
    return -1;

  demo::DelayResponse* task = new demo::DelayResponse;

  Endpoint endpoint ("TCP", "", 3000);
  ObjectAdapter* oa = comm->createObjectAdapterWithEndpoint ("MyHello", &endpoint);

  demo::AmhMyHelloI*  amh = new demo::AmhMyHelloI;
  amh->set(task);
  oa->add (amh, "MyHello");

  task->activate();

  comm->run ();

  delete task;

  return 0;
}
Ejemplo n.º 21
0
int physics_run(real t)
{
  //output.write("Running %e\n", t);
  // Run communications
  comms.run();

  // Density
  
  F_N = -V_dot_Grad(V, N) - N*Div(V);
 
  //output.write("N ");
 
  // Velocity 
  
  F_V = -V_dot_Grad(V, V) - Grad(P)/N + g;

  if(sub_initial) {
    F_V += Grad(P0)/N0 - g;
  }

  //output.write("V ");

  if(include_viscosity) {
    // Add viscosity
    
    F_V.y += nu*Laplacian(V.y);
    F_V.z += nu*Laplacian(V.z);

    //output.write("nu ");
  }
  
  // Pressure

  F_P = -V_dot_Grad(V, P) - gamma_ratio*P*Div(V);

  //output.write("P\n");

  // Set boundary conditions
  apply_boundary(F_N, "density");
  apply_boundary(F_P, "pressure");
  F_V.to_contravariant();
  apply_boundary(F_V, "v");

  //output.write("finished\n");

  return 0;
}
Ejemplo n.º 22
0
std::string Timer::elapsedCpuTime(const Communicator &comm) const
{
    std::chrono::duration<double, std::nano> dur(comm.sum((end_ - start_).count()));
    std::ostringstream sout;

    Hours hours = std::chrono::duration_cast<Hours>(dur);
    dur -= hours;

    Minutes minutes = std::chrono::duration_cast<Minutes>(dur);
    dur -= minutes;

    Seconds seconds = std::chrono::duration_cast<Seconds>(dur);

    sout << hours.count() << ":" << minutes.count() << ":" << seconds.count();

    return sout.str();
}
Ejemplo n.º 23
0
int physics_run(real t)
{
  // Run communications
  comms.run();

  msg_stack.push("F_rho");
  
  F_rho = -V_dot_Grad(v, rho) - rho*Div(v);

  msg_stack.pop(); msg_stack.push("F_p");

  F_p = -V_dot_Grad(v, p) - gamma*p*Div(v);
  
  msg_stack.pop(); msg_stack.push("F_v");
  
  F_v = -V_dot_Grad(v, v) + ((Curl(B)^B) - Grad(p))/rho;

  if(include_viscos) {
    F_v.x += viscos * Laplacian(F_v.x);
    F_v.y += viscos * Laplacian(F_v.y);
    F_v.z += viscos * Laplacian(F_v.z);
  }
  
  msg_stack.pop(); msg_stack.push("F_B");
  
  F_B = Curl(v^B);

  // boundary conditions

  apply_boundary(F_rho, "density");
  apply_boundary(F_p, "pressure");
  F_v.to_covariant();
  apply_boundary(F_v, "v");
  F_B.to_contravariant();
  apply_boundary(F_B, "B");

  msg_stack.pop(); msg_stack.push("DivB");
  
  divB = Div(B); // Just for diagnostic
  bndry_inner_zero(divB);
  bndry_sol_zero(divB);

  return 0;
}
Ejemplo n.º 24
0
// -------------------------------------------------------------
// petscStorageType
// -------------------------------------------------------------
/// 
inline MatType
petscStorageType(const Communicator& comm, const Matrix::StorageType& gtype)
{
  int nproc(comm.size());
  MatType result;
  switch (new_type) {
  case (Matrix::Dense):
    if (nproc > 1) {
      new_mat_type = MATMPIDENSE;
    } else {
      new_mat_type = MATSEQDENSE;
    } 
    break;
  case (Matrix::Sparse):
    if (nproc > 1) {
      new_mat_type = MATMPIAIJ;
    } else {
      new_mat_type = MATSEQAIJ;
    } 
    break;
   default:
     BOOST_ASSERT(false); 
  }
}
Ejemplo n.º 25
0
int physics_run(real t)
{
  //real bmk_t = MPI_Wtime();
  
  // Communicate variables
  comms.run();
  
  // Update profiles
  Nit = Ni0  + Ni.DC();
  Tit = Ti0  + Ti.DC();
  Tet = Te0  + Te.DC();
  Vit = Vi0  + Vi.DC();

  // Update non-linear coefficients on the mesh
  kapa_Te = 3.2*(1./fmei)*(wci/nueix)*(Tet^2.5);
  kapa_Ti = 3.9*(wci/nuiix)*(Tit^2.5);

  // note: nonlinear terms are not here
  peit = (Tet+Tit)*Nit;

  // DENSITY EQUATION
  F_Ni = -Vpar_Grad_par(Vit, Nit) 
    -Nit*Div_par(Vit) 
    +Div_X_K_Grad_X(D_perp*(Nit*0.0+1.0), Nit)
    ;


  // ION VELOCITY
  //F_Vi = -Grad_par(peit)/Nit -Vpar_Grad_par(Vit, Vit) + mu_perp*Delp2(Nit*Vit)/Nit;
  F_Vi = (
	  -Grad_par(peit) 
	  +Div_X_K_Grad_X(mu_perp*Nit, Vit)
	  )/Nit 
    -Vpar_Grad_par(Vit, Nit*Vit)/Nit 
    - F_Ni*Vit/Nit
    ;


  // ELECTRON TEMPERATURE
  F_Te = (Div_par_K_Grad_par(kapa_Te, Tet) 
	  +Div_X_K_Grad_X(chi_perp*Nit, Tet)
	  )/(1.5*Nit) 
    - F_Ni*Tet/Nit;


  // ION TEMPERATURE
  F_Ti = (Div_par_K_Grad_par(kapa_Ti, Tit) 
	  +Div_X_K_Grad_X(chi_perp*Nit, Tit)
	  )/(1.5*Nit)
    - F_Ni*Tit/Nit;


  // INNER TARGET PLATE
  
  bndry_ydown_flat(F_Ni); // Zero-gradient Ni
  bndry_ydown_relax_val(F_Vi, Vit, -3.095e4/Vi_x);
  bndry_ydown_relax_val(F_Te, Tet, 10./Te_x);
  bndry_ydown_relax_val(F_Ti, Tit, 10./Te_x);

  // OUTER TARGET PLATE

  bndry_yup_flat(F_Ni);
  bndry_yup_relax_val(F_Vi, Vit, 3.095e4/Vi_x);
  bndry_yup_relax_val(F_Te, Tet, 10./Te_x);
  bndry_yup_relax_val(F_Ti, Tit, 10./Te_x);
  
  // CORE BOUNDARY

  bndry_core_relax_val(F_Ni, Nit, 1e13/Ni_x);
  bndry_core_flat(F_Vi);
  bndry_core_relax_val(F_Te, Tet, 100./Te_x, lambda_relax);
  bndry_core_relax_val(F_Ti, Tit, 100./Te_x, lambda_relax);
  
  // PF BOUNDARY

  bndry_pf_relax_val(F_Ni, Nit, 1e12/Ni_x);
  bndry_pf_flat(F_Vi);
  bndry_pf_relax_val(F_Te, Tet, 10./Te_x);
  bndry_pf_relax_val(F_Ti, Tit, 10./Te_x);
  
  // OUTER BOUNDARY

  bndry_sol_relax_val(F_Ni, Nit, 1e12/Ni_x);
  bndry_sol_flat(F_Vi);
  bndry_sol_relax_val(F_Te, Tet, 10./Te_x);
  bndry_sol_relax_val(F_Ti, Tit, 10./Te_x);

  //output.write("TIMING: %e\n", MPI_Wtime() - bmk_t);

  return(0);
}
Ejemplo n.º 26
0
double Timer::elapsedSeconds(const Communicator& comm) const
{
    return comm.broadcast(comm.mainProcNo(), elapsedSeconds());
}
Ejemplo n.º 27
0
int main(int argc, char *argv[]){
	Communicator* comm = new Communicator(512, "10.42.0.1", 8000, "*", 8002);

    thread t(recvOdometry, comm);

	//initialize laser
    urg_t urg;
    long int *scan;
    long max_distance = 5000;
    long min_distance = 150;
    long time_stamp;
    int i;
    int n;

    //check if laser is available
    if (open_urg_sensor(&urg, argc, argv) < 0) {
        return -1;
    }

    //allocate necessary memory for scanning
    int numberOfPoints = 685;
    int sizeOfScan = sizeof(int);
    int bytesPerScan = numberOfPoints*sizeOfScan;
    scan = (long int*)malloc(urg_max_data_size(&urg) * sizeof(scan[0]));
    if (!scan) {
        perror("urg_max_index()");
        return -1;
    }

    //allocate memory for unsigned int
    int* intScan = (int*) malloc(bytesPerScan);


    //give information to PC about bytes per scan
    char buf[4];
    sprintf(buf, "%d", bytesPerScan);
    comm->send(buf, 4, 0);

    cout << numberOfPoints << endl;
    cout << sizeOfScan << endl;

    while(1){
    	//get new scan
        urg_start_measurement(&urg, URG_DISTANCE, 1, 0);
        n = urg_get_distance(&urg, scan, &time_stamp);
        if (n < 0) {
            printf("urg_get_distance: %s\n", urg_error(&urg));
            urg_close(&urg);
            return -1;
        }

        //first four values are odometry
        //put latest odometry-data in scan.
        mtx.lock();
        intScan[0] = dx;
        intScan[1] = dy;
        intScan[2] = tyaw;
        intScan[3] = tt;
        tt = 0;
        tyaw = 0;
        mtx.unlock();

        //better to parse to unsigned ints --> less data will be sent
        for(int i=4; i<numberOfPoints; i++){
            intScan[i] = (int)scan[i];
        }

        //send new scan
        comm->send(intScan, bytesPerScan, 0);
    }

    t.join();

    delete scan;
    urg_close(&urg);
}
Ejemplo n.º 28
0
int main(int argc, char* argv[]) {
  struct sigaction sa;
  sigemptyset(&sa.sa_mask);
  sa.sa_handler = SIG_IGN;
  sa.sa_flags = 0;
  sigaction( SIGPIPE, &sa, 0 );

  Communicator* comm = Communicator::instance();
  if (comm->init() == -1)
    return -1;

  //Reference ref(comm, Identity("MyHello"), Endpoint("TCP", "127.0.0.1", 3000));
  Reference ref(comm, Identity("MyHello"), Endpoint("TCP", "172.16.10.23", 3000), new TimeValue(3));
  IcmProxy::demo::MyHello myHello;
  myHello.setReference(&ref);

  Short u = 15;
  Long v;

  while(true) {

  ICC_DEBUG("sync calling.......");
  sleep(1);
  string ret = myHello.sayHello("Hello, sync1", u, v);
  if(ret == "") {
    cout << "call error!!" << endl;
  } else {
    cout << "call success!!" << endl;
    cout << "u:" << u << " v:" << v << " ret:" << ret << endl;
  }

  } // while

//  ICC_DEBUG("sync calling.......");
//  ret = myHello.sayHello("Hello, sync2", u, v);
//  cout << "u:" << u << " v:" << v << " ret:" << ret << endl;

//  ICC_DEBUG("async calling.......");
//  myHello.sayHello_async(new AMI_MyHello_sayHelloI, "Hello, async1", u);
//
//  ICC_DEBUG("async calling.......");
//  myHello.sayHello_async(new AMI_MyHello_sayHelloI, "Hello, async2", u);
//
//  ICC_DEBUG("async calling.......");
//  myHello.sayHello_async(new AMI_MyHello_sayHelloI, "Hello, async3", u);

//  static const char* __operation("sayHello");
//  TwowayAsynchInvocation _invocation (&ref, __operation, ref.communicator (), new AMI_MyHello_sayHelloI, ref.getMaxWaitTime());
//  IcmTransport * p = 0;
//  int ok = _invocation.start (p);
//  if (ok != 0)
//  {
//    IcmProxy::setCallErrno( ICM_INVOCATION_START_FAILED );
//    ICC_ERROR("invocation start ERROR!!!!!!");
//    return -1;
//  }
//  ok = _invocation.prepareHeader (1);
//  if (ok != 0)
//  {
//    IcmProxy::setCallErrno( ICM_INVOCATION_PREPAREHEADER_FAILED );
//    return -1;
//  }
//  OutputStream* __os = _invocation.outStream();
//  __os->write_string("Hello, asynctest");
//  __os->write_short(u);
////  ok = _invocation.invoke();
////  if(ok != 0)
////  {
////    IcmProxy::setCallErrno( ICM_INVOCATION_INVOKE_FAILED );
//////    this->transport(0);
////    ICC_ERROR("invocation start ERROR!!!!!!");
////    return -1;
////  }
//  int retval = _invocation.mTransport->tms()->bindDispatcher (_invocation.requestId(), _invocation.mRd);
//  if (retval == -1) {
////    this->closeConnection ();
//    return -1;
//  }
//  if(_invocation.mTransport->sendRequest(&ref,
//                                   comm,
//                                   *__os,
//                                   false,
//                                   0) == -1) {
//
//    return -1;
//  }


//  Rcver rcver(*comm, myHello);
//  rcver.activate();
//
//  comm->run();

//  while(true) {
//
//    ICC_DEBUG("async calling.......");
//    myHello.sayHello_async(new AMI_MyHello_sayHelloI, "Hello, sync1", u);
//    sleep(10);
//  } // while

  return 0;
}
Ejemplo n.º 29
0
int physics_init()
{
  Field2D I; // Shear factor 
  
  output.write("Solving 6-variable 2-fluid equations\n");

  /************* LOAD DATA FROM GRID FILE ****************/

  // Load 2D profiles (set to zero if not found)
  GRID_LOAD(Ni0);
  GRID_LOAD(Ti0);
  GRID_LOAD(Te0);
  GRID_LOAD(Vi0);

  // Load metrics
  GRID_LOAD(Rxy);
  GRID_LOAD(Bpxy);
  GRID_LOAD(Btxy);
  GRID_LOAD(hthe);
  grid.get(dx,   "dpsi");

  // Load normalisation values
  GRID_LOAD(Te_x);
  GRID_LOAD(Ti_x);
  GRID_LOAD(Ni_x);
  GRID_LOAD(bmag);

  Ni_x *= 1.0e14;
  bmag *= 1.0e4;

  /*************** READ OPTIONS *************************/

  // Read some parameters
  options.setSection("2fluid");
  OPTION(AA, 2.0);
  OPTION(ZZ, 1.0);

  OPTION(chi_perp,  0.6); // Read in m^2 / s 
  OPTION(D_perp,    0.6);
  OPTION(mu_perp,   0.6);

  OPTION(lambda_relax, 10.0);
  
  /************** CALCULATE PARAMETERS *****************/

  rho_s = 1.02*sqrt(AA*Te_x)/ZZ/bmag;
  fmei  = 1./1836.2/AA;

  lambda_ei = 24.-log(sqrt(Ni_x)/Te_x);
  lambda_ii = 23.-log(ZZ*ZZ*ZZ*sqrt(2.*Ni_x)/pow(Ti_x, 1.5));
  wci       = 9.58e3*ZZ*bmag/AA;
  nueix     = 2.91e-6*Ni_x*lambda_ei/pow(Te_x, 1.5);
  nuiix     = 4.78e-8*pow(ZZ,4.)*Ni_x*lambda_ii/pow(Ti_x, 1.5)/sqrt(AA);

  Vi_x = wci * rho_s;

  /************** PRINT Z INFORMATION ******************/
  
  real hthe0;
  if(GRID_LOAD(hthe0) == 0) {
    output.write("    ****NOTE: input from BOUT, Z length needs to be divided by %e\n", hthe0/rho_s);
  }

  /************** NORMALISE QUANTITIES *****************/

  output.write("\tNormalising to rho_s = %e\n", rho_s);

  // Normalise profiles
  Ni0 /= Ni_x/1.0e14;
  Ti0 /= Te_x;
  Te0 /= Te_x;
  Vi0 /= Vi_x;

   // Normalise geometry 
  Rxy /= rho_s;
  hthe /= rho_s;
  dx /= rho_s*rho_s*(bmag/1e4);

  // Normalise magnetic field
  Bpxy /= (bmag/1e4);
  Btxy /= (bmag/1e4);
  Bxy  /= (bmag/1e4);

  // calculate pressures
  pei0 = (Ti0 + Te0)*Ni0;
  pe0 = Te0*Ni0;

  // Normalise coefficients
  chi_perp /= rho_s*rho_s*wci;
  D_perp   /= rho_s*rho_s*wci;
  mu_perp  /= rho_s*rho_s*wci;

  chi_perp = 0.1;
  D_perp = 0.1;
  mu_perp = 0.1;
  
  output.write("Diffusion coefficients: chi %e D %e Mu %e\n",
	       chi_perp, D_perp, mu_perp);

  /**************** CALCULATE METRICS ******************/

  g11 = (Rxy*Bpxy)^2;
  g22 = 1.0 / (hthe^2);
  g33 = (Bxy^2)/g11;
  g12 = 0.0;
  g13 = 0.0;
  g23 = -Btxy/(hthe*Bpxy*Rxy);
  
  J = hthe / Bpxy;
  
  g_11 = 1.0/g11;
  g_22 = (Bxy*hthe/Bpxy)^2;
  g_33 = Rxy*Rxy;
  g_12 = 0.0;
  g_13 = 0.0;
  g_23 = Btxy*hthe*Rxy/Bpxy;


  /**************** SET EVOLVING VARIABLES *************/

  // Tell BOUT++ which variables to evolve
  // add evolving variables to the communication object

  Ni = Vi = Te = Ti = 0.0;
  bout_solve(Ni,    F_Ni,    "Ni");
  bout_solve(Vi,    F_Vi,    "Vi");
  bout_solve(Te,    F_Te,    "Te");
  bout_solve(Ti,    F_Ti,    "Ti");

  comms.add(Ni);
  comms.add(Vi);
  comms.add(Te);
  comms.add(Ti);

  /************** SETUP COMMUNICATIONS **************/
  
  // Add any other variables to be dumped to file
  dump.add(Ni0, "Ni0", 0);
  dump.add(Te0, "Te0", 0);
  dump.add(Ti0, "Ti0", 0);

  dump.add(Te_x,  "Te_x", 0);
  dump.add(Ti_x,  "Ti_x", 0);
  dump.add(Ni_x,  "Ni_x", 0);
  dump.add(rho_s, "rho_s", 0);
  dump.add(wci,   "wci", 0);

  return(0);
}
Ejemplo n.º 30
0
/// The main dmrg routine.
/// \param input DMRGInput object which contains the diferent parameters that define this dmrg run
std::vector<double> dmrg (const DMRGInput& input)
{
  using std::endl;
  using std::setw;
  using std::setprecision;
  using std::fixed;
  using std::scientific;

  const size_t K_roots = input.N_roots;
  const size_t MAX_ITER = input.N_max_sweep_iter;

  std::vector<double> esav(K_roots,0.0);

  Communicator world;
  time_stamp ts;

  for(size_t iroot = 0; iroot < K_roots; ++iroot) {

    // Build initial MPSs
    if(!input.restart) make_random_mpss(input,iroot);

    bool conv = false;
    // Optimization with sweep algorithm
    for(size_t iter = 0; iter < MAX_ITER && !conv; ++iter) {

      pout << "\t====================================================================================================" << endl;
      pout << "\t\tSWEEP ITERATION [ " << setw(4) << iter << " ] :: ROOT = " << setw(2) << iroot << endl;
      pout << "\t====================================================================================================" << endl;

      ts.start();

      double eswp = make_sweep(esav,input,iroot);

      double edif = eswp-esav[iroot];
      pout << "\t====================================================================================================" << endl;
      pout << "\t\tSWEEP ITERATION [ " << setw(4) << iter << " ] :: ROOT = " << setw(2) << iroot << " FINISHED"
           << " ( " << fixed << setprecision(2) << setw(8) << ts.lap() << " sec. ) " << endl;
      pout.precision(16);
      pout << "\t\t\tSweep Energy = " << setw(24) << fixed << eswp << " ( delta E = ";
      pout.precision(2);
      pout << setw(8) << scientific << edif << " ) " << endl;
      pout << endl;
      if(world.rank() == 0) {
        esav[iroot] = eswp;
        if(iter > 0 && std::fabs(edif) < input.tolerance) conv = true;
      }
#ifndef _SERIAL
      boost::mpi::broadcast(world,conv,0);
      boost::mpi::broadcast(world,esav,0);
#endif
    }
    // Stop by no convergence
    if(!conv) {
      pout << "\t+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-" << endl;
      pout << "\t\tNO CONVERGENCE MET FOR ROOT = " << setw(2) << iroot << endl;
      pout << "\t\tPROGRAM STOPPED..." << endl;
      break;
    }

    if(input.algorithm == ONESITE) continue;

    DMRGInput in2nd = input;
    in2nd.algorithm = ONESITE;
    in2nd.restart   = true;

    conv = false;
    // Optimization with sweep algorithm
    for(size_t iter = 0; iter < MAX_ITER && !conv; ++iter) {

      pout << "\t====================================================================================================" << endl;
      pout << "\t\tSWEEP ITERATION [ " << setw(4) << iter << " ] :: ROOT = " << setw(2) << iroot << endl;
      pout << "\t====================================================================================================" << endl;

      ts.start();

      double eswp = make_sweep(esav,in2nd,iroot);

      double edif = eswp-esav[iroot];
      pout << "\t====================================================================================================" << endl;
      pout << "\t\tSWEEP ITERATION [ " << setw(4) << iter << " ] :: ROOT = " << setw(2) << iroot << " FINISHED"
           << " ( " << fixed << setprecision(2) << setw(8) << ts.lap() << " sec. ) " << endl;
      pout.precision(16);
      pout << "\t\t\tSweep Energy = " << setw(24) << fixed << eswp << " ( delta E = ";
      pout.precision(2);
      pout << setw(8) << scientific << edif << " ) " << endl;
      pout << endl;
      if(world.rank() == 0) {
        esav[iroot] = eswp;
        if(iter > 0 && std::fabs(edif) < in2nd.tolerance) conv = true;
      }
#ifndef _SERIAL
      boost::mpi::broadcast(world,conv,0);
      boost::mpi::broadcast(world,esav,0);
#endif
    }
    // Stop by no convergence
    if(!conv) {
      pout << "\t+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-" << endl;
      pout << "\t\tNO CONVERGENCE MET FOR ROOT = " << setw(2) << iroot << endl;
      pout << "\t\tPROGRAM STOPPED..." << endl;
      break;
    }
//  gaugefix<fermion>(input,iroot);
  }
  pout << "\t====================================================================================================" << endl;
  pout.precision(16);
  for(size_t iroot = 0; iroot < K_roots; ++iroot) {
    pout << "\t\t\tSweep Energy = " << setw(24) << fixed << esav[iroot] << endl;
  }

  return esav;
}