program ghost_cells use mpi implicit none integer, parameter :: N=20 integer :: my_id, num_procs, ierr integer :: i,j integer :: rem, num_local_col integer :: proc_right, proc_left integer, allocatable :: matrix(:,:) integer status1(MPI_Status_size), status2(MPI_Status_size) call mpi_init(ierr) call mpi_comm_rank(MPI_COMM_WORLD,my_id,ierr) call mpi_comm_size(MPI_COMM_WORLD,num_procs,ierr) ! number of columns for each mpi task rem= mod(N,num_procs) num_local_col = (N - rem)/num_procs if ( my_id < rem ) num_local_col = num_local_col+1 allocate(matrix(N,num_local_col+2)) ! inizialization of the local matrix do j=1,num_local_col+2 do i=1,N matrix(i,j) = my_id enddo enddo !! Compute proc_right, proc_left ... ! send receive of the ghost regions !! Use MPI_Sendrecv for communications ... ! check printings write(*,*) "my_id ", my_id, " colonna arrivata da sinistra: ", matrix(:,1) write(*,*) "my_id ", my_id, " colonna arrivata da destra: ", & matrix(:,num_local_col+2) deallocate(matrix) !! Finalize ... end program