I have a main program that has subroutine written using coarrays. The problem is that while running the code it treats the entire code (main + subroutine) as parallel code and runs it on all specified processors. For eg., the Below program prints "Hello from main" four times when running using 4 CPUs. I want that the main program runs on one CPU while when it encounters a subroutine that uses coarrays it runs on all specified CPUs.
Main program that call subroutine coarray_test
program main
implicit none
write (*,*) "Hello from main "
call coarray_test
end program
Subroutine coarray_test
subroutine coarray_test
implicit none
write (*,*) "Hello from Subroutine coarray_test "
return
end subroutine coarray_test
Command used for compile and execution
export FOR_COARRAY_NUM_IMAGES=4
ifort -g -coarray -o test.out main.f90 coarray_test.f90
./test.out
Output
Hello from main
Hello from Subroutine coarray_test
Hello from main
Hello from Subroutine coarray_test
Hello from main
Hello from Subroutine coarray_test
Hello from main
Hello from Subroutine coarray_test
Expected Output
Hello from main
Hello from Subroutine coarray_test
Hello from Subroutine coarray_test
Hello from Subroutine coarray_test
Hello from Subroutine coarray_test