Index: palm/trunk/SOURCE/lpm_exchange_horiz.f90
===================================================================
--- palm/trunk/SOURCE/lpm_exchange_horiz.f90	(revision 2245)
+++ palm/trunk/SOURCE/lpm_exchange_horiz.f90	(revision 2305)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Improved calculation of particle IDs.
+! 
+! 2245 2017-06-02 14:37:10Z schwenkel
 ! Bugfix in Add_particles_to_gridcell:
 ! Apply boundary conditions also in y-direction
@@ -106,4 +109,5 @@
  MODULE lpm_exchange_horiz_mod
  
+    USE, INTRINSIC ::  ISO_C_BINDING
 
     USE control_parameters,                                                    &
@@ -130,5 +134,5 @@
         ONLY:  alloc_factor, deleted_particles, grid_particles,                &
                ibc_par_lr, ibc_par_ns, min_nr_particle,                        &
-               mpi_particle_type, number_of_particles,                         &
+               number_of_particles,                                            &
                offset_ocean_nzt, offset_ocean_nzt_m1, particles,               &
                particle_type, prt_count, trlp_count_sum,                       &
@@ -195,4 +199,5 @@
     INTEGER(iwp) ::  kp                !< index variable along z
     INTEGER(iwp) ::  n                 !< particle index variable 
+    INTEGER(iwp) ::  par_size          !< Particle size in bytes
     INTEGER(iwp) ::  trlp_count        !< number of particles send to left PE
     INTEGER(iwp) ::  trlp_count_recv   !< number of particles receive from right PE
@@ -419,8 +424,11 @@
 
        ALLOCATE(rvrp(MAX(1,trrp_count_recv)))
-
-       CALL MPI_SENDRECV( trlp(1)%radius, max(1,trlp_count), mpi_particle_type,&
-                          pleft, 1, rvrp(1)%radius,                            &
-                          max(1,trrp_count_recv), mpi_particle_type, pright, 1,&
+!      
+!--    This MPI_SENDRECV should work even with odd mixture on 32 and 64 Bit 
+!--    variables in structure particle_type (due to the calculation of par_size)
+       par_size = c_sizeof(trlp(1))
+       CALL MPI_SENDRECV( trlp, max(1,trlp_count)*par_size, MPI_BYTE,&
+                          pleft, 1, rvrp,                            &
+                          max(1,trrp_count_recv)*par_size, MPI_BYTE, pright, 1,&
                           comm2d, status, ierr )
 
@@ -436,8 +444,11 @@
 
        ALLOCATE(rvlp(MAX(1,trlp_count_recv)))
-
-       CALL MPI_SENDRECV( trrp(1)%radius, max(1,trrp_count), mpi_particle_type,&
-                          pright, 1, rvlp(1)%radius,                           &
-                          max(1,trlp_count_recv), mpi_particle_type, pleft, 1, &
+!      
+!--    This MPI_SENDRECV should work even with odd mixture on 32 and 64 Bit 
+!--    variables in structure particle_type (due to the calculation of par_size)
+       par_size = c_sizeof(trrp(1))
+       CALL MPI_SENDRECV( trrp, max(1,trrp_count)*par_size, MPI_BYTE,&
+                          pright, 1, rvlp,                           &
+                          max(1,trlp_count_recv)*par_size, MPI_BYTE, pleft, 1, &
                           comm2d, status, ierr )
 
@@ -641,8 +652,11 @@
 
        ALLOCATE(rvnp(MAX(1,trnp_count_recv)))
- 
-       CALL MPI_SENDRECV( trsp(1)%radius, trsp_count, mpi_particle_type,      &
-                          psouth, 1, rvnp(1)%radius,                             &
-                          trnp_count_recv, mpi_particle_type, pnorth, 1,   &
+!      
+!--    This MPI_SENDRECV should work even with odd mixture on 32 and 64 Bit 
+!--    variables in structure particle_type (due to the calculation of par_size)
+       par_size = c_sizeof(trsp(1))
+       CALL MPI_SENDRECV( trsp, trsp_count*par_size, MPI_BYTE,      &
+                          psouth, 1, rvnp,                             &
+                          trnp_count_recv*par_size, MPI_BYTE, pnorth, 1,   &
                           comm2d, status, ierr )
 
@@ -658,8 +672,11 @@
 
        ALLOCATE(rvsp(MAX(1,trsp_count_recv)))
-
-       CALL MPI_SENDRECV( trnp(1)%radius, trnp_count, mpi_particle_type,      &
-                          pnorth, 1, rvsp(1)%radius,                          &
-                          trsp_count_recv, mpi_particle_type, psouth, 1,   &
+!      
+!--    This MPI_SENDRECV should work even with odd mixture on 32 and 64 Bit 
+!--    variables in structure particle_type (due to the calculation of par_size)
+       par_size = c_sizeof(trnp(1))
+       CALL MPI_SENDRECV( trnp, trnp_count*par_size, MPI_BYTE,      &
+                          pnorth, 1, rvsp,                          &
+                          trsp_count_recv*par_size, MPI_BYTE, psouth, 1,   &
                           comm2d, status, ierr )
 
