Service Operations Insight

 View Only
  • 1.  ADN Command to Exit While Loop

    Posted Jun 02, 2016 01:13 PM

    How to exit a while loop immediately? The break command doesn't work, saying it's reserved for future use.



  • 2.  Re: ADN Command to Exit While Loop

    Posted Jun 08, 2016 10:31 AM

    Hello Christoper,

     

    Is this issue with capacity manager? if so, which part of the product are you experiencing this issue?



  • 3.  Re: ADN Command to Exit While Loop

    Posted Jun 08, 2016 11:10 AM

    ADN is the language built into the Hyperformix Modeler product.

     

    It memory serves the While statement is only evaluated after all the steps under it are completed.

     

    Sounds like maybe you want to use another way to write this statement...What are you trying to do in the While statement?

     

    David



  • 4.  Re: ADN Command to Exit While Loop

    Posted Jun 08, 2016 11:28 AM

    Here is a section of code that was written long ago using the WHILE statement in ADN.

     

    Maybe this will give you an idea of how to improve your code:

     

    Within this code snippet the While statement is used more than once.

     

        // -------------------------
        public behavior service( tSubsystemName ) {

            didForward = false;
            integer mode = transactionMode();
            beginService();
            if ( localTime <= 0 ) {
                call serviceExecute();
            }
            else {
                if (( mode == LOCAL ) || ( mode == PARALLEL_LOCAL )) {
                    remLocalTime = localTime;
                }
                else {
                    qTime = simGetTime() - fQueueStartTime;
                    remLocalTime = localTime - qTime; //  Remaining local time
                }
                if ( remLocalTime <= 0.0 ) {
                    call serviceExecute();
                }
                else {
                    join {
                        thread { Delay remLocalTime; }
                        thread { call serviceExecute(); }
                    }  // End join
                }  // End if
            }  // End if

            integer ccInt;
            integer ccLoop;
            real ccRem;
            real prob;
            ses_ResourcePoolIF ptPool;

            if ( count1 < 0.0 ) {
                ccInt = 10000;
            }
            else {
                if ( count1 < 1.0 ) {
                    print "*** Background_phgp0137_UnCoupled parallel thread count =", count1, "; must be >= 1.0";
                    print "*** Background_phgp0137_UnCoupled.count1 set to 1.0";
                    count1 = 1.0;
                }
                ccInt = Integer( count1 );
                ccRem = count1 - ccInt;
                if ( ccRem > 0.0 ) {
                    prob = Uniform( 0.0, 1.0 );
                    if ( prob <= ccRem ) {
                        ccInt = ccInt + 1;
                    }
                }
            }
            ptPool = ses_ResourcePoolFactory.create( "Background_phgp0137_UnCoupled_CalleeThreadPool",
                                                    ccInt, ses_ResourcePoolFactory.DISCIPLINE_FIFO,
                                                    ses_ResourcePoolFactory.POOLTYPE_RESOURCE ,
                                                    ses_ResourcePoolFactory.POOLSTATS_NONE );
            //  Begin Parallel group
            join {
                thread {
                    integer mode2 = ses_Transaction.PARALLEL_LOCAL;
                    integer ccInt2;
                    integer ccLoop2;
                    real ccRem2;
                    real ccProb2;
                    ccInt2 = Integer( count2 );
                    ccLoop2 = ccInt2;
                    while ( ccLoop2 > 0 ) {
                        call ptPool.allocate( 1 );
                        call Background_phgp0137_CPUtime.initiate( this, mode2, null );
                        tmp = ptPool.free( 1 );
                        ccLoop2 = ccLoop2 - 1;
                    }
                    ccRem2 = count2 - ccInt2;
                    if ( ccRem2 > 0.0 ) {
                        ccProb2 = Uniform( 0.0, 1.0 );
                        if ( ccProb2 <= ccRem2 ) {
                            call ptPool.allocate( 1 );
                            call Background_phgp0137_CPUtime.initiate( this, mode2, null );
                            tmp = ptPool.free( 1 );
                        }
                    }
                }    //  End thread
                thread {
                    integer mode3 = ses_Transaction.PARALLEL_LOCAL;
                    integer ccInt3;
                    integer ccLoop3;
                    real ccRem3;
                    real ccProb3;
                    ccInt3 = Integer( count3 );
                    ccLoop3 = ccInt3;
                    while ( ccLoop3 > 0 ) {
                        call ptPool.allocate( 1 );
                        call Background_phgp0137_DiskIO.initiate( this, mode3, null );
                        tmp = ptPool.free( 1 );
                        ccLoop3 = ccLoop3 - 1;
                    }
                    ccRem3 = count3 - ccInt3;
                    if ( ccRem3 > 0.0 ) {
                        ccProb3 = Uniform( 0.0, 1.0 );
                        if ( ccProb3 <= ccRem3 ) {
                            call ptPool.allocate( 1 );
                            call Background_phgp0137_DiskIO.initiate( this, mode3, null );
                            tmp = ptPool.free( 1 );
                        }
                    }
                }    //  End thread
            } // end join
            endService( msgReplySize );
            mode = transactionMode();
            if ( (mode == SEQUENTIAL_ASYNC) || (mode == PARALLEL_ASYNC) ||
                ( (mode == FORWARD) && (didForward || !(isSynchronousThread())) ) ) {
                endTransaction();
            }
        } // end service



  • 5.  Re: ADN Command to Exit While Loop

    Posted Jun 08, 2016 11:58 AM

    So it looks like the short answer is that there is no escape clause for while loops in ADN. I had a while loop that loops as long as the array value == 0 but needed to escape the loop if it was the last index in the array because it would increment the index value and loop with an error because the index would be out of the range. It would have been simple to say "if index == arraysize then break" but instead my workaround is to decrement the index by 1 if index == arraysize. The simulation time expires ending the loop.



  • 6.  Re: ADN Command to Exit While Loop

    Posted Jun 08, 2016 12:37 PM

    That is correct.

     

    If my memory is correct, the development team opted NOT to implement the BREAK because it leads to bad coding techniques.   Your workaround is actually a better way to handle it, and considered good coding by the object oriented experts in our old Hyperformix development team.

     

    http://www.informationweek.com/software/information-management/hyperformix-awarded-patent-for-application-performance-solution/d/d-id/1032258?

     

    This is one of the developers:

    Allan Clarke's Home Page

     

     

    David



  • 7.  Re: ADN Command to Exit While Loop

    Posted Jun 09, 2016 04:11 AM

    Wow - congratulations David - your memory is better than mine!  It's been a while since I touched ADN at that level, and I'd forgotten all about some of that stuff.