Skip to content

Commit e511d1b

Browse files
committed
bugfixed that allocation issue -- I had a typo in the first mpi_comm_size line. it all works now!
1 parent a2dde5d commit e511d1b

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

testmpi.f90

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ program rmc
1818
integer :: world_rank, rank
1919
integer :: world_nprocs, nprocs
2020
integer :: root
21-
integer, dimension(:), allocatable :: world_ranks, ranks, world_colors, colors
21+
integer, dimension(:), allocatable :: world_ranks, ranks, world_colors, colors, temp
2222
integer :: to_send
2323

2424

@@ -33,7 +33,7 @@ program rmc
3333
! Initialize MPI
3434
call mpi_init_thread(MPI_THREAD_MULTIPLE, ipvd, mpierr)
3535
call mpi_comm_rank(mpi_comm_world, world_rank, mpierr)
36-
call mpi_comm_size(colored_comm, world_nprocs, mpierr)
36+
call mpi_comm_size(mpi_comm_world, world_nprocs, mpierr)
3737
write(*,*) "Core", world_rank, "has color", color
3838

3939
! Split the world communicator into separate pieces for each mpiexec subprogram
@@ -48,19 +48,18 @@ program rmc
4848
root = 0
4949

5050
call mpi_barrier(colored_comm, mpierr)
51-
write(*,'(A10, I2, A4, I2, A11, I2, A6, I2, A18, I2)') "I am core ", rank, " of ", nprocs, " with color", color, ", root", root, ", and colored_comm", colored_comm
51+
write(*,'(A10, I2, A4, I2, A11, I2, A6, I2, A18, I2)') "I am core ", rank, " of ", nprocs, " with color", color, ", root", root, ", and communicator", colored_comm
5252

5353
! Allocate space for a few variables that are going to be used for gathering and printing
5454
allocate(world_ranks(nprocs), stat=stat)
5555
world_ranks = -1
5656

5757
! Gather each 'rank' into 'world_ranks' on processor 'root' through each 'colored_comm'
5858
call mpi_gather(world_rank, 1, MPI_INT, world_ranks, 1, MPI_INT, root, colored_comm, mpierr)
59-
allocate(ranks(nprocs), stat=stat) ! There is some really weird bug going on here. The entire program fails if I don't do this allocation. I need to experiment more.
6059

6160
call mpi_barrier(colored_comm, mpierr)
6261
if(rank .eq. root) then
63-
write(*,*) "world", color, "got the following ranks from the whole world:", world_ranks
62+
write(*,*) "World", color, "got the following ranks from the whole world:", world_ranks
6463
endif
6564

6665
! Now try a bcast
@@ -69,7 +68,7 @@ program rmc
6968
endif
7069
call mpi_barrier(colored_comm, mpierr)
7170
call mpi_bcast(to_send, 1, MPI_INT, root, colored_comm, mpierr)
72-
write(*,'(A10, I2, A11, I2, A32)') "I am core ", rank, " and I got ", to_send, " broadcasted to me from my root."
71+
write(*,'(A10, I2, A10, I2, A32)') "I am core ", rank, " and I got", to_send, " broadcasted to me from my root."
7372

7473
! Free the sub-communicators and finalize
7574
call mpi_comm_free(colored_comm, mpierr)

0 commit comments

Comments
 (0)