From: Shaman <shaman@kki.net.pl>
Newsgroups: comp.sys.transputer
Subject: Small job - occam2 - english comments & variable names
Date: Mon, 14 Jun 1999 08:20:05 +0200
Organization: Politechnika Slaska, Gliwice
Message-Id: <37649F15.79420903@kki.net.pl>
References: <37609EB2.1478E59C@kki.net.pl>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Xref: ukc comp.sys.transputer:9168


Shaman wrote:
 
 Hello :-)
 I think I need your help.
 I have to written small prog. in occam language implementation
 sorting by collation. I done this, but my teacher maintain this
 is incorrect, but he don't want to help me correct this.
 
 Would you help me? I attached my source.
 foundation: 4 processors, array is partitioning and each of
 processor sorting themselves part of array and send back to
 another (one of them) process who collapting it.
 
 PS. sorry for my english - I'm still learning ;-)


 #INCLUDE "hostio.inc"
 
 PROC main (CHAN OF SP fs, ts)
 
   #USE "hostio.lib"  -- iservers library
 
   VAL NPROC IS 4:       -- number of working process
   VAL MAX_SIZE IS 100:  -- size of array to be sorted
   [MAX_SIZE]INT tab:    -- array to bo sorted
   [MAX_SIZE]INT t_tmp:  -- temporary array
   INT el:
   INT part:
 
   SEQ
     part = MAX_SIZE \ NPROC
     -- loading table
     SEQ i = 0 FOR MAX_SIZE
       SEQ
         so.read.int(fs, ts, el, 0)
         tab[i] = el
 
     -- buble sorting (I don't know correct english name)
     -- each processor sorting his own part of array
     -- to be problem sollution right each process should
     -- receive part of array by chanel and resend this after
     -- sorted it. :-( I don't know to do it
 
     PAR i = 0 FOR NPROC
      BYTE rob
      BYTE left
      BYTE right
      SEQ
        -- setting range of array which will be sorting by i-proc.
        left  = i * part
        right = left + part - 1
        SEQ j = left FOR (right - left) -- = for j = left to right - 1
          SEQ k = j + 1 FOR prawy - j   -- = for k = j+1 to right
            SEQ
              IF
               tab[k] < tab[j]
                  rob  = tab[k]
                  tab[k] = tab[j]
                  tab[j] = rob
                TRUE
                  SKIP
     --
     -- collapting
     -- variables for collapting

     BYTE left
     BYTE middle
     BYTE right
     BYTE counter1
     BYTE counter2
     BYTE index
     --
     SEQ i = 1 FOR NPROC-1
       SEQ
         index = 0 -- index in t_tmp array
         left = 0
         middle = (i * part)
         right = middle + part - 1
         counter1 = left
         counter2 = middle
         SEQ
           WHILE counter1 < middle
             SEQ
               IF
                 tab[counter1] < tab[counter2] --warunek
                   t_tmp[index] = tab[counter1]
                   index = index + 1
                   counter1 = counter1 + 1
                   IF
                     counter >= middle
                       SEQ j = counter2 FOR (right - counter2 + 1) 
                         SEQ
                           t_tmp[index] = tab[j]
                           index  = index + 1
                     TRUE
                       SKIP
                 tab[counter1] >= tab[counter2] --warunek
                   t_tmp[index] = tab[counter2]
                   index  = index + 1
                   counter2 = counter2 + 1
                   IF
                     counter2 > right
                       SEQ j = counter1 FOR (middle - counter1) 
                         SEQ
                           t_tmp[index] = tab[j]
                           index  = index + 1
                           counter1 = middle -- end
                     TRUE
                       SKIP
           
           -- rewriting temporrary array to main array
           SEQ j = 0 FOR index 
             SEQ
               tab[j] = t_tmp[j]
 
     -- show contents of array
     SEQ i = 0 FOR MAX_SIZE
       SEQ
         so.write.int(fs, ts, tab[i], 0)
         so.exit(fs, ts, sps.success)

 --
 Greetings
 Shaman
 shaman@kki.net.pl

