Hello
First, you there is no need for the IF (ncsize>1) because the subroutine GLOBAL_TO_LOCAL_POINT(I,MESH) will return I if ncsize is <=1. But this is not the problem ! this is just a part of the problem.
Actually, if node I is not in the subdomain, subroutine GLOBAL_TO_LOCAL_POINT will return 0 and that's why you have problem when you use KFROPT%I(K) because K is 0.
Therefore, you can replace, for instance, the line
KFROPT%I(K) = IVAL2
by
IF(K.NE.0)KFROPT%I(K) = IVAL2
and the final code reads:
DO I = 1,NPOIN_GLOB
READ(NFILE,*,END=999,ERR=998) IVAL1, IVAL2
K = GLOBAL_TO_LOCAL_POINT(I,MESH)
IF(K.NE.0)KFROPT%I(K) = IVAL2
ENDDO
Actually, as it was said by Jean Michel and Leo, this solution is expensive and needs to be optimized especially if there are many calls to GLOBAL_TO_LOCAL_POINT.
A final remark about your second solution. yes it works, but is false: you are looping with the index I (first loop DO I=1,NPOIN_GLOB) and in serial case you use the index K (KFROPT%I(K) = IVAL2). Thus the serial case is not good.
With my best regards
Riadh ATA