void Foam::multiSolver::setUpParallel() { if (Pstream::master()) { fileNameList roots(Pstream::nProcs()); roots[0] = multiDictRegistry_.rootPath(); manageLocalRoot_ = true; // Receive from slaves for ( int slave=Pstream::firstSlave(); slave<=Pstream::lastSlave(); slave++ ) { IPstream fromSlave(Pstream::blocking, slave); roots[slave] = fileName(fromSlave); } // Distribute for ( int slave=Pstream::firstSlave(); slave<=Pstream::lastSlave(); slave++ ) { OPstream toSlave(Pstream::blocking, slave); if (roots[slave] != roots[slave - 1]) { toSlave << true; } else { toSlave << false; } } } else { // Send to master { OPstream toMaster(Pstream::blocking, Pstream::masterNo()); toMaster << fileName(multiDictRegistry_.rootPath()); } // Receive from master { IPstream fromMaster(Pstream::blocking, Pstream::masterNo()); manageLocalRoot_ = readBool(fromMaster); } } }
Foam::LUscalarMatrix::LUscalarMatrix ( const lduMatrix& ldum, const FieldField<Field, scalar>& interfaceCoeffs, const lduInterfaceFieldPtrsList& interfaces ) { if (Pstream::parRun()) { PtrList<procLduMatrix> lduMatrices(Pstream::nProcs()); label lduMatrixi = 0; lduMatrices.set ( lduMatrixi++, new procLduMatrix ( ldum, interfaceCoeffs, interfaces ) ); if (Pstream::master()) { for ( int slave=Pstream::firstSlave(); slave<=Pstream::lastSlave(); slave++ ) { lduMatrices.set ( lduMatrixi++, new procLduMatrix(IPstream(Pstream::scheduled, slave)()) ); } } else { OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); procLduMatrix cldum ( ldum, interfaceCoeffs, interfaces ); toMaster<< cldum; } if (Pstream::master()) { label nCells = 0; forAll(lduMatrices, i) { nCells += lduMatrices[i].size(); } scalarSquareMatrix m(nCells, nCells, 0.0); transfer(m); convert(lduMatrices); } } else {
Gather<T0>::Gather(const T0& localData, const bool redistribute) : List<T0>(0), nProcs_(max(1, Pstream::nProcs())) { this->setSize(nProcs_); // // Collect sizes on all processor // if (Pstream::parRun()) { if (Pstream::master()) { this->operator[](0) = localData; // Receive data for ( int slave = Pstream::firstSlave(), procIndex = 1; slave <= Pstream::lastSlave(); slave++, procIndex++ ) { IPstream fromSlave(Pstream::scheduled, slave); fromSlave >> this->operator[](procIndex); } // Send data for ( int slave = Pstream::firstSlave(), procIndex = 1; slave <= Pstream::lastSlave(); slave++, procIndex++ ) { OPstream toSlave(Pstream::scheduled, slave); if (redistribute) { toSlave << *this; } else { // Dummy send just to balance sends/receives toSlave << 0; } } } else { // Slave: send my local data to master { OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); toMaster << localData; } // Receive data from master { IPstream fromMaster(Pstream::scheduled, Pstream::masterNo()); if (redistribute) { fromMaster >> *this; } else { label dummy; fromMaster >> dummy; } } }