Cyclops Tensor Framework
parallel arithmetic on multidimensional arrays
particle_interaction.cxx
Go to the documentation of this file.
1 /*Copyright (c) 2011, Edgar Solomonik, all rights reserved.*/
2 
10 #include <ctf.hpp>
11 #include "moldynamics.h"
12 using namespace CTF;
14  World & dw){
15 
18 
19  Vector<particle> P(n, dw, sP);
20 
21  particle * loc_parts;
22  int64_t nloc;
23  int64_t * inds;
24  P.get_local_data(&nloc, &inds, &loc_parts);
25 
26  srand48(dw.rank);
27 
28  for (int64_t i=0; i<nloc; i++){
29  loc_parts[i].dx = drand48();
30  loc_parts[i].dy = drand48();
31  loc_parts[i].coeff = .001*drand48();
32  loc_parts[i].id = 777;
33  }
34  P.write(nloc, inds, loc_parts);
35  free(inds);
36  delete [] loc_parts;
37 
38  Vector<force> F(n, dw, gF);
39 
40 // CTF::Bivar_Function<particle, particle, force> fGF(&get_force);
42 
43  F["i"] += fGF(P["i"],P["j"]);
44 
45  Matrix<force> F_all(n, n, NS, dw, gF);
46 
47  F_all["ij"] = fGF(P["i"],P["j"]);
48 
49 
50  Vector<> f_mgn(n, dw);
51 
52  CTF::Function<force, double> get_mgn([](force f){ return f.fx+f.fy; } );
53 
54  f_mgn["i"] += get_mgn(F_all["ij"]);
55  -1.0*f_mgn["i"] += get_mgn(F["i"]);
56 
57  int pass = (f_mgn.norm2() < 1.E-6);
58  MPI_Allreduce(MPI_IN_PLACE, &pass, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
59 
60  if (dw.rank == 0){
61  if (pass){
62  printf("{ F[\"i\"] = get_force(P[\"i\"],P[\"j\"]) } passed\n");
63  } else {
64  printf("{ F[\"i\"] = get_force(P[\"i\"],P[\"j\"]) } failed\n");
65  }
66  }
67 
68  Transform<force,particle>([] (force f, particle & p){ p.dx += f.fx*p.coeff; p.dy += f.fy*p.coeff; })(F["i"], P["i"]);
69 
70  return pass;
71 }
72 
73 
74 #ifndef TEST_SUITE
75 
76 char* getCmdOption(char ** begin,
77  char ** end,
78  const std::string & option){
79  char ** itr = std::find(begin, end, option);
80  if (itr != end && ++itr != end){
81  return *itr;
82  }
83  return 0;
84 }
85 
86 
87 int main(int argc, char ** argv){
88  int rank, np, n;
89  int const in_num = argc;
90  char ** input_str = argv;
91 
92  MPI_Init(&argc, &argv);
93  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
94  MPI_Comm_size(MPI_COMM_WORLD, &np);
95 
96  if (getCmdOption(input_str, input_str+in_num, "-n")){
97  n = atoi(getCmdOption(input_str, input_str+in_num, "-n"));
98  if (n < 0) n = 5;
99  } else n = 5;
100 
101 
102  {
103  World dw(MPI_COMM_WORLD, argc, argv);
104 
105  if (rank == 0){
106  printf("Computing particle_interaction A_ijkl = f(B_ijkl, A_ijkl)\n");
107  }
108  particle_interaction(n, dw);
109  }
110 
111 
112  MPI_Finalize();
113  return 0;
114 }
115 
121 #endif
Set class defined by a datatype and a min/max function (if it is partially ordered i...
Definition: set.h:280
int main(int argc, char **argv)
Matrix class which encapsulates a 2D tensor.
Definition: matrix.h:18
def rank(self)
Definition: core.pyx:312
char * getCmdOption(char **begin, char **end, const std::string &option)
double dy
Definition: moldynamics.h:38
double fy
Definition: moldynamics.h:7
Vector class which encapsulates a 1D tensor.
Definition: vector.h:14
Definition: common.h:37
an instance of the CTF library (world) on a MPI communicator
Definition: world.h:19
string
Definition: core.pyx:456
int particle_interaction(int n, World &dw)
int rank
rank of local processor
Definition: world.h:24
double coeff
Definition: moldynamics.h:39
Group is a Monoid with operator &#39;-&#39; defined special case (parent) of a ring.
Definition: group.h:16
Definition: apsp.cxx:17
double dx
Definition: moldynamics.h:37
double fx
Definition: moldynamics.h:6
def np(self)
Definition: core.pyx:315