The easiest way to do that is that each processor writes in different files. So put a condition on the rank of the processor for the "open file part" of your code and for the written part. Then do a fuse of the files created.
Or
You can write a piece of code to initialise a table(size equal to the maximum of iel for your case) at 0.d0. Then each processor filling the table(iel) by the pressure then you can do a sum with PARRSM just before to open and write the result (where the table(...) /=0.d0) from the processor 0.
IF(IRANGP.GE.0) THEN
CALL PARRSM(nbrface,Psurf)
CALL PARRSM(nbrface,Xgrav)
CALL PARRSM(nbrface,Ygrav)
CALL PARRSM(nbrface,Zgrav)
ENDIF
if (irangp.le.0) then
OPEN(FILE='pressure_field.csv',UNIT=11,ACCESS='APPEND')
Do ii=1, NLELT
if (Xgrav(ii) /= 0.d0) then
WRITE(11,*) &
Xgrav(ii),';',Ygrav(ii),';',Zgrav(ii),';',Psurf(ii)
endif
Enddo
CLOSE(UNIT=11)
endif
I do not know how much sums with multiprocessor.
Thanks for any help
!if you use ILELT which go from 1 to NLELT when you will do the sum on all the processors you will have a huge pressure
!so if iel and IFAC are well inferior to nbrface do:
Xgrav(IFAC) = cdgfbo(1,IFAC)
Ygrav(IFAC) = cdgfbo(2,IFAC)
Zgrav(IFAC) = cdgfbo(3,IFAC)
Psurf(iel)=rtp(iel,ipr)
(with this, each processor will fill the arrays one times because iel and ifac are generic to the entire domain)
(I'm not sure if the numbering of iel of ifac start from 1 in code_satune, you need to check that)
ENDDO
!change that
IF(IRANGP.GE.0) THEN
CALL PARRSM(nbrface,Psurf)
CALL PARRSM(nbrface,Xgrav)
CALL PARRSM(nbrface,Ygrav)
CALL PARRSM(nbrface,Zgrav)
ENDIF
!by (for all processors)
CALL PARSOM(Psurf)
CALL PARSOM(Xgrav)
CALL PARSOM(Ygrav)
CALL PARSOM(Zgrav)
(all the tables Psurf,etc have the true values and 0.d0 on all the processors.
All the values will be exchanged between the processors by the sum.
For example if the processor 1 knows the pressure at iel = 10 and not iel =11 and the processor 2 knows the pressure at iel = 11 and not iel =10
you will have before the parsom!
on the proc1
Psurf(10)=1000Pa
Psurf(11)=0.d0
on the proc2
Psurf(10)=0.d0
Psurf(11)=999Pa
after the "call parsom" you will have on all the processors:
Psurf(10)=1000+0=1000Pa
Psurf(11)=0+999=999Pa
if (irangp.le.0) then
OPEN(FILE='pressure_field.csv',UNIT=11,ACCESS='APPEND')
! here you need to change the loop on NLELT and do the loop on value of Psurs(i)=j or j /=0.d0
Do ii=1, NLELT
if (Xgrav(ii) /= 0.d0) then
WRITE(11,*) &
Xgrav(ii),';',Ygrav(ii),';',Zgrav(ii),';',Psurf(ii)
endif
Enddo
CLOSE(UNIT=11)
endif