Loading...
Searching...
No Matches
MPIPot.cpp
Go to the documentation of this file.
1/*
2** This file is part of eOn.
3**
4** SPDX-License-Identifier: BSD-3-Clause
5**
6** Copyright (c) 2010--present, eOn Development Team
7** All rights reserved.
8**
9** Repo:
10** https://github.com/TheochemUI/eOn
11*/
12
14#include <mpi.h>
15#include <stdio.h>
16#include <time.h>
17#ifndef _WIN32
18#include <unistd.h>
19#endif
20
27
28void MPIPot::cleanMemory(void) { return; }
29
31
32void MPIPot::force(long N, const double *R, const int *atomicNrs, double *F,
33 double *U, double *variance, const double *box) {
34 variance = nullptr;
35 // Send data to potential
36 int pbc = 1;
37 int failed;
38 char cwd[1024];
39 long icwd[1024];
40 getcwd(cwd, 1024);
41 for (int i = 0; i < 1024; i++) {
42 icwd[i] = static_cast<long>(cwd[i]);
43 }
44 int intn = static_cast<int>(N);
45 MPI_Send(&intn, 1, MPI_INT, potentialRank, 0, MPI_COMM_WORLD);
46 MPI_Send(atomicNrs, N, MPI_INT, potentialRank, 0, MPI_COMM_WORLD);
47 MPI_Send(R, 3 * N, MPI_DOUBLE, potentialRank, 0, MPI_COMM_WORLD);
48 MPI_Send(box, 9, MPI_DOUBLE, potentialRank, 0, MPI_COMM_WORLD);
49 MPI_Send(&pbc, 1, MPI_INT, potentialRank, 0, MPI_COMM_WORLD);
50 MPI_Send(&icwd[0], 1024, MPI_INT, potentialRank, 0, MPI_COMM_WORLD);
51
52 if (poll_period > 0.0) {
53 int eon_flag = 0;
54 MPI_Iprobe(potentialRank, 0, MPI_COMM_WORLD, &eon_flag, MPI_STATUS_IGNORE);
55 while (!eon_flag) {
56 usleep(static_cast<useconds_t>(poll_period / 1000000.0));
57 MPI_Iprobe(potentialRank, 0, MPI_COMM_WORLD, &eon_flag,
58 MPI_STATUS_IGNORE);
59 }
60 }
61
62 // Recv data from potential
63 MPI_Recv(&failed, 1, MPI_INT, potentialRank, 0, MPI_COMM_WORLD,
64 MPI_STATUS_IGNORE);
65 if (failed == 1) {
66 throw 100;
67 }
68
69 MPI_Recv(U, 1, MPI_DOUBLE, potentialRank, 0, MPI_COMM_WORLD,
70 MPI_STATUS_IGNORE);
71 MPI_Recv(F, 3 * N, MPI_DOUBLE, potentialRank, 0, MPI_COMM_WORLD,
72 MPI_STATUS_IGNORE);
73 // printf("energy: %12.4e\n", *U);
74 // printf("forces:\n");
75 // for (int i=0;i<N;i++) printf("%12.4e %12.4e %12.4e\n", F[3*i], F[3*i+1],
76 // F[3*i+2]);
77}
void cleanMemory(void)
Definition MPIPot.cpp:28
void force(long N, const double *R, const int *atomicNrs, double *F, double *U, double *variance, const double *box)
Definition MPIPot.cpp:32
double poll_period
Definition MPIPot.h:29
int potentialRank
Definition MPIPot.h:28
~MPIPot()
Definition MPIPot.cpp:30
MPIPot(const Parameters &p)
Definition MPIPot.cpp:21
struct eonc::Parameters::potential_options_t potential_options
Potential(PotType a_ptype)
Definition Potential.h:35