Even after fixing the code and checking that Valgrind is not complaining of any leaks on my laptop, I am still not able to run it using the OpenCoarrays+MVAPICH2 configuration on the cluster (commenting out the communication part throws the same error). One small correction, I use GCC 6.3 on my laptop (not 6.1), whereas on Blues I use GCC 6.1. I have attached the code here.
[sghosh@blogin3 put-get]$ mpif90 -fcoarray=lib -I/home/sghosh/builds/opencaf/include -Wall -o get_bw get_bw.f90 -L/home/sghosh/builds/opencaf/lib64 -lcaf_mpi -L/home/sghosh/builds/mvapich222-gnu-psm/lib -lmpi -lmpifort -lmpich
[sghosh@blogin3 put-get]$ cafrun -n 2 ./get_bw
get_bw:89652 terminated with signal 11 at PC=2b852443d601 SP=7ffc600491b0. Backtrace:
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPID_Isend+0x131)[0x2b852443d601]
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPIC_Sendrecv+0x119)[0x2b85243d5b99]
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPIR_Allreduce_pt2pt_rd_MV2+0x39b)[0x2b85242d34ab]
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPIR_Allreduce_index_tuned_intra_MV2+0x50e)[0x2b85242d82de]
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPIR_Allreduce_impl+0x26)[0x2b852427aa56]
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPIR_Get_contextid_sparse_group+0x3b6)[0x2b85243f91a6]
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPIR_Get_contextid+0x10)[0x2b85243f9630]
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPIR_Comm_copy+0x32)[0x2b85243fa592]
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPIR_Comm_dup_impl+0x44)[0x2b8524370ff4]
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPI_Comm_dup+0x158)[0x2b85243711c8]
/home/sghosh/builds/opencaf/lib64/libcaf_mpi.so.1(_gfortran_caf_init+0x94)[0x2b8524011a04]
./get_bw[0x40195c]
/lib64/libc.so.6(__libc_start_main+0xfd)[0x2b8525438d1d]
./get_bw[0x4010a9]
get_bw:89653 terminated with signal 11 at PC=2b30ff2e2601 SP=7fff6c1bc7c0. Backtrace:
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPID_Isend+0x131)[0x2b30ff2e2601]
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPIC_Sendrecv+0x119)[0x2b30ff27ab99]
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPIR_Allreduce_pt2pt_rd_MV2+0x39b)[0x2b30ff1784ab]
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPIR_Allreduce_index_tuned_intra_MV2+0x50e)[0x2b30ff17d2de]
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPIR_Allreduce_impl+0x26)[0x2b30ff11fa56]
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPIR_Get_contextid_sparse_group+0x3b6)[0x2b30ff29e1a6]
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPIR_Get_contextid+0x10)[0x2b30ff29e630]
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPIR_Comm_copy+0x32)[0x2b30ff29f592]
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPIR_Comm_dup_impl+0x44)[0x2b30ff215ff4]
/home/sghosh/builds/mvapich222-gnu-psm/lib/libmpi.so.12(MPI_Comm_dup+0x158)[0x2b30ff2161c8]
/home/sghosh/builds/opencaf/lib64/libcaf_mpi.so.1(_gfortran_caf_init+0x94)[0x2b30feeb6a04]
./get_bw[0x40195c]
/lib64/libc.so.6(__libc_start_main+0xfd)[0x2b31002ddd1d]
./get_bw[0x4010a9]