| 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
!)
 | 
| 
 |