本文整理汇总了C++中Communicator类的典型用法代码示例。如果您正苦于以下问题:C++ Communicator类的具体用法?C++ Communicator怎么用?C++ Communicator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Communicator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: siteIndexOf
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
}
示例2: main
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;
}
示例3: fin
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;
}
}
示例4: main
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;
}
示例5: clientThread
void * clientThread(void * param) {
int clientSocket = *(unsigned int *)param;
Communicator communicator;
communicator.handleClientConnection(clientSocket);
pthread_exit(NULL);
}
示例6: Communicator
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();
}
示例7: calculateAllDistances
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 );
}
示例8: main
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;
}
示例9: main
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;
}
示例10: main
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;
}
示例11: while
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;
}
示例12: ok_presed
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","[email protected]");
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());
}
示例13: small_test_mpi
// 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]);
}
示例14: main
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;
}
}
示例15: main
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);
}
}