| 39 |
|
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
| 40 |
|
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
| 41 |
|
*/ |
| 42 |
+ |
|
| 43 |
+ |
#include "config.h" |
| 44 |
+ |
|
| 45 |
+ |
#ifdef IS_MPI |
| 46 |
+ |
#include <mpi.h> |
| 47 |
+ |
#endif |
| 48 |
|
|
| 49 |
|
#include "io/DumpWriter.hpp" |
| 50 |
|
#include "primitives/Molecule.hpp" |
| 58 |
|
#ifdef _MSC_VER |
| 59 |
|
#define isnan(x) _isnan((x)) |
| 60 |
|
#define isinf(x) (!_finite(x) && !_isnan(x)) |
| 55 |
– |
#endif |
| 56 |
– |
|
| 57 |
– |
#ifdef IS_MPI |
| 58 |
– |
#include <mpi.h> |
| 61 |
|
#endif |
| 62 |
|
|
| 63 |
|
using namespace std; |
| 304 |
|
void DumpWriter::writeFrame(std::ostream& os) { |
| 305 |
|
|
| 306 |
|
#ifdef IS_MPI |
| 307 |
< |
MPI::Status istatus; |
| 307 |
> |
MPI_Status istatus; |
| 308 |
|
#endif |
| 309 |
|
|
| 310 |
|
Molecule* mol; |
| 362 |
|
#else |
| 363 |
|
|
| 364 |
|
const int masterNode = 0; |
| 365 |
< |
int worldRank = MPI::COMM_WORLD.Get_rank(); |
| 366 |
< |
int nProc = MPI::COMM_WORLD.Get_size(); |
| 365 |
> |
int worldRank; |
| 366 |
> |
int nProc; |
| 367 |
|
|
| 368 |
+ |
MPI_Comm_size( MPI_COMM_WORLD, &nProc); |
| 369 |
+ |
MPI_Comm_rank( MPI_COMM_WORLD, &worldRank); |
| 370 |
+ |
|
| 371 |
+ |
|
| 372 |
|
if (worldRank == masterNode) { |
| 373 |
|
os << " <Snapshot>\n"; |
| 374 |
|
writeFrameProperties(os, |
| 391 |
|
|
| 392 |
|
for (int i = 1; i < nProc; ++i) { |
| 393 |
|
// tell processor i to start sending us data: |
| 394 |
< |
MPI::COMM_WORLD.Bcast(&i, 1, MPI::INT, masterNode); |
| 394 |
> |
MPI_Bcast(&i, 1, MPI_INT, masterNode, MPI_COMM_WORLD); |
| 395 |
|
|
| 396 |
|
// receive the length of the string buffer that was |
| 397 |
|
// prepared by processor i: |
| 398 |
|
int recvLength; |
| 399 |
< |
MPI::COMM_WORLD.Recv(&recvLength, 1, MPI::INT, i, MPI::ANY_TAG, |
| 400 |
< |
istatus); |
| 399 |
> |
MPI_Recv(&recvLength, 1, MPI_INT, i, MPI_ANY_TAG, MPI_COMM_WORLD, |
| 400 |
> |
&istatus); |
| 401 |
|
|
| 402 |
|
// create a buffer to receive the data |
| 403 |
|
char* recvBuffer = new char[recvLength]; |
| 404 |
|
if (recvBuffer == NULL) { |
| 405 |
|
} else { |
| 406 |
|
// receive the data: |
| 407 |
< |
MPI::COMM_WORLD.Recv(recvBuffer, recvLength, MPI::CHAR, i, |
| 408 |
< |
MPI::ANY_TAG, istatus); |
| 407 |
> |
MPI_Recv(recvBuffer, recvLength, MPI_CHAR, i, |
| 408 |
> |
MPI_ANY_TAG, MPI_COMM_WORLD, &istatus); |
| 409 |
|
// send it to the file: |
| 410 |
|
os << recvBuffer; |
| 411 |
|
// get rid of the receive buffer: |
| 417 |
|
int myturn = 0; |
| 418 |
|
for (int i = 1; i < nProc; ++i){ |
| 419 |
|
// wait for the master node to call our number: |
| 420 |
< |
MPI::COMM_WORLD.Bcast(&myturn, 1, MPI::INT, masterNode); |
| 420 |
> |
MPI_Bcast(&myturn, 1, MPI_INT, masterNode, MPI_COMM_WORLD); |
| 421 |
|
if (myturn == worldRank){ |
| 422 |
|
// send the length of our buffer: |
| 423 |
< |
MPI::COMM_WORLD.Send(&sendBufferLength, 1, MPI::INT, masterNode, 0); |
| 423 |
> |
MPI_Send(&sendBufferLength, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD); |
| 424 |
|
|
| 425 |
|
// send our buffer: |
| 426 |
< |
MPI::COMM_WORLD.Send((void *)buffer.c_str(), sendBufferLength, |
| 427 |
< |
MPI::CHAR, masterNode, 0); |
| 426 |
> |
MPI_Send((void *)buffer.c_str(), sendBufferLength, |
| 427 |
> |
MPI_CHAR, masterNode, 0, MPI_COMM_WORLD); |
| 428 |
|
|
| 429 |
|
} |
| 430 |
|
} |
| 468 |
|
for (int i = 1; i < nProc; ++i) { |
| 469 |
|
|
| 470 |
|
// tell processor i to start sending us data: |
| 471 |
< |
MPI::COMM_WORLD.Bcast(&i, 1, MPI::INT, masterNode); |
| 471 |
> |
MPI_Bcast(&i, 1, MPI_INT, masterNode, MPI_COMM_WORLD); |
| 472 |
|
|
| 473 |
|
// receive the length of the string buffer that was |
| 474 |
|
// prepared by processor i: |
| 475 |
|
int recvLength; |
| 476 |
< |
MPI::COMM_WORLD.Recv(&recvLength, 1, MPI::INT, i, MPI::ANY_TAG, |
| 477 |
< |
istatus); |
| 476 |
> |
MPI_Recv(&recvLength, 1, MPI_INT, i, MPI_ANY_TAG, MPI_COMM_WORLD, |
| 477 |
> |
&istatus); |
| 478 |
|
|
| 479 |
|
// create a buffer to receive the data |
| 480 |
|
char* recvBuffer = new char[recvLength]; |
| 481 |
|
if (recvBuffer == NULL) { |
| 482 |
|
} else { |
| 483 |
|
// receive the data: |
| 484 |
< |
MPI::COMM_WORLD.Recv(recvBuffer, recvLength, MPI::CHAR, i, |
| 485 |
< |
MPI::ANY_TAG, istatus); |
| 484 |
> |
MPI_Recv(recvBuffer, recvLength, MPI_CHAR, i, |
| 485 |
> |
MPI_ANY_TAG, MPI_COMM_WORLD, &istatus); |
| 486 |
|
// send it to the file: |
| 487 |
|
os << recvBuffer; |
| 488 |
|
// get rid of the receive buffer: |
| 494 |
|
int myturn = 0; |
| 495 |
|
for (int i = 1; i < nProc; ++i){ |
| 496 |
|
// wait for the master node to call our number: |
| 497 |
< |
MPI::COMM_WORLD.Bcast(&myturn, 1, MPI::INT, masterNode); |
| 497 |
> |
MPI_Bcast(&myturn, 1, MPI_INT, masterNode, MPI_COMM_WORLD); |
| 498 |
|
if (myturn == worldRank){ |
| 499 |
|
// send the length of our buffer: |
| 500 |
< |
MPI::COMM_WORLD.Send(&sendBufferLength, 1, MPI::INT, masterNode, 0); |
| 500 |
> |
MPI_Send(&sendBufferLength, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD); |
| 501 |
|
// send our buffer: |
| 502 |
< |
MPI::COMM_WORLD.Send((void *)buffer.c_str(), sendBufferLength, |
| 503 |
< |
MPI::CHAR, masterNode, 0); |
| 502 |
> |
MPI_Send((void *)buffer.c_str(), sendBufferLength, |
| 503 |
> |
MPI_CHAR, masterNode, 0, MPI_COMM_WORLD); |
| 504 |
|
} |
| 505 |
|
} |
| 506 |
|
} |
| 771 |
|
#ifdef IS_MPI |
| 772 |
|
if (worldRank == 0) { |
| 773 |
|
#endif // is_mpi |
| 768 |
– |
|
| 774 |
|
buffers.push_back(dumpFile_->rdbuf()); |
| 770 |
– |
|
| 775 |
|
eorStream = createOStream(eorFilename_); |
| 772 |
– |
|
| 776 |
|
buffers.push_back(eorStream->rdbuf()); |
| 774 |
– |
|
| 777 |
|
#ifdef IS_MPI |
| 778 |
|
} |
| 779 |
|
#endif // is_mpi |
| 780 |
|
|
| 781 |
|
TeeBuf tbuf(buffers.begin(), buffers.end()); |
| 782 |
|
std::ostream os(&tbuf); |
| 781 |
– |
|
| 783 |
|
writeFrame(os); |
| 784 |
|
|
| 785 |
|
#ifdef IS_MPI |
| 789 |
|
delete eorStream; |
| 790 |
|
#ifdef IS_MPI |
| 791 |
|
} |
| 792 |
< |
#endif // is_mpi |
| 792 |
< |
|
| 792 |
> |
#endif // is_mpi |
| 793 |
|
} |
| 794 |
|
|
| 795 |
|
std::ostream* DumpWriter::createOStream(const std::string& filename) { |