Initializing help system before first use

Using the debugger and profiler


Type: Programming
Rating: 2 (easy-medium)
Description: The Mosel debugger and profiler may be used either through Xpress Workbench or from the Mosel command line. The model prime2.mos shows typical debugging and profiling command sequences. The model prime3.mos is a more efficient re-formulation of the same algorithm. The model runprime2d.mos shows a debugging command sequence for a submodel started from this model.
  • prime2.mos: Debugging and profiling commands
  • runprime2d.mos: Parallel debugging (requires prime2d.mos)
  • prime3.mos: Prime number algorithm for large limit values
File(s): prime2.mos, prime3.mos, runprime2d.mos, prime2d.mos


prime2.mos
(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file prime2.mos 
   ```````````````
   Working with sets.
   -- Debugging and profiling --
 
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, 2001, rev. Jul. 2014
*******************************************************!)

model Prime 

 parameters
  LIMIT=20000                   ! Search for prime numbers in 2..LIMIT
 end-parameters

 declarations
  SNumbers: set of integer      ! Set of numbers to be checked
  SPrime: set of integer        ! Set of prime numbers
 end-declarations

 SNumbers:={2..LIMIT} 
 
 writeln("Prime numbers between 2 and ", LIMIT, ":")

 n:=2
 repeat
   while (not(n in SNumbers)) n+=1
   SPrime += {n}                ! n is a prime number
   i:=n
   while (i<=LIMIT) do          ! Remove n and all its multiples
     SNumbers-= {i}
     i+=n
   end-do
 until SNumbers={}    
 
 writeln(SPrime)
 writeln(" (", getsize(SPrime), " prime numbers.)")
 
end-model

(!

Debugging
=========
Use the following command sequence in the Mosel command line:

mosel debug prime2.mos 'LIMIT=50'
break 31
bcond 1-1 getsize(SNumbers) < 10
cont
print n
display SNumbers
display SPrime
cont
quit


Profiling
=========
Use the following command in the Mosel command line:

mosel profile prime2.mos 'LIMIT=50'

Obtain information about memory usage:

mosel debug prime2.mos
info SPrime
lsmods
quit

!)

prime3.mos
(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file prime3.mos 
   ```````````````
   Prime number algorithm for large values of LIMIT.
 
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, 2006
*******************************************************!)

model "Prime (array)"

 parameters
  LIMIT=20000                   ! Search for prime numbers in 2..LIMIT
 end-parameters

 declarations
  INumbers = 2..LIMIT           ! Set of numbers to be checked
  SNumbers: array(INumbers) of boolean   
  SPrime: set of integer        ! Set of prime numbers
 end-declarations

 writeln("Prime numbers between 2 and ", LIMIT, ":")

 n:=2
 repeat
   SPrime += {n}                ! n is a prime number
   i:=n
   while (i<=LIMIT) do          ! Remove n and all its multiples
     SNumbers(i):= true
     i+=n
   end-do
   while (n <= LIMIT and SNumbers(n)) n+=1
 until (n>LIMIT)   
 
 writeln(SPrime)
 writeln(" (", getsize(SPrime), " prime numbers.)")
 
end-model

runprime2d.mos
(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file runprime2d.mos 
   ```````````````````
   Model handling.
   - Using the parallel debugger -
 
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, 2005, rev. Jul. 2014
*******************************************************!)

model "Run model prime"
 uses "mmjobs"

 parameters
  LIMIT=20000                  ! Search for prime numbers in 2..LIMIT
 end-parameters

 declarations
  modPrime: Model
  event: Event
 end-declarations
                               ! Compile 'prime2d.mos' in debug mode
 if compile("G","prime2d.mos")<>0 then exit(1); end-if

 load(modPrime, "prime2d.bim") ! Load bim file

 run(modPrime, "LIMIT="+LIMIT) ! Start execution and
 wait                          ! wait for an event

                               ! An event is available: submodel finished
 event:=getnextevent
 writeln("Exit status: ", getvalue(event))
 writeln("Exit code  : ", getexitcode(modPrime))

 unload(modPrime)              ! Unload the submodel
end-model 

(!

Debugging
=========
Use the following command sequence in the Mosel command line:

mosel debug runprime2d.mos LIMIT=50
break 29
cont
next
model 2
break 34
bcond 2-1 getsize(SNumbers) < 10
cont
print n
display SNumbers
display SPrime
cont
quit

!)

prime2d.mos
(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file prime2d.mos 
   ````````````````
   Working with sets.
   -- Debugging and profiling --
 
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, 2001, rev. Jul. 2014
*******************************************************!)

model Prime 
 uses "mmsystem"

 parameters
  LIMIT=20000                   ! Search for prime numbers in 2..LIMIT
 end-parameters

 declarations
  SNumbers: set of integer      ! Set of numbers to be checked
  SPrime: set of integer        ! Set of prime numbers
 end-declarations

 sleep(5000)                    ! Leave some time to enter debugging statements

 SNumbers:={2..LIMIT} 
 
 writeln("Prime numbers between 2 and ", LIMIT, ":")

 n:=2
 repeat
   while (not(n in SNumbers)) n+=1
   SPrime += {n}                ! n is a prime number
   i:=n
   while (i<=LIMIT) do          ! Remove n and all its multiples
     SNumbers-= {i}
     i+=n
   end-do
 until SNumbers={}    
 
 writeln(SPrime)
 writeln(" (", getsize(SPrime), " prime numbers.)")
 
end-model

(!

Debugging
=========
Use the following command sequence in the Mosel command line:

mosel debug prime2d.mos 'LIMIT=50'
break 34
bcond 1-1 getsize(SNumbers) < 10
cont
print n
display SNumbers
display SPrime
cont
quit


Profiling
=========
Use the following command in the Mosel command line:

mosel profile prime2.mos 'LIMIT=50'

Obtain information about memory usage:

mosel debug prime2.mos
info SPrime
lsmods
quit

!)

© 2001-2020 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.