| 363 | |
| 364 | |
| 365 | void Foam::UPstream::allocatePstreamCommunicator |
| 366 | ( |
| 367 | const label parentIndex, |
| 368 | const label index |
| 369 | ) |
| 370 | { |
| 371 | if (index == PstreamGlobals::MPIGroups_.size()) |
| 372 | { |
| 373 | // Extend storage with dummy values |
| 374 | MPI_Group newGroup = MPI_GROUP_NULL; |
| 375 | PstreamGlobals::MPIGroups_.append(newGroup); |
| 376 | MPI_Comm newComm = MPI_COMM_NULL; |
| 377 | PstreamGlobals::MPICommunicators_.append(newComm); |
| 378 | } |
| 379 | else if (index > PstreamGlobals::MPIGroups_.size()) |
| 380 | { |
| 381 | FatalErrorInFunction |
| 382 | << "PstreamGlobals out of sync with UPstream data. Problem." |
| 383 | << Foam::exit(FatalError); |
| 384 | } |
| 385 | |
| 386 | |
| 387 | if (parentIndex == -1) |
| 388 | { |
| 389 | // Allocate world communicator |
| 390 | |
| 391 | if (index != UPstream::worldComm) |
| 392 | { |
| 393 | FatalErrorInFunction |
| 394 | << "world communicator should always be index " |
| 395 | << UPstream::worldComm << Foam::exit(FatalError); |
| 396 | } |
| 397 | |
| 398 | PstreamGlobals::MPICommunicators_[index] = MPI_COMM_WORLD; |
| 399 | MPI_Comm_group(MPI_COMM_WORLD, &PstreamGlobals::MPIGroups_[index]); |
| 400 | MPI_Comm_rank |
| 401 | ( |
| 402 | PstreamGlobals::MPICommunicators_[index], |
| 403 | &myProcNo_[index] |
| 404 | ); |
| 405 | |
| 406 | // Set the number of processes to the actual number |
| 407 | int numProcs; |
| 408 | MPI_Comm_size(PstreamGlobals::MPICommunicators_[index], &numProcs); |
| 409 | |
| 410 | //procIDs_[index] = identity(numProcs); |
| 411 | procIDs_[index].setSize(numProcs); |
| 412 | forAll(procIDs_[index], i) |
| 413 | { |
| 414 | procIDs_[index][i] = i; |
| 415 | } |
| 416 | } |
| 417 | else |
| 418 | { |
| 419 | // Create new group |
| 420 | MPI_Group_incl |
| 421 | ( |
| 422 | PstreamGlobals::MPIGroups_[parentIndex], |