[Company Logo Image]    

Home Feedback Contents Search

4.5 OOP
4.1 Structure 4.2 Compiling 4.3 Example 4.4 Socket 4.5 OOP 4.6 Competing 4.7 Optimization 4.8 Connector 4.9 Merging 4.10 Emulation 4.11 Ordered Calls 4.12 Last-Only 4.13 Group Inputs 4.14 Complex Sys. 4.15 Prior Art... 4.16 Redundant SW 4.17 Visual SW 

Back Home Up Next

4.5 Object-Oriented Example

const int n=100

//----------------------------------------------------

struct Array

{  type Data[n];  

   socket void all_done();

   //-----

   detach

   {  int total_count;

      void done_item()

      {  ++total_count;

         if ( total_count==n )

            all_done();

         return;

      };

      void zero_count()

      {  total_count=0;

      }; 

   };

   //-----

   detach void add_item(int i, type& A, type& B)

   {  return;

      C[i] = A[i]+B[i]; //Time consuming operation     

      done_item();

   };

   //-----

   detach void add_arrays(Array& A, Array& B)

   {  zero_count();

      for ( int i=0; i<n; i++ )

          add_item(i,A.Data,B.Data);

      void all_done()

      {

      };

   };

};

FIG. 5: An example of object-oriented stress-flow code

The examples above used globally defined data and routines and therefore were not an object-oriented samples of code. Apart from lesser clarity, that program would not be able to add two separate sets of tables at the same time. A proper object-oriented version of the same programming example is shown on FIG. 5. Data and operations on it are defined as part of one structure/class/object. Stress-flow adds parallelism elegantly to it. All previously described atoms are now member functions, including our entry-point “add_arays.”

A fundamental principle of stress-flow is generating internal locks together with each detach function or detach block, in this case of member functions the locks will be inserted as invisible member variables. This simple principle is all that was necessary to create object-oriented parallel programming using stress-flow. Our example results in several automatically compiler-generated locks – now all these locks become part of every instance of object Array. Separate instances of Array can process themselves in parallel because they have all necessary synchronization mechanisms automatically replicated.

All object-oriented rules of variable/function location and scope apply to automatic generation of the stress-atom locks. Member stress-flow atoms have member locks. Static stress-flow atoms have static locks. This is as natural from object-oriented standpoint as possible. Please note that important part here is the definition scope of the lock – and not necessarily the location. If a computer was built completely according to the concepts of stress-flow, the locks could even be implemented and allocated in special hardware. What this would mean as far as translation of object oriented code would be that locks corresponding to class member functions would be replicated for each instance while those corresponding to global or static functions would not.

Back Home Up Next
Send mail to info@stressflow.com with questions or comments.
Copyright © 2005-2010. All Rights Reserved. Patents Pending in Multiple Jurisdictions.
First published 03/29/06. Last modified: 06/25/10