I posted this to the FORTRAN Mac/linux forum (http://software.intel.com/en-us/forums/showthread.php?t=69829), but didn't get a response, and I thought it was appropriate to cross-post here anyway:
I am using PXFFORK to fork my simulation for doing post-processing and whatnot. I can achieve some speedup by doing this in an independent thread, like so:
! Mac desktop, 2.93GHz Quad-Core Intel Xeon, 16GB RAM
! Mac OSX v 10.5.8
! ifort v 11.1
integer pid, ierror
if(pid>0) return ! We are the parent. Go back to computing.
if(pid==0) then ! We are the child. Postprocess.
stop !!!!!!!!!!!!! STOP !!!!!!
if(pid<0) then ! System error. No child created.
write(*,*) "FORK ERROR: ", pid
end subroutine postprocess_wrapper
These forked processes do not completely exit when they reach the STOP command:
localhost:~> ps -u nooj
502 83350 ?? 0:00.00 (MyForkProgram)
502 83366 ?? 0:00.00 (MyForkProgram)
502 83367 ?? 0:00.00 (MyForkProgram)
502 83368 ?? 0:00.00 (MyForkProgram)
502 83369 ?? 0:00.00 (MyForkProgram)
502 83370 ?? 0:00.00 (MyForkProgram)
502 83375 ?? 0:00.00 (MyForkProgram)
On mac, there is a maximum number of processes per shell, default of 100. (Google for "fork: Resource temporarily unavailable".) There are ways to increase this number, of course, but that's not the problem. The problem is that my code is done, and the process should exit completely (successfully). All the processes immediately exit completely when the last thread finishes.
Ideas? I think this should be solvable by replacing my code as I have given it with something better.