IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Execute a routine only once


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Pankaj Shrivastava
Currently Banned

New User


Joined: 24 Jul 2009
Posts: 51
Location: Pune

PostPosted: Mon Jul 27, 2009 12:58 pm
Reply with quote

Hi ,

I have a situation , where i need to execute a routine only for the first record of the file , and for susequent records I should not execute the routine . I saw/practiced the basic way of doing this is to set a flag 'N' After the first execution and check each time the value of this flag for 'Y' to determine if it has to be executed or not .

Code:

CLI      FLAG,'Y' 
BNE      SKIP     
MVI      FLAG,'N' 
ROUTINE  EQU  *   
...               
...               
SKIP     EQU  *   
...               
...               
FLAG     DC  C'Y' 


Is there any smarter way of doing this . Please help
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Mon Jul 27, 2009 1:19 pm
Reply with quote

Why?

Is this method using to many yoctoseconds or not obfuscated enough?
Back to top
View user's profile Send private message
Pankaj Shrivastava
Currently Banned

New User


Joined: 24 Jul 2009
Posts: 51
Location: Pune

PostPosted: Mon Jul 27, 2009 1:26 pm
Reply with quote

Robert,

My Program is reading more than 36 million records , this certainly is consuming some time checking the CLI each time .

I cant close the file after first record to reset the pointer in file .
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Mon Jul 27, 2009 2:04 pm
Reply with quote

Pankaj Shrivastava wrote:
My Program is reading more than 36 million records , this certainly is consuming some time checking the CLI each time .


Are you effing serious?

The following PL/I code:

Code:
dcl i fixed bin (31);
dcl j fixed bin (31);
j = random() * 10000000;
put skip data(j);
put skip list(datetime());
do i = 1 to 10000000;
  if i = j then
    put skip data(i);
end;
put skip list(datetime());


Results in this output, punctuation added to the timestamps for clarity:

Code:

J=       4427071;
2009-07-27T10:23:54.294
I=       4427071;
2009-07-27T10:23:54.346


In other words, this whole loop took 52 milliseconds in a compiled language.
Back to top
View user's profile Send private message
Pankaj Shrivastava
Currently Banned

New User


Joined: 24 Jul 2009
Posts: 51
Location: Pune

PostPosted: Mon Jul 27, 2009 2:40 pm
Reply with quote

Thx Robert , I appreciate your calculation . But i was looking for an answer not your justification of sparing 52 millisecond . If you dont know an alternative ..better not jump to write any thing rediculous .
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Mon Jul 27, 2009 3:10 pm
Reply with quote

Pankaj Shrivastava wrote:
I appreciate your calculation . But i was looking for an answer not your justification of sparing 52 millisecond . If you dont know an alternative ..better not jump to write any thing rediculous .


My code showed that running this loop 10,000,000 times takes all of 52 milliseconds, so the kind of test will take about 5.2 nano-seconds. Assuming that your test will take about the same time, it will take less than .2 seconds of the total processing time for your 36,000,000 records, and the time to do so will be several orders of magnitude in excess of those 0.2 seconds.

The "CLI/BNE" code is readable and as fast as it possibly can be.
Back to top
View user's profile Send private message
Pankaj Shrivastava
Currently Banned

New User


Joined: 24 Jul 2009
Posts: 51
Location: Pune

PostPosted: Mon Jul 27, 2009 3:51 pm
Reply with quote

Why your are struck in calculation of millisecond or so..i agree that it will hardly matter in one run or two .

Looking forward for someone to provide me an innovative solution ...
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Mon Jul 27, 2009 4:01 pm
Reply with quote

You can't get much faster than a CLI (an SI instruction), as the operand is part of the instruction and I don't really see an overhead issue at all.

You may want to look at a conditional NOP and that might give you back some time, although it will be minimal in the grand scheme of things.

You could try using SI instruction TM (it might be slightly faster, although that's a relative term), where the first time through, the target label is X'80' and then it is reset to X'00'. So, you'd have two different condition-codes: BO for the first TM X'80' (reset to X'00') and BZ for all other times (High-Bit is Off).

Bill
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Mon Jul 27, 2009 4:30 pm
Reply with quote

Pankaj,
Theres is a way. Some sites don't like self-modifying code, but this sample would do the trick.....
Code:
CHGME    NOP   SKIPIT             
         MVI   CHGME+1,X'F0'     
ROUTINE  EQU   *                 
         .                       
         .                       
         .                       
         .                       
         .                       
         .                       
SKIPIT   EQU   *                 


Basically, what's being done is to change a NOP instruction to a branch. The first time through, the NOP does nothing,the next instruction changes the NOP to a branch and the code in ROUTINE gets executed. Next time(s) through, the instruction at CHGME is a branch around ROUTINE.

Sometimes it's nice just to know that you can do these things....

Garry.
Back to top
View user's profile Send private message
Pankaj Shrivastava
Currently Banned

New User


Joined: 24 Jul 2009
Posts: 51
Location: Pune

PostPosted: Mon Jul 27, 2009 4:30 pm
Reply with quote

I wrote a simple program ..wherein i tried to avoid using any conditional check to determine the execution of a routine :

Code:

PGMXYZ   START  0               
         BALR   3,0             
         USING  *,3             
         ST     14,MYVAR         
         LH     7,=H'10'         
         LA     6,FIRSTIME       
         B      CNTR             
LOOP     BR     6               
FIRSTIME EQU    *               
         LA     6,OTHRTIME       
         WTO   'FIRSTTIME'       
         B      CNTR             
OTHRTIME EQU    *               
         WTO    'OTHERTIME'     
CNTR     BCT    7,LOOP           
SKIP     L      14,MYVAR         
         BR     14               
FLAG     DC    C'Y'             
MYVAR    DS    F                 
         END                     



Here rather then using CLI i am using BR ..and the dseired address ( first or subsequent ) has been put in place.

Please comment if this code has any glitch ..though it lloks as if it may work better than conditional one .

Thanks
Back to top
View user's profile Send private message
Pankaj Shrivastava
Currently Banned

New User


Joined: 24 Jul 2009
Posts: 51
Location: Pune

PostPosted: Mon Jul 27, 2009 4:58 pm
Reply with quote

Thanks a lot !! The NOP is really a fentastic way !!

Thanks ..i will keep your suggestion icon_biggrin.gif
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon Jul 27, 2009 5:16 pm
Reply with quote

using a nop will make the program not reentrant,
many audit/review processes will reject the code
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Jul 27, 2009 5:17 pm
Reply with quote

Quote:
I have a situation , where i need to execute a routine only for the first record of the file , and for susequent records I should not execute the routine
Why not have the first record read, execute your routine, then start a loop to read the rest of the records? Sure there's two read statements but there's no testing overhead at all.

Of course, as was pointed out, you are spending WAY too much time and effort worrying about fractions of a second. You want to optimize something that does not need optimizing anyway. If your program was having performance problems (such as not completing within the batch window), I'd say you might want to think about this. If it is completing within the expected time frame, though, you're just wasting resources looking at this.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Execute secondary panel of sdsf with ... CLIST & REXX 1
No new posts Fetch data from programs execute (dat... DB2 3
This topic is locked: you cannot edit posts or make replies. How To Write, Compile and Execute Cob... COBOL Programming 5
No new posts ACS exit routine JCL & VSAM 0
No new posts Evaluate variable to execute a jcl step JCL & VSAM 3
Search our Forums:

Back to Top