From 070ff0b714f5ff1fb9ffd6588ea2857730ab040f Mon Sep 17 00:00:00 2001
From: Cristian C Lalescu <Cristian.Lalescu@ds.mpg.de>
Date: Fri, 10 Jul 2015 14:22:37 +0200
Subject: [PATCH] add function to synch just one particle

not sure we'll ever use it, but you never know.
---
 src/base.hpp                 |  3 ++-
 src/slab_field_particles.cpp | 34 +++++++++++++++++++++++++++++++---
 src/slab_field_particles.hpp |  4 ++++
 3 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/src/base.hpp b/src/base.hpp
index 281bd9bc..a2963509 100644
--- a/src/base.hpp
+++ b/src/base.hpp
@@ -28,7 +28,6 @@
 #define BASE
 
 static const int message_buffer_length = 1024;
-static char debug_message_buffer[message_buffer_length];
 extern int myrank, nprocs;
 
 inline int MOD(int a, int n)
@@ -38,6 +37,8 @@ inline int MOD(int a, int n)
 
 #ifndef NDEBUG
 
+static char debug_message_buffer[message_buffer_length];
+
 inline void DEBUG_MSG(const char * format, ...)
 {
     va_list argptr;
diff --git a/src/slab_field_particles.cpp b/src/slab_field_particles.cpp
index 2b7aa23c..e21d8fb6 100644
--- a/src/slab_field_particles.cpp
+++ b/src/slab_field_particles.cpp
@@ -129,6 +129,34 @@ int slab_field_particles<rnumber>::get_rank(double z)
     return tmp;
 }
 
+template <class rnumber>
+void slab_field_particles<rnumber>::synchronize_single_particle(int p)
+{
+    MPI_Status *s = new MPI_Status;
+    if (this->watching[p]) for (int r=0; r<this->fs->rd->nprocs; r++)
+        if (r != this->computing[p])
+        {
+            if (this->fs->rd->myrank == this->computing[p])
+                MPI_Send(
+                        this->state + p*this->ncomponents,
+                        this->ncomponents,
+                        MPI_REAL8,
+                        r,
+                        p*this->computing[p],
+                        this->fs->rd->comm);
+            if (this->fs->rd->myrank == r)
+                MPI_Recv(
+                        this->state + p*this->ncomponents,
+                        this->ncomponents,
+                        MPI_REAL8,
+                        this->computing[p],
+                        p*this->computing[p],
+                        this->fs->rd->comm,
+                        s);
+        }
+    delete s;
+}
+
 template <class rnumber>
 void slab_field_particles<rnumber>::synchronize()
 {
@@ -226,9 +254,9 @@ void slab_field_particles<rnumber>::get_grid_coordinates(double *x, int *xg, dou
 template <class rnumber>
 void slab_field_particles<rnumber>::linear_interpolation(float *field, int *xg, double *xx, double *dest)
 {
-    ptrdiff_t tindex, tmp;
-    tindex = ((ptrdiff_t(xg[2]  )*this->fs->rd->subsizes[1]+xg[1]  )*this->fs->rd->subsizes[2]+xg[0]  )*3;
-    tmp = ptrdiff_t(xg[2]);
+    //ptrdiff_t tindex, tmp;
+    //tindex = ((ptrdiff_t(xg[2]  )*this->fs->rd->subsizes[1]+xg[1]  )*this->fs->rd->subsizes[2]+xg[0]  )*3;
+    //tmp = ptrdiff_t(xg[2]);
     //DEBUG_MSG(
     //        "linear interpolation xx is %lg %lg %lg xg is %d %d %d,"
     //        " corner index is ((%ld*%d+%d)*%d+%d)*3 = %ld\n",
diff --git a/src/slab_field_particles.hpp b/src/slab_field_particles.hpp
index 4f8c094b..e7abde5b 100644
--- a/src/slab_field_particles.hpp
+++ b/src/slab_field_particles.hpp
@@ -42,6 +42,9 @@ class slab_field_particles
         /* watching is an array of shape [nparticles], with
          * watching[p] being true if particle p is in the domain of myrank
          * or in the buffer regions.
+         * watching is not really being used right now, since I don't do partial
+         * synchronizations of particles.
+         * we may do this at some point in the future, if it seems needed...
          * */
         bool *watching;
         /* computing is an array of shape [nparticles], with
@@ -97,6 +100,7 @@ class slab_field_particles
         /* generic methods, should work for all children of this class */
         int get_rank(double z); // get rank for given value of z
         void synchronize();
+        void synchronize_single_particle(int p);
         void get_grid_coordinates(double *x, int *xg, double *xx);
         void linear_interpolation(float *field, int *xg, double *xx, double *dest);
         void rFFTW_to_buffered(rnumber *src, rnumber *dst);
-- 
GitLab