Revision | b4e5826854ddd5010842a47cda7368e657b121b8 (tree) |
---|---|
Zeit | 2013-06-18 14:37:25 |
Autor | Mikiya Fujii <mikiya.fujii@gmai...> |
Commiter | Mikiya Fujii |
ZindoS::CalcCISMatrix is MPI-parallelized. #31588
git-svn-id: https://svn.sourceforge.jp/svnroot/molds/branches/mpi-cis@1366 1136aad2-a195-0410-b898-f5ea1d11b9d8
@@ -2280,16 +2280,18 @@ void ZindoS::DoCISDirect(){ | ||
2280 | 2280 | void ZindoS::CalcCISMatrix(double** matrixCIS) const{ |
2281 | 2281 | this->OutputLog(this->messageStartCalcCISMatrix); |
2282 | 2282 | double ompStartTime = omp_get_wtime(); |
2283 | + boost::mpi::communicator* world = MolDS_mpi::MpiProcess::GetInstance()->GetCommunicator(); | |
2283 | 2284 | |
2284 | - stringstream ompErrors; | |
2285 | -#pragma omp parallel for schedule(auto) | |
2286 | 2285 | for(int k=0; k<this->matrixCISdimension; k++){ |
2287 | - try{ | |
2288 | - // single excitation from I-th (occupied)MO to A-th (virtual)MO | |
2289 | - int moI = this->GetActiveOccIndex(*this->molecule, k); | |
2290 | - int moA = this->GetActiveVirIndex(*this->molecule, k); | |
2286 | + // single excitation from I-th (occupied)MO to A-th (virtual)MO | |
2287 | + int moI = this->GetActiveOccIndex(*this->molecule, k); | |
2288 | + int moA = this->GetActiveVirIndex(*this->molecule, k); | |
2289 | + if(k%world->size() != world->rank()){continue;} | |
2291 | 2290 | |
2292 | - for(int l=k; l<this->matrixCISdimension; l++){ | |
2291 | + stringstream ompErrors; | |
2292 | +#pragma omp parallel for schedule(auto) | |
2293 | + for(int l=k; l<this->matrixCISdimension; l++){ | |
2294 | + try{ | |
2293 | 2295 | // single excitation from J-th (occupied)MO to B-th (virtual)MO |
2294 | 2296 | int moJ = this->GetActiveOccIndex(*this->molecule, l); |
2295 | 2297 | int moB = this->GetActiveVirIndex(*this->molecule, l); |
@@ -2321,16 +2323,38 @@ void ZindoS::CalcCISMatrix(double** matrixCIS) const{ | ||
2321 | 2323 | matrixCIS[k][l] = value; |
2322 | 2324 | // End of the slow algorith. */ |
2323 | 2325 | } |
2324 | - } | |
2325 | - catch(MolDSException ex){ | |
2326 | + catch(MolDSException ex){ | |
2326 | 2327 | #pragma omp critical |
2327 | - ompErrors << ex.what() << endl ; | |
2328 | + ompErrors << ex.what() << endl ; | |
2329 | + } | |
2330 | + } // end of l-loop | |
2331 | + // Exception throwing for omp-region | |
2332 | + if(!ompErrors.str().empty()){ | |
2333 | + throw MolDSException(ompErrors.str()); | |
2328 | 2334 | } |
2329 | 2335 | } // end of k-loop |
2330 | - // Exception throwing for omp-region | |
2331 | - if(!ompErrors.str().empty()){ | |
2332 | - throw MolDSException(ompErrors.str()); | |
2336 | + | |
2337 | + | |
2338 | + // communication to collect all matrix data on rank 0 | |
2339 | + if(world->rank() == 0){ | |
2340 | + // receive the matrix data from other ranks | |
2341 | + for(int k=0; k<this->matrixCISdimension; k++){ | |
2342 | + if(k%world->size() == 0){continue;} | |
2343 | + int source = k%world->size(); | |
2344 | + int tag = k; | |
2345 | + world->recv(source, tag, matrixCIS[k], this->matrixCISdimension); | |
2346 | + } | |
2347 | + } | |
2348 | + else{ | |
2349 | + // send the matrix data to rank-0 | |
2350 | + for(int k=0; k<this->matrixCISdimension; k++){ | |
2351 | + if(k%world->size() != world->rank()){continue;} | |
2352 | + int dest = 0; | |
2353 | + int tag = k; | |
2354 | + world->send(dest, tag, matrixCIS[k], this->matrixCISdimension); | |
2355 | + } | |
2333 | 2356 | } |
2357 | + | |
2334 | 2358 | double ompEndTime = omp_get_wtime(); |
2335 | 2359 | this->OutputLog(boost::format("%s%lf%s\n%s") % this->messageOmpElapsedTimeCalcCISMarix.c_str() |
2336 | 2360 | % (ompEndTime - ompStartTime) |