Vous êtes sur la page 1sur 5

MULTI THREADING

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.

WORKING OF THE MULTITHREADING SUBSYSTEM IN GLOBUS

A program by name BATCH.JOB.CONTROL is the key program that makes multithreading


possible in GLOBUS. It is this program that is responsible for splitting the job into multiple
threads and executing them simultaneously, thus making full use of the processors
available.Before we understand the working of this program, firstly we must decide on the
name of our job (this will be exactly the same as the name of your routine).Once the job
name is decided, the following files need to be created.

xxx.SELECT The routine which will prepare a key only file


containing all the ids which need to be
processed by this job
xxx.LOAD The routine which will perform any
initialization (file opens etc).
xxx.COMMON Insert for a labeled common:
This file will hold all initialized variables for
use by the job.
xxx The batch job itself with ONE argument
passed (the id to be processed). It is very
important not to perform any initialization in
this program this will be repeated
THOUSANDS of times as the routine is
called for every contract.
BATCH.JOB.CONTROL

I_xxx.COMMON

xxx.LOAD

xxx.SELECT xxx.LIST

xxx

Figure 1.1 Flow of the multithreading subsystem in Globus

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

COM /ACCALCCOM/ FN.CUS,


FN.AC,
FV.AC,
FN.CUS.ACC,
FV.CUS.ACC,
FN.AC.CA.LI,
FV.AC.CA.LI,
FV.CUS,
CUS.REC,
CUS.NAT,
CUS.RES,
AC.ACC.OFF,
AC.WORK.BAL,
AC.ONL.BAL,
AC.MNE,
NO.CUS.ACC,
CNT.CUS.ACC,
CUS.ACC.REC,
WRITE.REC,
AC.REC,
WR.FILE

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

*Open the Customer file


FN.CUS = 'F.CUSTOMER' ; FV.CUS = ''
CALL OPF(FN.CUS,FV.CUS)
*Open the Account file
FN.AC = 'F.ACCOUNT' ; FV.AC = ''
CALL OPF(FN.AC,FV.AC)
*Open the Customer.Account file
FN.CUS.ACC = 'F.CUSTOMER.ACCOUNT' ; FV.CUS.ACC = ''
CALL OPF(FN.CUS.ACC,FV.CUS.ACC)
RETURN
END

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.

Globus Demo Account PROGRAM FILE, INPUT

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.

Globus Demo Account BATCH ENTRY, INPUT

BATCH PROCESS..... AC.CALC.EOD


------------------------------------------------------------------------------
1 BATCH.STAGE....... A002 APPLICATION
2 DEFAULT.PRINTER...
3 PROCESS.STATUS.... 0 READY
4 BATCH.ENVIRONMENT. F FOREGROUND
5 DEPARTMENT.CODE...
6. 1 JOB.NAME....... GREAT
7. 1. 1 VERIFICATION
8. 1 FREQUENCY...... D DAILY
9. 1 NEXT.RUN.DATE.. 09 MAR 2000
10. 1 PRINTER.NAME...
11. 1. 1 DATA........
12. 1 JOB.STATUS..... 0 READY
13. 1 LAST.RUN.DATE.. 08 MAR 2000
14. 1 JOB.MESSAGE....
15. 1 USER...........
16 RECORD.STATUS.....

Vous aimerez peut-être aussi