I want to use in the same code PETSC and, in other regions, OpenMP and I have found a problem that I think it's not because of PETSC.
You have a WRITE in a parallel region, which means that it can be entered in more than one thread at a time. Fortran does not allow what it calls "recursive I/O" (except for internal files) - once you start an I/O operation on a unit no other operation on that unit may begin.
Now, I do see that you are using a two-year-old version of Intel Fortran and I know that in the 2017 version a change was made so that the Fortran run-time library was always "reentrant". I am not sure if that would help you here, but it might.
Either remove the WRITE from the parallel region or protect it with a critical section.
Thanks, Steve, it's a great honor to be answered by you since your answers have been helping me a lot in the last years. It's true that with CRITICAL I didn't get the error anymore... but I got confused since I got that error when linking with PETSC and don't when I didn't link the program.
Thank you for your dedication!