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
 

 

Execute a routine only once

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler
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    Post subject: Execute a routine only once
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

Active Member


Joined: 07 Feb 2009
Posts: 982
Location: Oostende, Belgium

PostPosted: Mon Jul 27, 2009 1:19 pm    Post subject:
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    Post subject:
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

Active Member


Joined: 07 Feb 2009
Posts: 982
Location: Oostende, Belgium

PostPosted: Mon Jul 27, 2009 2:04 pm    Post subject:
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    Post subject:
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

Active Member


Joined: 07 Feb 2009
Posts: 982
Location: Oostende, Belgium

PostPosted: Mon Jul 27, 2009 3:10 pm    Post subject:
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    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Mon Jul 27, 2009 4:01 pm    Post subject: Reply to: Execute a routine only once
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

Active Member


Joined: 08 May 2006
Posts: 988
Location: Dublin, Ireland / Edinburgh, Scotland

PostPosted: Mon Jul 27, 2009 4:30 pm    Post subject:
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    Post subject:
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    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Mon Jul 27, 2009 5:16 pm    Post subject: Reply to: Execute a routine only once
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: 7908
Location: Bellevue, IA

PostPosted: Mon Jul 27, 2009 5:17 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SORT - E15 and E35 using same user ex... Abhi Nature DFSORT/ICETOOL 12 Mon Oct 03, 2016 4:33 pm
No new posts execute APP if they are not ADDRESS T... italo_pm CLIST & REXX 3 Fri Aug 12, 2016 2:15 am
No new posts Execute multiple DB2 Load commands in... faizm DB2 4 Wed Aug 03, 2016 12:53 pm
No new posts CEXEC not able to execute if no SLINE... boyti ko CLIST & REXX 2 Wed Apr 13, 2016 4:31 pm
No new posts CALL MACRO EXECUTE FORM - Setting the... sudarshan.srivathsav PL/I & Assembler 7 Tue Feb 09, 2016 10:32 pm


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