// ============================================================================ StatusCode Tuples::TupleObj::column ( const std::string& name , const bool value ) { if ( invalid() ) { return InvalidTuple ; } Bool* item = bools( name ) ; if ( !item ) { return InvalidColumn ; } *item = value ; return StatusCode::SUCCESS ; }
inline typename vector<T,D>::bools vector<T,D>::_cmp( const_ref vec ) const { bools::type res = 0; Op op; for ( dim i = 0; i<D; ++i ) { if ( op( data[i], vec.data[i] ) ) res |= (1<<i); } return bools( res ); }
/* This test *may* deadlock if we don't use non-blocking communication */ void TestNonBlockingSendingClass() throw (Exception) { ObjectCommunicator<ClassOfSimpleVariables> communicator; { // Create a simple class to send std::vector<double> doubles(3); doubles[0] = 1.1; doubles[1] = 1.2; doubles[2] = 1.3 + PetscTools::GetMyRank(); std::vector<bool> bools(2); bools[0] = true; bools[1] = true; boost::shared_ptr<ClassOfSimpleVariables> p_new_class(new ClassOfSimpleVariables(42,"hello",doubles,bools)); // Send the class for (unsigned p=0; p < PetscTools::GetNumProcs(); p++) { if (p != PetscTools::GetMyRank()) { p_new_class->mVectorOfDoubles[1] = 1.2 + p; // Arguments are object, destination, tag communicator.ISendObject(p_new_class, p, 123 + PetscTools::GetMyRank()); } } } { boost::shared_ptr<ClassOfSimpleVariables> p_recv_class; for (unsigned p=0; p < PetscTools::GetNumProcs(); p++) { if (p != PetscTools::GetMyRank()) { communicator.IRecvObject(p, 123 + p); p_recv_class = communicator.GetRecvObject(); // Check that the values are correct TS_ASSERT_EQUALS(p_recv_class->GetNumber(),42); TS_ASSERT_EQUALS(p_recv_class->GetString(),"hello"); TS_ASSERT_EQUALS(p_recv_class->GetVectorOfDoubles().size(),3u); TS_ASSERT_EQUALS(p_recv_class->GetVectorOfBools().size(),2u); TS_ASSERT_DELTA(p_recv_class->GetVectorOfDoubles()[0],1.1,1e-12); TS_ASSERT_DELTA(p_recv_class->GetVectorOfDoubles()[1],1.2 + PetscTools::GetMyRank(),1e-12); TS_ASSERT_DELTA(p_recv_class->GetVectorOfDoubles()[2],1.3 + p,1e-12); TS_ASSERT(p_recv_class->GetVectorOfBools()[0]); TS_ASSERT(p_recv_class->GetVectorOfBools()[1]); } } } PetscTools::Barrier("Make sure that no ISendObject buffers are in use before proceeding"); }
/** We cannot pre-post Irecv because we need to know the (dynamic) size of the object being sent first */ void TestNonBlockingRecvClass() throw (Exception) { ObjectCommunicator<ClassOfSimpleVariables> communicator; if (PetscTools::AmMaster()) { // Create a simple class to send std::vector<double> doubles(3); doubles[0] = 1.1; doubles[1] = 1.2; doubles[2] = 1.3; std::vector<bool> bools(2); bools[0] = true; bools[1] = true; boost::shared_ptr<ClassOfSimpleVariables> p_new_class(new ClassOfSimpleVariables(42,"hello",doubles,bools)); // Send the class for (unsigned p=1; p < PetscTools::GetNumProcs(); p++) { // Arguments are object, destination, tag p_new_class->mVectorOfDoubles[1] = 1.2 + p; communicator.ISendObject(p_new_class, p, 123); } } else { boost::shared_ptr<ClassOfSimpleVariables> p_recv_class; TS_ASSERT_THROWS_THIS(p_recv_class = communicator.GetRecvObject(), "No object to receive in ObjectCommunicator::GetRecvObject"); // Receive the string. This returns before the receive is complete. communicator.IRecvObject(0, 123); // Get an object from the communicator. Implicit MPI_Wait. p_recv_class = communicator.GetRecvObject(); // Check that the values are correct TS_ASSERT_EQUALS(p_recv_class->GetNumber(),42); TS_ASSERT_EQUALS(p_recv_class->GetString(),"hello"); TS_ASSERT_EQUALS(p_recv_class->GetVectorOfDoubles().size(),3u); TS_ASSERT_EQUALS(p_recv_class->GetVectorOfBools().size(),2u); TS_ASSERT_DELTA(p_recv_class->GetVectorOfDoubles()[0],1.1,1e-12); TS_ASSERT_DELTA(p_recv_class->GetVectorOfDoubles()[1],1.2+PetscTools::GetMyRank(),1e-12); TS_ASSERT_DELTA(p_recv_class->GetVectorOfDoubles()[2],1.3,1e-12); TS_ASSERT(p_recv_class->GetVectorOfBools()[0]); TS_ASSERT(p_recv_class->GetVectorOfBools()[1]); } PetscTools::Barrier("Make sure that no ISendObject buffers are in use before proceeding"); }
int main() { std::vector<bool> bools(10, true); for(auto b : bools) std::cout << std::boolalpha << b << " "; std::cout << "\n"; for(auto b : bools) b = false; for(auto b : bools) std::cout << std::boolalpha << b << " "; }
void TestSendingClass() throw (Exception) { MPI_Status status; ObjectCommunicator<ClassOfSimpleVariables> communicator; if (PetscTools::AmMaster()) { // Create a simple class to send std::vector<double> doubles(3); doubles[0] = 1.1; doubles[1] = 1.2; doubles[2] = 1.3; std::vector<bool> bools(2); bools[0] = true; bools[1] = true; boost::shared_ptr<ClassOfSimpleVariables> p_new_class(new ClassOfSimpleVariables(42,"hello",doubles,bools)); // Send the class for (unsigned p=1; p < PetscTools::GetNumProcs(); p++) { // Arguments are object, destination, tag communicator.SendObject(p_new_class, p, 123); } } else { boost::shared_ptr<ClassOfSimpleVariables> p_recv_class; p_recv_class = communicator.RecvObject(0, 123, status); // Check that the values are correct TS_ASSERT_EQUALS(p_recv_class->GetNumber(),42); TS_ASSERT_EQUALS(p_recv_class->GetString(),"hello"); TS_ASSERT_EQUALS(p_recv_class->GetVectorOfDoubles().size(),3u); TS_ASSERT_EQUALS(p_recv_class->GetVectorOfBools().size(),2u); TS_ASSERT_DELTA(p_recv_class->GetVectorOfDoubles()[0],1.1,1e-12); TS_ASSERT_DELTA(p_recv_class->GetVectorOfDoubles()[1],1.2,1e-12); TS_ASSERT_DELTA(p_recv_class->GetVectorOfDoubles()[2],1.3,1e-12); TS_ASSERT(p_recv_class->GetVectorOfBools()[0]); TS_ASSERT(p_recv_class->GetVectorOfBools()[1]); } }
void TestSendRecv() throw (Exception) { if (PetscTools::GetNumProcs() == 2) { MPI_Status status; ObjectCommunicator<ClassOfSimpleVariables> communicator; // Create a simple class to send std::vector<double> doubles(3); doubles[0] = 1.1; doubles[1] = 1.2; doubles[2] = 1.3; std::vector<bool> bools(2); bools[0] = true; bools[1] = true; boost::shared_ptr<ClassOfSimpleVariables> p_send_class(new ClassOfSimpleVariables(42,"hello",doubles,bools)); boost::shared_ptr<ClassOfSimpleVariables> p_class(new ClassOfSimpleVariables); // Arguments are object, destination, tag p_class = communicator.SendRecvObject(p_send_class, 1-PetscTools::GetMyRank(), 123, 1-PetscTools::GetMyRank(), 123, status); // Check that the values are correct TS_ASSERT_EQUALS(p_class->GetNumber(),42); TS_ASSERT_EQUALS(p_class->GetString(),"hello"); TS_ASSERT_EQUALS(p_class->GetVectorOfDoubles().size(),3u); TS_ASSERT_EQUALS(p_class->GetVectorOfBools().size(),2u); TS_ASSERT_DELTA(p_class->GetVectorOfDoubles()[0],1.1,1e-12); TS_ASSERT_DELTA(p_class->GetVectorOfDoubles()[1],1.2,1e-12); TS_ASSERT_DELTA(p_class->GetVectorOfDoubles()[2],1.3,1e-12); TS_ASSERT(p_class->GetVectorOfBools()[0]); TS_ASSERT(p_class->GetVectorOfBools()[1]); } }