update_ghost_boundaries_streamBC.F90 18.6 KB
Newer Older
Femi Kadri's avatar
Femi Kadri committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
SUBROUTINE update_ghost_boundaries_streamBC(local_x_min_ghost,local_x_max_ghost,local_y_min_ghost,local_y_max_ghost,&
& local_z_min_ghost,local_z_max_ghost,local_x_min_real,local_x_max_real,local_y_min_real,local_y_max_real,local_z_min_real,&
& local_z_max_real,My_MPI_Process_ID,IN,OUT,WEST,EAST,UP,DOWN,cartesian_communicator,local_x_nodes_ghost,&
& local_y_nodes_ghost,local_z_nodes_ghost,local_x_nodes_real,local_y_nodes_real,local_z_nodes_real,&
& divide_x,divide_y,divide_z,Q,f_temp,receive_buffer_from_west,receive_buffer_from_east,&
& send_buffer_to_east,send_buffer_to_west,receive_buffer_from_down,receive_buffer_from_up,&
& send_buffer_to_up,send_buffer_to_down,receive_buffer_from_in,receive_buffer_from_out,&
& send_buffer_to_out,send_buffer_to_in,my_mpi_real_data_type)


USE debug_module
!USE precision_detector

	IMPLICIT NONE

	INCLUDE "mpif.h"

	INTEGER,INTENT(IN) :: local_x_min_ghost,local_x_max_ghost,local_y_min_ghost,local_y_max_ghost
	INTEGER,INTENT(IN) :: local_z_min_ghost,local_z_max_ghost
	INTEGER,INTENT(IN) :: local_x_min_real,local_x_max_real,local_y_min_real,local_y_max_real
	INTEGER,INTENT(IN) :: local_z_min_real,local_z_max_real
	INTEGER,INTENT(IN) :: My_MPI_Process_ID,Q
	INTEGER,INTENT(IN) :: IN,OUT,WEST,EAST,UP,DOWN,cartesian_communicator


	INTEGER,INTENT(IN) :: local_x_nodes_ghost,local_y_nodes_ghost,local_z_nodes_ghost
	INTEGER,INTENT(IN) :: local_x_nodes_real,local_y_nodes_real,local_z_nodes_real
	
	LOGICAL*4,INTENT(IN) :: divide_x,divide_y,divide_z
	LOGICAL*4,PARAMETER :: debug = GLOBAL_DEBUG

	REAL,INTENT(INOUT) :: f_temp(0:Q,local_x_min_ghost:local_x_max_ghost,local_y_min_ghost:local_y_max_ghost,&
	& local_z_min_ghost:local_z_max_ghost)

	INTEGER STATUS(MPI_STATUS_SIZE)
	INTEGER :: mpi_error_code,i,j
	INTEGER :: in_out_receive_size, in_out_send_size,out_in_receive_size,out_in_send_size
	INTEGER :: west_east_receive_size, west_east_send_size,east_west_receive_size,east_west_send_size
	INTEGER :: down_up_receive_size, down_up_send_size,up_down_receive_size,up_down_send_size

	INTEGER,PARAMETER :: x_dir_number_nonblocking_comm = 4
	INTEGER :: x_dir_send_recv_request_array(x_dir_number_nonblocking_comm)
	INTEGER :: x_dir_send_recv_status_array(MPI_STATUS_SIZE,x_dir_number_nonblocking_comm)

	INTEGER :: isend_west_east_request
	INTEGER :: irecv_west_east_request
	INTEGER :: isend_east_west_request
	INTEGER :: irecv_east_west_request

	INTEGER isend_west_east_status(MPI_STATUS_SIZE)
	INTEGER irecv_west_east_status(MPI_STATUS_SIZE)
	INTEGER isend_east_west_status(MPI_STATUS_SIZE)
	INTEGER irecv_east_west_status(MPI_STATUS_SIZE)

	INTEGER,PARAMETER :: y_dir_number_nonblocking_comm = 4
	INTEGER :: y_dir_send_recv_request_array(y_dir_number_nonblocking_comm)
	INTEGER :: y_dir_send_recv_status_array(MPI_STATUS_SIZE,y_dir_number_nonblocking_comm)

	INTEGER :: isend_down_up_request
	INTEGER :: irecv_down_up_request
	INTEGER :: isend_up_down_request
	INTEGER :: irecv_up_down_request

	INTEGER :: isend_down_up_status(MPI_STATUS_SIZE)
	INTEGER :: irecv_down_up_status(MPI_STATUS_SIZE)
	INTEGER :: isend_up_down_status(MPI_STATUS_SIZE)
	INTEGER :: irecv_up_down_status(MPI_STATUS_SIZE)

	INTEGER,PARAMETER :: z_dir_number_nonblocking_comm = 4
	INTEGER :: z_dir_send_recv_request_array(z_dir_number_nonblocking_comm)
	INTEGER :: z_dir_send_recv_status_array(MPI_STATUS_SIZE,z_dir_number_nonblocking_comm)

	INTEGER :: isend_in_out_request
	INTEGER :: irecv_in_out_request
	INTEGER :: isend_out_in_request
	INTEGER :: irecv_out_in_request

	INTEGER :: isend_in_out_status(MPI_STATUS_SIZE)
	INTEGER :: irecv_in_out_status(MPI_STATUS_SIZE)
	INTEGER :: isend_out_in_status(MPI_STATUS_SIZE)
	INTEGER :: irecv_out_in_status(MPI_STATUS_SIZE)

	INTEGER,PARAMETER :: outward_mpi_sendrecv_tag = 44
	INTEGER,PARAMETER :: inward_mpi_sendrecv_tag = 45
	INTEGER,PARAMETER :: upward_mpi_sendrecv_tag = 46
	INTEGER,PARAMETER :: downward_mpi_sendrecv_tag = 47
	INTEGER,PARAMETER :: westward_mpi_sendrecv_tag = 48
	INTEGER,PARAMETER :: eastward_mpi_sendrecv_tag = 49
	INTEGER,INTENT(IN) :: my_mpi_real_data_type 

	REAL,INTENT(INOUT) :: receive_buffer_from_west(1:Q,local_y_min_real:local_y_max_real,&
	& local_z_min_real:local_z_max_real)
	REAL,INTENT(INOUT) :: receive_buffer_from_east(1:Q,local_y_min_real:local_y_max_real,&
	& local_z_min_real:local_z_max_real)
	REAL,INTENT(INOUT) :: send_buffer_to_east(1:Q,local_y_min_real:local_y_max_real,&
	& local_z_min_real:local_z_max_real)
	REAL,INTENT(INOUT) :: send_buffer_to_west(1:Q,local_y_min_real:local_y_max_real,&
	& local_z_min_real:local_z_max_real)

	REAL,INTENT(INOUT) :: receive_buffer_from_down(1:Q,local_x_min_ghost:local_x_max_ghost,&
	& local_z_min_real:local_z_max_real)
	REAL,INTENT(INOUT) :: receive_buffer_from_up(1:Q,local_x_min_ghost:local_x_max_ghost,&
	& local_z_min_real:local_z_max_real)
	REAL,INTENT(INOUT) :: send_buffer_to_up(1:Q,local_x_min_ghost:local_x_max_ghost,&
	& local_z_min_real:local_z_max_real)
	REAL,INTENT(INOUT) :: send_buffer_to_down(1:Q,local_x_min_ghost:local_x_max_ghost,&
	& local_z_min_real:local_z_max_real)

	REAL,INTENT(INOUT) :: receive_buffer_from_in(1:Q,local_x_min_ghost:local_x_max_ghost,&
	& local_y_min_ghost:local_y_max_ghost)
	REAL,INTENT(INOUT) :: receive_buffer_from_out(1:Q,local_x_min_ghost:local_x_max_ghost,&
	& local_y_min_ghost:local_y_max_ghost)
	REAL,INTENT(INOUT) :: send_buffer_to_out(1:Q,local_x_min_ghost:local_x_max_ghost,&
	& local_y_min_ghost:local_y_max_ghost)
	REAL,INTENT(INOUT) :: send_buffer_to_in(1:Q,local_x_min_ghost:local_x_max_ghost,&
	& local_y_min_ghost:local_y_max_ghost)
	
!	REAL,ALLOCATABLE :: receive_buffer_from_west(:,:,:),receive_buffer_from_east(:,:,:)
!	REAL,ALLOCATABLE :: send_buffer_to_east(:,:,:),send_buffer_to_west(:,:,:)

!	REAL,ALLOCATABLE :: receive_buffer_from_down(:,:,:),receive_buffer_from_up(:,:,:)
!	REAL,ALLOCATABLE :: send_buffer_to_up(:,:,:),send_buffer_to_down(:,:,:)

!	REAL,ALLOCATABLE :: receive_buffer_from_in(:,:,:),receive_buffer_from_out(:,:,:)
!	REAL,ALLOCATABLE :: send_buffer_to_out(:,:,:),send_buffer_to_in(:,:,:)

!my_mpi_real_data_type = get_my_mpi_real_data_type ()  !FUNNEL OUT THE RESULT OF PRECISION TESTING (this automatically sets the MPI REAL DATA PRECISION TYPE)

	IF(divide_x) THEN !IF THERE IS MPI SPLIT IN X DIRECTION

!		ALLOCATE ( receive_buffer_from_west(1:Q,local_y_min_real:local_y_max_real,local_z_min_real:local_z_max_real) )
!		ALLOCATE ( receive_buffer_from_east(1:Q,local_y_min_real:local_y_max_real,local_z_min_real:local_z_max_real) )
!		ALLOCATE ( send_buffer_to_east(1:Q,local_y_min_real:local_y_max_real,local_z_min_real:local_z_max_real) )
!		ALLOCATE ( send_buffer_to_west(1:Q,local_y_min_real:local_y_max_real,local_z_min_real:local_z_max_real) )


		!copy from f_temp array to send_buffer_to_east: (LOCAL_X_MAX_REAL) VALUES
		send_buffer_to_east(1:Q,local_y_min_real:local_y_max_real,local_z_min_real:local_z_max_real) = &
		& f_temp(1:Q,LOCAL_X_MAX_REAL,local_y_min_real:local_y_max_real,local_z_min_real:local_z_max_real)
		
		!copy from f_temp array to send_buffer_to_west: (LOCAL_X_MIN_INNER) VALUES
		send_buffer_to_west(1:Q,local_y_min_real:local_y_max_real,local_z_min_real:local_z_max_real) = &
		& f_temp(1:Q,LOCAL_X_MIN_REAL,local_y_min_real:local_y_max_real,local_z_min_real:local_z_max_real)


		west_east_send_size = Q * local_y_nodes_real * local_z_nodes_real
		west_east_receive_size = west_east_send_size

		east_west_receive_size = west_east_send_size
		east_west_send_size = west_east_send_size

		!MPI_SENDRECV WEST -> EAST: SEND (LOCAL_X_MAX_REAL) VALUES
!		call MPI_SENDRECV(send_buffer_to_east,west_east_send_size,my_mpi_real_data_type,EAST,eastward_mpi_sendrecv_tag, &
!		& receive_buffer_from_west,west_east_receive_size,my_mpi_real_data_type,WEST,eastward_mpi_sendrecv_tag,&
!		& cartesian_communicator,status,mpi_error_code)
		
		!MPI_Isend WEST -> EAST: SEND (LOCAL_X_MAX_REAL) VALUES  ...     NONBLOCKING COMMUNICATION!!
		call MPI_Isend(send_buffer_to_east,west_east_send_size,my_mpi_real_data_type,EAST,&
		&  eastward_mpi_sendrecv_tag,cartesian_communicator,isend_west_east_request,mpi_error_code)
		call MPI_Irecv(receive_buffer_from_west,west_east_receive_size,my_mpi_real_data_type,WEST,&
        & eastward_mpi_sendrecv_tag,cartesian_communicator,irecv_west_east_request,mpi_error_code)

		!MPI_SENDRECV EAST -> WEST: SEND (LOCAL_X_MIN_REAL) VALUES
!		call MPI_SENDRECV(send_buffer_to_west,east_west_send_size,my_mpi_real_data_type,WEST,westward_mpi_sendrecv_tag, &
!		& receive_buffer_from_east,east_west_receive_size,my_mpi_real_data_type,EAST,westward_mpi_sendrecv_tag,&
!		& cartesian_communicator,status,mpi_error_code)
		
		!MPI_SENDRECV EAST -> WEST: SEND (LOCAL_X_MIN_REAL) VALUES ...    NONBLOCKING COMMUNICATION!!
		call MPI_Isend(send_buffer_to_west,east_west_send_size,my_mpi_real_data_type,WEST,&
		&  westward_mpi_sendrecv_tag,cartesian_communicator,isend_east_west_request,mpi_error_code)
		call MPI_Irecv(receive_buffer_from_east,east_west_receive_size,my_mpi_real_data_type,EAST,&
        & westward_mpi_sendrecv_tag,cartesian_communicator,irecv_east_west_request,mpi_error_code)

		!END NONBLOCKING COMMUNICATION!!
		x_dir_send_recv_request_array = (/isend_west_east_request,irecv_west_east_request,&
		& isend_east_west_request,irecv_east_west_request/)

		call MPI_Waitall(x_dir_number_nonblocking_comm,x_dir_send_recv_request_array,&
		& x_dir_send_recv_status_array,mpi_error_code)
!		call MPI_Wait(isend_west_east_request,isend_west_east_status,mpi_error_code)
!		call MPI_Wait(irecv_west_east_request,irecv_west_east_status,mpi_error_code)
!		call MPI_Wait(isend_east_west_request,isend_east_west_status,mpi_error_code)
!		call MPI_Wait(irecv_east_west_request,irecv_east_west_status,mpi_error_code)


		!copy from receive_buffer_from_west to f_temp array: WEST (LOCAL_X_MAX_REAL) -> EAST (LOCAL_X_MIN_GHOST)
		f_temp(1:Q,LOCAL_X_MIN_GHOST,local_y_min_real:local_y_max_real,local_z_min_real:local_z_max_real) = &
		& receive_buffer_from_west(1:Q,local_y_min_real:local_y_max_real,local_z_min_real:local_z_max_real)

		
		!copy from receive_buffer_from_west to f_temp array: EAST(LOCAL_X_MIN_REAL) -> WEST(LOCAL_X_MAX_GHOST)
		f_temp(1:Q,LOCAL_X_MAX_GHOST,local_y_min_real:local_y_max_real,local_z_min_real:local_z_max_real) = &
		& receive_buffer_from_east(1:Q,local_y_min_real:local_y_max_real,local_z_min_real:local_z_max_real)

!		DEALLOCATE ( receive_buffer_from_west )
!		DEALLOCATE ( receive_buffer_from_east )
!		DEALLOCATE ( send_buffer_to_east )
!		DEALLOCATE ( send_buffer_to_west )

	ENDIF !!divide_x



	IF(divide_y) THEN !IF THERE IS MPI SPLIT IN Y DIRECTION

!		ALLOCATE ( receive_buffer_from_down(1:Q,local_x_min_ghost:local_x_max_ghost,local_z_min_real:local_z_max_real) )
!		ALLOCATE ( receive_buffer_from_up(1:Q,local_x_min_ghost:local_x_max_ghost,local_z_min_real:local_z_max_real) )
!		ALLOCATE ( send_buffer_to_up(1:Q,local_x_min_ghost:local_x_max_ghost,local_z_min_real:local_z_max_real) )
!		ALLOCATE ( send_buffer_to_down(1:Q,local_x_min_ghost:local_x_max_ghost,local_z_min_real:local_z_max_real) )

				
		!copy from f_temp array to send_buffer_to_up: (LOCAL_Y_MAX_INNER) VALUES 
		send_buffer_to_up(1:Q,local_x_min_ghost:local_x_max_ghost,local_z_min_real:local_z_max_real) = &
		& f_temp(1:Q,local_x_min_ghost:local_x_max_ghost,LOCAL_Y_MAX_REAL,local_z_min_real:local_z_max_real)
		
		!copy from f_temp array to send_buffer_to_down: (LOCAL_Y_MIN_REAL) VALUES
		send_buffer_to_down(1:Q,local_x_min_ghost:local_x_max_ghost,local_z_min_real:local_z_max_real) = &
		& f_temp(1:Q,local_x_min_ghost:local_x_max_ghost,LOCAL_Y_MIN_REAL,local_z_min_real:local_z_max_real)

		down_up_receive_size = Q * local_x_nodes_ghost * local_z_nodes_real
		down_up_send_size = down_up_receive_size
		up_down_receive_size = down_up_receive_size
		up_down_send_size = down_up_receive_size
		
	
		!MPI_SENDRECV DOWN -> UP: SEND (LOCAL_Y_MAX_REAL) VALUES
!		call MPI_SENDRECV(send_buffer_to_up,down_up_send_size,my_mpi_real_data_type,UP,upward_mpi_sendrecv_tag,&
!		& receive_buffer_from_down,down_up_receive_size,my_mpi_real_data_type,DOWN,upward_mpi_sendrecv_tag,&
!		& cartesian_communicator,status,mpi_error_code)
		
		!MPI_SENDRECV DOWN -> UP: SEND (LOCAL_Y_MAX_REAL) VALUES  ... NONBLOCKING!!!
		call MPI_Isend(send_buffer_to_up,down_up_send_size,my_mpi_real_data_type,UP,&
		&  upward_mpi_sendrecv_tag,cartesian_communicator,isend_down_up_request,mpi_error_code)
		call MPI_Irecv(receive_buffer_from_down,down_up_receive_size,my_mpi_real_data_type,DOWN,&
        & upward_mpi_sendrecv_tag,cartesian_communicator,irecv_down_up_request,mpi_error_code)

	
		!MPI_SENDRECV UP -> DOWN: SEND (LOCAL_Y_MIN_REAL:LOCAL_Y_MIN_INNER) VALUES
!		call MPI_SENDRECV(send_buffer_to_down,up_down_send_size,my_mpi_real_data_type,DOWN,downward_mpi_sendrecv_tag,&
!		& receive_buffer_from_up,up_down_receive_size,my_mpi_real_data_type,UP,downward_mpi_sendrecv_tag,&
!		& cartesian_communicator,status,mpi_error_code)
		
		!MPI_SENDRECV UP -> DOWN: SEND (LOCAL_Y_MIN_REAL:LOCAL_Y_MIN_INNER) VALUES  ... NONBLOCKING!!!
		call MPI_Isend(send_buffer_to_down,up_down_send_size,my_mpi_real_data_type,DOWN,&
		&  downward_mpi_sendrecv_tag,cartesian_communicator,isend_up_down_request,mpi_error_code)
		call MPI_Irecv(receive_buffer_from_up,up_down_receive_size,my_mpi_real_data_type,UP,&
        & downward_mpi_sendrecv_tag,cartesian_communicator,irecv_up_down_request,mpi_error_code)

		!END NONBLOCKING COMMUNICATION!!
		y_dir_send_recv_request_array = (/isend_down_up_request,irecv_down_up_request,&
		& isend_up_down_request,irecv_up_down_request/)

		call MPI_Waitall(y_dir_number_nonblocking_comm,y_dir_send_recv_request_array,&
		& y_dir_send_recv_status_array,mpi_error_code)
			

		!copy from receive_buffer_from_down to f_temp array: (LOCAL_Y_MAX_REAL) -> (LOCAL_Y_MIN_GHOST)  
		f_temp(1:Q,local_x_min_ghost:local_x_max_ghost,LOCAL_Y_MIN_GHOST,local_z_min_real:local_z_max_real) = &
		& receive_buffer_from_down(1:Q,local_x_min_ghost:local_x_max_ghost,local_z_min_real:local_z_max_real)

		
		!copy from receive_buffer_from_up to f_temp array: UP(LOCAL_Y_MIN_REAL) -> DOWN(LOCAL_Y_MAX_GHOST) 
		f_temp(1:Q,local_x_min_ghost:local_x_max_ghost,LOCAL_Y_MAX_GHOST,local_z_min_real:local_z_max_real) = &
		& receive_buffer_from_up(1:Q,local_x_min_ghost:local_x_max_ghost,local_z_min_real:local_z_max_real)
		

!		DEALLOCATE ( receive_buffer_from_down )
!		DEALLOCATE ( receive_buffer_from_up )
!		DEALLOCATE ( send_buffer_to_up )
!		DEALLOCATE ( send_buffer_to_down )

	ENDIF !!divide_y

	

	IF(divide_z) THEN !IF THERE IS MPI SPLIT IN Z DIRECTION

!		ALLOCATE ( receive_buffer_from_in(1:Q,local_x_min_ghost:local_x_max_ghost,local_y_min_ghost:local_y_max_ghost) )
!		ALLOCATE ( receive_buffer_from_out(1:Q,local_x_min_ghost:local_x_max_ghost,local_y_min_ghost:local_y_max_ghost) )
!		ALLOCATE ( send_buffer_to_out(1:Q,local_x_min_ghost:local_x_max_ghost,local_y_min_ghost:local_y_max_ghost) )
!		ALLOCATE ( send_buffer_to_in(1:Q,local_x_min_ghost:local_x_max_ghost,local_y_min_ghost:local_y_max_ghost) )


		!copy from f_temp array to send_buffer_to_out: (LOCAL_Z_MAX_INNER:LOCAL_Z_MAX_REAL) 
		send_buffer_to_out(1:Q,local_x_min_ghost:local_x_max_ghost,local_y_min_ghost:local_y_max_ghost) = &
		& f_temp(1:Q,local_x_min_ghost:local_x_max_ghost,local_y_min_ghost:local_y_max_ghost,LOCAL_Z_MAX_REAL)
	
		!copy from f_temp array to send_buffer_to_out: (LOCAL_Z_MIN_REAL:LOCAL_Z_MIN_INNER)
		send_buffer_to_in(1:Q,local_x_min_ghost:local_x_max_ghost,local_y_min_ghost:local_y_max_ghost) = &
		& f_temp(1:Q,local_x_min_ghost:local_x_max_ghost,local_y_min_ghost:local_y_max_ghost,LOCAL_Z_MIN_REAL)

!		WRITE(9,*) 'send_buffer_to_in'
!		DO J = local_y_min_ghost,local_y_max_ghost

!			DO I = local_x_min_ghost,local_x_max_ghost

!				WRITE(9,*) I,J,send_buffer_to_in(I,J)
	
!			END DO !I

!		END DO	!J

		in_out_receive_size = Q * local_x_nodes_ghost * local_y_nodes_ghost
		in_out_send_size = in_out_receive_size
		out_in_receive_size = in_out_receive_size
		out_in_send_size = in_out_receive_size

		

		!MPI_SENDRECV IN -> OUT: SEND (LOCAL_Z_MAX_INNER:LOCAL_Z_MAX_REAL) VALUES  
!		call MPI_SENDRECV(send_buffer_to_out,in_out_send_size,my_mpi_real_data_type,OUT,outward_mpi_sendrecv_tag,&
!		& receive_buffer_from_in,in_out_receive_size,my_mpi_real_data_type,IN,outward_mpi_sendrecv_tag,&
!		& cartesian_communicator,status,mpi_error_code)
		
		!MPI_SENDRECV IN -> OUT: SEND (LOCAL_Z_MAX_INNER:LOCAL_Z_MAX_REAL) VALUES  
		call MPI_Isend(send_buffer_to_out,in_out_send_size,my_mpi_real_data_type,OUT,&
		&  outward_mpi_sendrecv_tag,cartesian_communicator,isend_in_out_request,mpi_error_code)
		call MPI_Irecv(receive_buffer_from_in,in_out_receive_size,my_mpi_real_data_type,IN,&
        & outward_mpi_sendrecv_tag,cartesian_communicator,irecv_in_out_request,mpi_error_code)


		!write(0,*) My_MPI_Process_ID,'sent out'

		!MPI_SENDRECV IN -> OUT: SEND (LOCAL_Z_MIN_REAL:LOCAL_Z_MIN_INNER) VALUES  
!		call MPI_SENDRECV(send_buffer_to_in,out_in_send_size,my_mpi_real_data_type,IN,inward_mpi_sendrecv_tag,&
!		& receive_buffer_from_out,out_in_receive_size,my_mpi_real_data_type,OUT,inward_mpi_sendrecv_tag,&
!		& cartesian_communicator,status,mpi_error_code)

		!MPI_SENDRECV IN -> OUT: SEND (LOCAL_Z_MIN_REAL:LOCAL_Z_MIN_INNER) VALUES  
		call MPI_Isend(send_buffer_to_in,out_in_send_size,my_mpi_real_data_type,IN,&
		&  inward_mpi_sendrecv_tag,cartesian_communicator,isend_out_in_request,mpi_error_code)
		call MPI_Irecv(receive_buffer_from_out,out_in_receive_size,my_mpi_real_data_type,OUT,&
        & inward_mpi_sendrecv_tag,cartesian_communicator,irecv_out_in_request,mpi_error_code)


		!END NONBLOCKING COMMUNICATION!!
		z_dir_send_recv_request_array = (/isend_in_out_request,irecv_in_out_request,&
		& isend_out_in_request,irecv_out_in_request/)

		call MPI_Waitall(z_dir_number_nonblocking_comm,z_dir_send_recv_request_array,&
		& z_dir_send_recv_status_array,mpi_error_code)

		!write(0,*) My_MPI_Process_ID,'sent in'


!		WRITE(9,*) 'receive_buffer_from_out'

!		DO J = local_y_min_ghost,local_y_max_ghost

!			DO I = local_x_min_ghost,local_x_max_ghost

!				WRITE(9,*) I,J,receive_buffer_from_out(I,J)
	
!			END DO !I

!		END DO	!J


		!copy from receive_buffer_from_down to f_temp array: IN(LOCAL_Z_MAX_REAL) -> OUT(LOCAL_Z_MIN_GHOST)
		f_temp(1:Q,local_x_min_ghost:local_x_max_ghost,local_y_min_ghost:local_y_max_ghost,LOCAL_Z_MIN_GHOST) = &
		& receive_buffer_from_in(1:Q,local_x_min_ghost:local_x_max_ghost,local_y_min_ghost:local_y_max_ghost)

		
		!copy from receive_buffer_from_down to f_temp array: OUT(LOCAL_Z_MIN_REAL) -> IN(LOCAL_Z_MAX_GHOST) 
		f_temp(1:Q,local_x_min_ghost:local_x_max_ghost,local_y_min_ghost:local_y_max_ghost,LOCAL_Z_MAX_GHOST) = &
		& receive_buffer_from_out(1:Q,local_x_min_ghost:local_x_max_ghost,local_y_min_ghost:local_y_max_ghost)

!		DEALLOCATE ( receive_buffer_from_in )
!		DEALLOCATE ( receive_buffer_from_out )
!		DEALLOCATE ( send_buffer_to_out )
!		DEALLOCATE ( send_buffer_to_in )

	ENDIF !divide_z

RETURN 

END SUBROUTINE update_ghost_boundaries_streamBC