Professional Documents
Culture Documents
MULTI THREADING
When a single process can be executed by more than one processor, the process is said to be
multi-threaded. A thread can be defined as an independent executable unit of a process. The
benefit of this approach is that more that one processor can be used to execute the same process
and therefore the process becomes more time efficient.
MULTITHREADING IN GLOBUS
If you are running using the GLOBUS Desktop then it is possible to run the end of day in multi-
thread mode. In this mode the desktop initiates N number of Unix/NT sessions (the number is a
parameter on the SPF file) which can run batch processes simultaneously.
All batch processes which have the same batch stage and sequence number can be run
simultaneously. Hence FX.END.OF.DAY (A100) can run at the same time as the
LD.END.OF.DAY (A100). The batch control application when run from the desktop control the
synchronization of jobs between the threads hence the next stage cannot commence until the
current stage is complete.
I_xxx.COMMON
xxx.LOAD
xxx.SELECT xxx.LIST
xxx
The BATCH.JOB.CONTROL program first looks for a program called xxx.LOAD. Once found,
executes it and then executes program by name xxx.SELECT. It is in this program that all ids that
have to be processed are selected and written on to a file by name xxx.LIST. The
BATCH.JOB.CONTROL program then picks up ids from this file and supplies it to the program
called xxx. This is the program that will perform the necessary calculations based on the id.
Copies of this program will be made and run simultaneously on the available processors, thus
resulting in multithreading. The number of ids supplied to each copy of the program is
dynamically decided by the BATCH.JOB.CONTROL program.
Example:
Let us understand multithreading with a simple, example. Let us write a program that will list the
Customer Ids,Customer Mnemonics,their respective Account Numbers and the WorkingBalances.
Name of the job : AC.CALC.EOD
Name of routine : AC.CALC
Step1:
Create a file by name I_AC.CALC.COMMON
I_AC.CALC.COMMON
Step2:
Create a file named AC.CALC.LOAD that will open all necessary files
SUBROUTINE AC.CALC.LOAD
$INSERT I_COMMON
$INSERT I_EQUATE
$INSERT I_AC.CALC.COMMON
Step3:
Create a hashed file called AC.CALC.LIST - This file will be used to store all the selected ids.
CREATE.FILE FBNK.AC.CALC.LIST 3 11 4
Note : Ensure that you create a FILE.CONTROL record for this file.You can use the
FILE.CONTROL record of the ACCOUNT file.
Step4:
Create a file by name CUS.SELECT that will selects all the ids from the customer file.
SUBROUTINE AC.CALC.SELECT
$INSERT I_COMMON
$INSERT I_EQUATE
$INSERT I_AC.CALC.COMMON
*This program selects the ids from the Customer file and writes the selected list of ids onto a
hashed file called AC.CALC.LIST
CMMD = "CLEAR.FILE ":FN.AC.CA.LI
EXECUTE CMMD
SEL.CMD = "SELECT FBNK.CUSTOMER"
CALL EB.READLIST(SEL.CMD,CUS.LIST,'',NO.SEL,SEL.ERR)
CALL BATCH.BUILD.LIST('F.AC.CALC.LIST',CUS.LIST)
RETURN
END
Step5:
Create a file called AC.CALC that will manipulate on the ids.
SUBROUTINE AC.CALC(CUS.ID)
$INSERT I_AC.CALC.COMMON
$INSERT I_COMMON
$INSERT I_EQUATE
$INSERT I_F.CUSTOMER
$INSERT I_F.ACCOUNT
$INSERT I_F.CUSTOMER.ACCOUNT
*This program extracts the customers mnemonic,his account numbers and their respective
working balances.
CALL F.READ(FN.CUS,CUS.ID,CUS.REC,FV.CUS,CUS.YERR)
CUS.NAT = CUS.REC<EB.CUS.MNEMONIC>
CALL F.READ(FN.CUS.ACC,CUS.ID,CUS.ACC.REC,FV.CUS.ACC,CUS.ACC.YERR)
NO.CUS.ACC = DCOUNT(CUS.ACC.REC,FM)
IF CUS.ACC.YERR = '' THEN
FOR CNT.CUS.ACC = 1 TO NO.CUS.ACC
CALL F.READ(FN.AC,CUS.ACC.REC<CNT.CUS.ACC>,AC.REC,FV.AC,AC.YERR)
IF AC.YERR = '' THEN
AC.ACC.OFF = AC.REC<AC.ACCOUNT.OFFICER>
AC.WORK.BAL = AC.REC<AC.OPEN.ACTUAL.BAL>
AC.ONL.BAL = AC.REC<AC.ONLINE.ACTUAL.BAL>
AC.MNE = AC.REC<AC.MNEMONIC>
WRITE.REC =
CUS.ID:"*":CUS.NAT:"*":CUS.RES:"*":CUS.ACC.REC<CNT.CUS.ACC>:"*":AC.AC
C.OFF:"*":AC.WORK.BAL:"*":AC.ONL.BAL:"*":AC.MNE
PRINT WRITE.REC
END
NEXT CNT.CUS.ACC
END
RETURN
END
Step6:
Create an entry in the PGM.FILE for the batch job.
PROGRAM AC.CALC.EOD
------------------------------------------------------------------------------
1 TYPE.............. B
2. 1 GB SCREEN.TITLE MULTI THREADING
3 ADDITIONAL.INFO...
4. 1 BATCH.JOB...... @BATCH.JOB.CONTROL
5 PRODUCT........... AC
6 SUB.PRODUCT.......
7. 1 DESCRIPTION....
8. 1 APPL.FOR.SUBR..
9 RESERVED.4........
10 RESERVED.3........
11 RESERVED.2........
12 RESERVED.1........
13 RECORD.STATUS.....
14 CURR.NO........... 1
15. 1 INPUTTER....... 1000_TRAINEE10
16. 1 DATE.TIME...... 06 MAR 01 17:28
Step7:
Create an entry in the BATCH application as follows.