View previous topic :: View next topic
|
Author |
Message |
razesh84
New User
Joined: 05 Apr 2010 Posts: 41 Location: Kolkata,India
|
|
|
|
Hi,
One of my cobol module takes 13min of cpu.Using strobe i found that 99% of
cpu was spent during a conditional expression
IF A > B
Move statements
A & B both defined as follows
Code: |
01 A PIC 9(06) VALUE ZERO.
01 B PIC 9(06) VALUE ZERO. |
I changed the definition of both variables like these
1> PIC S9(06) COMP VALUE ZERO
2> PIC S9(06) COMP-3 VALUE ZERO
3> A1 REDEFINES A PIC X(06) & checked with A1 [IF A1 > B1]
Here are the CPU times of the runs
Comp - 19:18.96
Comp-3 - 08:56.59
Alphanumeric - 10:19.68
However, when i changed the compiler option from TRUNC(BIN) to TRUNC(OPT) with COMP fields CPU time reduced to 04:19.56.
Can anyone tell me which USAGE performs optimum for conditional statement.Also are there any other compiler option that i can use.
Based on those stats can i conclude that for conditional checking datatypes are efficient by the following order
COMP-3>Alphanumeric>Numeric>Binary |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
One of the basic rules for arithmetic comparison is (when you can), try and use like data-types.
In your example, comparing display-numeric to binary (halfword or fullword) is a good example of a bad idea. Substituting with a binary doubleword (9(18) COMP), could very well cause the compiler to call a run-time routine and make things even worse.
Depending on the TRUNC Option (as you've found), TRUNC(BIN) can cause all sort of gyrations (also known as a dog with fleas) and the compiler could wind up expanding into several dozen instructions, just to issue a simple comparison.
If your compiler supports COMP-5 (introduced with OS/390 COBOL version 2.2.1), then it would be wise on your part to convert all variables defined as COMP/BINARY/COMP-4 to COMP-5. The TRUNC option has no affect on COMP-5.
Search this forum for COMP-5 and you'll find other postings.
I would also caution you on the usage of the NUMPROC(PFD) option, which (IMHO) should never be used. It can really wreak havoc when you least expect it and cause all sorts of headaches.
Bill |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Based on those stats can i conclude that for conditional checking datatypes are efficient by the following order
COMP-3>Alphanumeric>Numeric>Binary
|
Only for the specific test you ran. This will not be true for other comparisons. . . |
|
Back to top |
|
|
razesh84
New User
Joined: 05 Apr 2010 Posts: 41 Location: Kolkata,India
|
|
|
|
Thanks Bill
let me try with the COMP-5 thing tomorrow.
Quote: |
One of the basic rules for arithmetic comparison is (when you can), try and use like data-types. |
In my first run both variables [A& B]was defined 9(06),2nd run S9(06) COMP,3rd run S9(06) COMP-3,4th run X(06) & last S9(06) COMP with TRUNC(OPT) in effect.
so i maintained similar data-types in all the runs.
Though the CPU dropped from 13 to 7 min with this(comp+trunc-opt) still 7 mins of CPU on a single comparison looks to much to me.what do you think on this?
I guess there is still a scope of improvement.Please let me know if there is anything else you need to know.
@Dick
i agree with you...every module has its own problem & requires unique solution |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
still 7 mins of CPU on a single comparison looks to much to me.what do you think on this? |
I suspect that 7 cpu minutes is not used for a single comparison. . . Or there is more to the "compare" than a simple IF.
One of the processes i ran today processed more than 100 million records and did multiple comparisons and calculations and used less than 2 minutes cpu. . . I don't know the processing power of the lpar, but it is not incredably big (from what i'm told).
How many records are being read? |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Is the compare statement the culprit, or the following move statements?
Maybe you could give the whole piece of coding? And how about showing
the assembler statements generated for this piece? |
|
Back to top |
|
|
razesh84
New User
Joined: 05 Apr 2010 Posts: 41 Location: Kolkata,India
|
|
|
|
Hi all,
@Bill
good news is the compiler supports COMP-5 but bad news is no improvement
CPU time is still hovering around 19 mins which is more than what current production code takes.I may run it tomorrow hoping for some drop in cpu.
@Dick
Strobe report is concentrating on this particular statment(98% CPU).Here is the full piece of code.This IF statment executed 19,720,074,876 times
Code: |
IF WS-SUB > WS-ACT-SUB
MOVE 0 TO WS-FOUND-SW
MOVE 1 TO WS-LOOP-END-SW
ELSE
IF AIR-ACCT-NUM = WS-PBD-ACT (WS-SUB)
MOVE 1 TO WS-FOUND-SW
MOVE 1 TO WS-LOOP-END-SW
ELSE
ADD 1 TO WS-SUB
END-IF
END-IF. |
@Peter
Can you please tell me where i can find the assembler statements.
Thank you all guys
I ran the code all day long with little changes here & there but nothing excited me |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
How big is the table being searched? |
|
Back to top |
|
|
razesh84
New User
Joined: 05 Apr 2010 Posts: 41 Location: Kolkata,India
|
|
|
|
table definition
Code: |
01 MSSC-TRANSLATE-TABLE.
02 WS-ACCOUNT-TRANS OCCURS 99999.
03 entry1 PIC X(09).
03 entry2 PIC X(09).
03 entry3 PIC X(09).
03 entry4 PIC X(09).
|
|
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
You could try adding INDICES to the table, dynamically calculating the maximum table-hibound in Housekeeping.
Use the INDICES instead of subscripts.
Code: |
01 MSSC-TRANSLATE-TABLE.
02 WS-ACCOUNT-TRANS OCCURS 99999
INDEXED BY X-WS-AT, X-WS-AT-MAX.
03 entry1 PIC X(09).
03 entry2 PIC X(09).
03 entry3 PIC X(09).
03 entry4 PIC X(09).
01 WS-BINARY-REC.
03 WS-FWORD PIC S9(08) COMP-5.
DIVIDE LENGTH OF MSSC-TRANSLATE-TABLE BY LENGTH OF WS-ACCOUNT-TRANS (1) GIVING WS-FWORD.
SET X-WS-AT TO 1.
SET X-WS-AT-MAX TO WS-FWORD.
|
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Use binary search to reduce the time to find the account number. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Was there some reason the actual field names for the array were not posted. . .
If WS-PBD-ACT is actually one of the "entry" array fields and the array data is sorted by this prior to loading the array, and SEARCH ALL (binary search) is used, most of the cpu time will dissappear.
As luck would have it, someone here had a similar situation. Their original lookup was much like yours. The original lookup used:
Code: |
/STOP 2010278.1035 CPU 2MIN 56.58SEC |
Using SEARCH ALL the following cpu was used:
Code: |
/STOP 2010279.1305 CPU 0MIN 10.71SEC |
Another thing to consider when using a table lookup it that if the "current" value is the same as the "previous" value, there is no need to look in the array. The code already knows whether the value is "found" or not and if found, the proper position in the array is in the index. . . |
|
Back to top |
|
|
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
Razesh84,
It seems to me that the datatype is not the issue here.
The issue is that the statement was executed 19 billion times.
How many entries (exact number) are in this table (for the run in question?) Does WS-ACT-SUB contain this value?
How many input records are being checked against the table (for the run in question?)
You may want to consider using and external Sort with a Joinkeys to append the matching information to the end of each input record.
This way you can eliminate the loop and IF statement, thus reducing your CPU time by 98%.
Please answer all of the questions. Doing so will help everyone here help you.
Do not be focused on one particular, look at the big picture. |
|
Back to top |
|
|
razesh84
New User
Joined: 05 Apr 2010 Posts: 41 Location: Kolkata,India
|
|
|
|
Hi,
@Dick
I somehow overlooked the 2nd if statement.I dont know why i masked the original fields name....may be working really hard....need a break
sorry about that
@Dave
yes....you are right...its not the problem with the datatype.two things influenced me to stick on the datatype.
1> i got an improvement of 50% cpu changing a subscripts from usage display to binary in my previous module
2> strobe was pointing me to the first if.
this may be the reason......since the outer if executed more than the inner(search)....first if was highlighted although the main reason was something else.
thanks you all guys.....
we're having holiday season right now...will tell you later how much savings i got
bye |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
i got an improvement of 50% cpu changing a subscripts from usage display to binary in my previous module |
Expected. . .
Binary arithmetic is much, much faster than adding to a zoned-decimal number. There is no "machine instruction" to add to zoned-decimal, so the data muct be converted before the arithmetic can happen and then converted back to zoned-decimal after the add. A bit of handy learning might be to look at the assembler code generated for each . . .
Hope you enjoyed the holidays
d |
|
Back to top |
|
|
razesh84
New User
Joined: 05 Apr 2010 Posts: 41 Location: Kolkata,India
|
|
|
|
Hi Guys,
sorry for kept you all waiting!!!!
just finished the code & the result is a big fat 99.999% improvement in cpu....yes it dropped to 5 seconds from 13 mins
another module gone.... i got a whole system left
@dick
can you please tell me how/where to look for the assembler codes |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Change the ID DIVISION statement to these 2 statements:
Code: |
CBL LIST
IDENTIFICATION DIVISION. |
The compile output will contain something like this:
Code: |
000236 SEARCH
0008BA 47F0 B2E2 BC 15,738(0,11)
0008BE GN=19 EQU *
000237 GO
0008BE 47F0 B404 BC 15,1028(0,11)
0008C2 47F0 B356 BC 15,854(0,11)
0008C6 GN=9 EQU *
000238 WHEN
0008C6 D20B D150 2760 MVC 336(12,13),1888(2)
0008CC 4150 D150 LA 5,336(0,13)
0008D0 5050 D142 ST 5,322(0,13)
0008D4 D203 D160 A020 MVC 352(4,13),32(10) |
This is the first part of the code generated by the SEARCH ALL. |
|
Back to top |
|
|
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
So what was the code change? |
|
Back to top |
|
|
razesh84
New User
Joined: 05 Apr 2010 Posts: 41 Location: Kolkata,India
|
|
|
|
@dave
1> set the array size dynamically [DEPENDING ON]
2> used binary search instead of IFs [as suggested by Robert & others]
with all other compiler options intact that means TRUNC(BIN) is still on!!! |
|
Back to top |
|
|
razesh84
New User
Joined: 05 Apr 2010 Posts: 41 Location: Kolkata,India
|
|
|
|
@dick
i put 'CBL LIST' statement in one of my code & found something like this in the listing
Code: |
005884 MOVE
00641E D202 2918 31D6 MVC 2328(3,2),470(3) TABLE1-CNTY-CD WK-A-TABLE1-CNTY-CD
005885 SEARCH
006424 47F0 BEDC BC 15,3804(0,11) GN=75(006436)
006428 GN=224 EQU *
005887 MOVE
006428 5820 9130 L 2,304(0,9) BLW=0
00642C D20E 22C4 C00C MVC 708(15,2),12(12) WK-MBR-COUNTY-NAME SYSLIT AT +12
006432 47F0 BF72 BC 15,3954(0,11) GN=74(0064CC)
006436 GN=75 EQU * |
can you please tell me how to interpret it? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
can you please tell me how to interpret it? |
Probably not. . .
You might not realize it but you just asked to be taught assembler. We are not able to provide this level of training.
Looking at assembler is fine as long as there is at least some existing knowledge of the assembler language. . . |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
Here's your impetus to take an assembler class. You'll learn what's actually going on, and it's fun, too! |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Razesh84 said -
Quote: |
it dropped to 5 seconds from 13 mins |
That's terrific! Well done young man.
Keep up the good work and stellar effort.
Bill |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Razesh84,
with an assembler manual in hand,
and a cobol listing of a reasonably complex cobol program,
you can at least get a feel for what is done.
you won't learn how to write assembler,
but understanding how/what the cobol instructions are expanded to assembler will help you write better cobol.
a good example is look at the code generated to reference table items with subscripts
and compare the same code written with indexes. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Follow-on:
If you want to read about assembler and would prefer a "book" rather than a reference manual, i suggest you find the book written by Kevin McQuillen (more than 30 years ago).
d |
|
Back to top |
|
|
|