How to initialize the array/table in cobol ?



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Re: How to initialize the array/table in cobol ?

Postby wicherc » Thu Sep 06, 2012 7:34 pm

BillyBoyo: Thanks for your response. I never saw this format of coding. But i tested and work ok. But......
In our case, a program calls to a routine, for thousands, and in each call initialize an array with 4000 occurs. This method and others we tested, are consuming a lot of CPU in serv.units and cpu time (more than 10').
Thanks again!
wicherc
 
Posts: 7
Joined: Tue Sep 04, 2012 12:36 am
Has thanked: 0 time
Been thanked: 0 time

Re: Re: How to initialize the array/table in cobol ?

 

Re: How to initialize the array/table in cobol ?

Postby dick scherrer » Thu Sep 06, 2012 8:12 pm

Hello,

You might consider having an initialized set of data in the calling program, passing this as one of the parms in the CALL, and then the called code would spend NO time initializing . . . There would be 2 sets in the calling program.

One that is initialized and is never modified. The other would be simply moved to before the call.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: How to initialize the array/table in cobol ?

Postby BillyBoyo » Thu Sep 06, 2012 8:14 pm

OK, time for you to look up "reference modification" in the Cobol manuals.

"Old style" would be slightly faster.

It's not clear to me if this has solved your problem. If not, describe your problem and someone can probably suggestion something.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: How to initialize the array/table in cobol ?

Postby dick scherrer » Thu Sep 06, 2012 8:19 pm

Hello,

My guess is that if one move was issued in the calling program it would be far faster than any lines of individual code or INITIALIZE statements to initialize the the array in the sub-program.

If the goal is to reduce cpu time, reducing or eliminating code to "loop thru" will have the biggest impact.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: How to initialize the array/table in cobol ?

Postby wicherc » Thu Sep 06, 2012 9:04 pm

Hi!
Thanks BillyBoyo and Dick.
The Dick's solution was one we tested, with some slight difference. Look at our code at the routine:
WORKING STORAGE
01  WCA-PRUEBA    PIC  9(9) VALUE ZEROS.
01  TAB-INTERNA.
    05  TAB-SDO                     OCCURS 4000 TIMES.
       10  LIS-MTO-RDO-GR.
         15  COD-CLI-CD            PIC S9(9).
         15  COD-CTA-CD            PIC S9(9).
         15  COD-TIP-DOC-CD        PIC X(2).
         15  NUM-DOC-NU            PIC X(30).
          --------- etc -----------------------------
01  MOV-INTERNA.
         15  FILLER                PIC S9(9).
         15  FILLER                PIC S9(9).
         15  FILLER                PIC X(2).
         15  FILLER                PIC X(30).
       -------------- etc --------------------------
Both have the same qty of fields.

LINKAGE SECTION.
 01  LLAMADA PIC X(7).
* ----------------------------------------
 PROCEDURE DIVISION USING LLAMADA.
      IF WCA-PRUEBA = ZERO
        MOVE 999 TO WCA-PRUEBA
        MOVE 'PRIMERA' TO LLAMADA
        INITIALIZE TAB-INTERNA
        MOVE TAB-INTERNA TO MOV-INTERNA
      ELSE
        MOVE 'RESTO' TO LLAMADA
        MOVE MOV-INTERNA TO TAB-INTERNA.
     GOBACK.
When the pgm calls to the routine for first time, find WCA-PRUEBA = 0, then took the INITIALIZE and move to the other set.
The difference with your suggestion was that the other set of data are inside the routine.
But . . . .
We test this option and compare with the original way and the results didn´t go the best:
Test 1 to 4: the original code with a sentence INITIALIZE TAB-INTERNA at each call. Test 5 to 8: the results testing with the code descripted before:

Test   Elapsed Time   CPU Time   Serv. Units % WFL
1   1.50                     0.58   14039k        66
2   1.70                     0.59   14237k        38
3   0.50                     0.50   12816k        97
4   2.10                     0.74   18247k        30
5   8.2                     1.25   30001k        20
6   1.7                     1.22   29381k        68
7   1.4                     1.21   29231k        95
8   1.6                     1.21   29333k        74
The WFL values is an average we took from RMF for each test.
Thanks a lot for read from the beginning until here.
wicherc
 
Posts: 7
Joined: Tue Sep 04, 2012 12:36 am
Has thanked: 0 time
Been thanked: 0 time

Re: How to initialize the array/table in cobol ?

Postby BillyBoyo » Thu Sep 06, 2012 9:08 pm

In order of "performance"

MOVEing block which only ever holds initial values
The "offset move", "old school"
The "offset move", reference-modification
INITIALIZE
Any sort of loop

There will not be much to choose between the top four, but if doing it a lot of times, it'll add up.

The problem with the first three is ensuring that the data definitions always match when something changes.

This problem can be avoided through some "once-per-run" code in the program which checks that things match up.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: How to initialize the array/table in cobol ?

Postby wicherc » Thu Sep 06, 2012 9:19 pm

One important clarification.
The code was tested 4 times each. The first four with the original code and with identical conditions, and the last with de code described.
This code is all the routine and was called 1 millon times in each time.
wicherc
 
Posts: 7
Joined: Tue Sep 04, 2012 12:36 am
Has thanked: 0 time
Been thanked: 0 time

Re: How to initialize the array/table in cobol ?

Postby BillyBoyo » Thu Sep 06, 2012 9:51 pm

Your results look "odd".

First thing is, are you sure they are the correct way around? I'll assume yes :-)

There is no way there should be twice as much CPU usage. Unless doing eveything twice, or the amount of extra you put in leads to the doubling. So, we have to see.

Firstly Did you check that after million calls LLAMADA is actually "RESTO"? If it is not, please show your compile options.

Secondly, change WCA-PRUEBA to PIC X. Put on an 88 "WCA-PRUEBA-FIRST-TIME VALUE ZERO." Add a 2nd 88 "WCA-PRUEBA-NOT-FIRST-TIME VALUE "1".

     IF WCA-PRUEBA-FIRST-TIME
        SET WCA-PRUEBA-NOT-FIRST-TIME TO TRUE
        INITIALIZE TAB-INTERNA
        MOVE TAB-INTERNA TO MOV-INTERNA
        MOVE 'PRIMERA' TO LLAMADA
      ELSE
        MOVE MOV-INTERNA TO TAB-INTERNA
        MOVE 'RESTO' TO LLAMADA
      END-IF


Just run once and post the results please.
Change TAB-INTERNA to PIC X(whatever) and get rid of all the subordinate items. They are not necessary, and just have to be maintained because they are there. Won't affect the run-time.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: How to initialize the array/table in cobol ?

Postby wicherc » Thu Sep 06, 2012 11:08 pm

Yes, The first time LLAMADA is PRIMERA, and the 1MM with RESTO.
I´ll try with your suggest and post the results.
Thanks!
wicherc
 
Posts: 7
Joined: Tue Sep 04, 2012 12:36 am
Has thanked: 0 time
Been thanked: 0 time

Re: How to initialize the array/table in cobol ?

Postby BillyBoyo » Fri Sep 07, 2012 1:53 am

It's very strange. When I do a 20k MOVE to the table it blasts the INITIALIZE to pieces.

20K was just a guess, not knowing your actual length. I only had one field (4000 times) to INITIALIZE.

Even the extra code as you have it does nothing.

Yet you have it twice as slow.

What version of Cobol are you using (from the top of the compile listing)? Can you paste you compile options here, please?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

PreviousNext

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post