Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Efficient datatype for condition checking
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
razesh84

New User


Joined: 05 Apr 2010
Posts: 41
Location: Kolkata,India

PostPosted: Wed Oct 06, 2010 6:36 pm    Post subject: Efficient datatype for condition checking
Reply with quote

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
View user's profile Send private message

Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Oct 06, 2010 10:58 pm    Post subject: Reply to: Efficient datatype for condition checking
Reply with quote

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
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Oct 07, 2010 12:09 am    Post subject:
Reply with quote

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
View user's profile Send private message
razesh84

New User


Joined: 05 Apr 2010
Posts: 41
Location: Kolkata,India

PostPosted: Thu Oct 07, 2010 1:08 am    Post subject:
Reply with quote

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
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Oct 07, 2010 3:40 am    Post subject:
Reply with quote

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
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Thu Oct 07, 2010 4:13 pm    Post subject:
Reply with quote

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
View user's profile Send private message
razesh84

New User


Joined: 05 Apr 2010
Posts: 41
Location: Kolkata,India

PostPosted: Thu Oct 07, 2010 6:51 pm    Post subject:
Reply with quote

Hi all,

@Bill
good news is the compiler supports COMP-5 but bad news is no improvement icon_cry.gif
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 icon_exclaim.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Thu Oct 07, 2010 6:56 pm    Post subject:
Reply with quote

How big is the table being searched?
Back to top
View user's profile Send private message
razesh84

New User


Joined: 05 Apr 2010
Posts: 41
Location: Kolkata,India

PostPosted: Thu Oct 07, 2010 7:03 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Oct 07, 2010 7:12 pm    Post subject: Reply to: Efficient datatype for condition checking
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Thu Oct 07, 2010 7:24 pm    Post subject:
Reply with quote

Use binary search to reduce the time to find the account number.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Oct 07, 2010 7:35 pm    Post subject:
Reply with quote

Hello,

Was there some reason the actual field names for the array were not posted. . . icon_sad.gif

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
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 645
Location: Pennsylvania

PostPosted: Thu Oct 07, 2010 10:05 pm    Post subject:
Reply with quote

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
View user's profile Send private message
razesh84

New User


Joined: 05 Apr 2010
Posts: 41
Location: Kolkata,India

PostPosted: Sat Oct 09, 2010 8:42 pm    Post subject:
Reply with quote

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
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sat Oct 09, 2010 9:05 pm    Post subject: Reply to: Efficient datatype for condition checking
Reply with quote

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 icon_smile.gif

d
Back to top
View user's profile Send private message
razesh84

New User


Joined: 05 Apr 2010
Posts: 41
Location: Kolkata,India

PostPosted: Fri Oct 22, 2010 6:58 pm    Post subject:
Reply with quote

Hi Guys,

sorry for kept you all waiting!!!!
just finished the code & the result is a big fat 99.999% icon_biggrin.gif 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 icon_question.gif
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Fri Oct 22, 2010 7:10 pm    Post subject:
Reply with quote

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
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 645
Location: Pennsylvania

PostPosted: Fri Oct 22, 2010 7:12 pm    Post subject:
Reply with quote

So what was the code change?
Back to top
View user's profile Send private message
razesh84

New User


Joined: 05 Apr 2010
Posts: 41
Location: Kolkata,India

PostPosted: Fri Oct 22, 2010 7:35 pm    Post subject:
Reply with quote

@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
View user's profile Send private message
razesh84

New User


Joined: 05 Apr 2010
Posts: 41
Location: Kolkata,India

PostPosted: Fri Oct 22, 2010 9:15 pm    Post subject:
Reply with quote

@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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. How to pass the previous month date i... Suganya87 DFSORT/ICETOOL 5 Mon Oct 31, 2016 4:13 pm
No new posts Efficient sorting chandracdac DFSORT/ICETOOL 5 Sat Oct 22, 2016 3:23 am
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Syncsort - NULL in Integer field chec... nartcr SYNCSORT 4 Thu Oct 06, 2016 6:47 am
No new posts Reasonable way of checking wildcards ... sergeyken CLIST & REXX 5 Wed Sep 07, 2016 8:43 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us