On Thu, Mar 12, 2015 at 11:50 AM, Cody Permann <codyperm...@gmail.com> wrote:
> Try to stay out of parallel_implementation.h. Generally you don't need to > go down that far unless you are adding new type specializations. The > signatures you need for most communication patterns are in parallel.h: > > /** > * Blocking-send to one processor with data-defined type. > */ > template <typename T> > void send (const unsigned int dest_processor_id, > T &buf, > const MessageTag &tag=no_tag) const; > > /** > * Blocking-receive from one processor with data-defined type. > */ > template <typename T> > Status receive (const unsigned int dest_processor_id, > T &buf, > const MessageTag &tag=any_tag) const; > > > So sending/recieving looks more like this: > _communicator.send(rank, some_vector); > _communicator.receive(rank, some_vector): > I tried and it works. Thanks! I think I should add some "tag" for safety, right? But when I try the following, the vector was sent, but never received. Why? _communicator.send(rank, send_vector, 101); _communicator.send(rank, receive_vector, 101); > BTW - When you are using MOOSE, you'll have a built-in Communicator in > every object. It's simply "_comm". > You mean simply use _comm instead of _communicator? What are the differences between them? Thank you, Lei > Cody > > > > > On Thu, Mar 12, 2015 at 10:40 AM Lei Zhao <leizhao...@gmail.com> wrote: > >> Hi All, >> >> I am working on some parallelism with Communicator. But I don't understand >> exactly the syntax of _communicator.send and _communicator.receive. This >> is >> the definition of send for sending a vector in parallel_implementation.h. >> >> *template <typename T>* >> *inline void Communicator::send (const unsigned int dest_processor_id,* >> * std::vector<T> &buf,* >> * const DataType &type,* >> * Request &req,* >> * const MessageTag &tag) const* >> *{* >> * START_LOG("send()", "Parallel");* >> >> *#ifndef NDEBUG* >> * // Only catch the return value when asserts are active.* >> * const int ierr =* >> *#endif* >> * ((this->send_mode() == SYNCHRONOUS) ?* >> * MPI_Issend : MPI_Isend) (buf.empty() ? NULL : &buf[0],* >> * cast_int<int>(buf.size()),* >> * type,* >> * dest_processor_id,* >> * tag.value(),* >> * this->get(),* >> * req.get());* >> >> * libmesh_assert (ierr == MPI_SUCCESS);* >> >> * STOP_LOG("send()", "Parallel");* >> *}* >> >> >> Suppose I want to send a vector<double> from processor 0 to processor 1. I >> tried the following: >> >> if (_communicator.rank() == 0) >> { >> std::vector<double> sender; >> sender.push_back(1.1); >> sender.push_back(2.2); >> Request & req; >> * _communicator.send(1, &sender, MPI::DOUBLE, req, 10.231);* >> } >> else if (_communicator.rank() == 1) >> { >> std::vector<double> receiver(2); >> Request & req; >> * _communicator.receive(0, &receiver, MPI::DOUBLE, req, 10.231);* >> } >> >> >> I encountered the compilation errors as follows. Does anyone know how to >> setup the correct syntax for this case? >> >> >> *'Request' was not declared in this scope'MPI' has not been declared* >> >> >> Thank you very much, >> Lei >> >> >> ------------------------------------------------------------------- >> Lei Zhao >> Research Assistant >> University of Wisconsin-Madison >> 206 Materials Science & Engineering >> 1509 University Avenue >> Madison, WI 53706, US >> Email: lzha...@wisc.edu >> Tel.: (608)332-8385 >> ------------------------------------------------------------ >> ------------------ >> Dive into the World of Parallel Programming The Go Parallel Website, >> sponsored >> by Intel and developed in partnership with Slashdot Media, is your hub >> for all >> things parallel software development, from weekly thought leadership >> blogs to >> news, videos, case studies, tutorials and more. Take a look and join the >> conversation now. http://goparallel.sourceforge.net/ >> _______________________________________________ >> Libmesh-users mailing list >> Libmesh-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/libmesh-users >> > ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Libmesh-users mailing list Libmesh-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libmesh-users