+ Reply to Thread
Results 1 to 1 of 1

Thread: Writing ASP.NET code as a Symphony DE client

  1. #1
    Young's Avatar
    Young is offline Junior Member
    Join Date
    March 5th, 2008
    Location
    Toronto, Canada
    Posts
    58
    Blog Entries
    1
    Downloads
    7
    Uploads
    0

    Default Writing ASP.NET code as a Symphony DE client

    ASP.NET code can be written in C# and Symphony API to act as a client to the Symphony DE service written in Java, C++ or C# API

    1. Getting prepared
    You need to have your project of ASP.NET Web Application to refer to Symphony .NET API assembly file correctly as follows, in order to use Symphony .NET API:
    (1) From the Solution Explorer, right click on Reference
    (2) Slect "Add Reference"
    (3) Browse to %SOAM_HOME%\4.0\win32-vc7\lib
    (4) Select "Platform.Symphony.Soam.Net.dll"

    2. Writing a workload submission webform.
    (1) Add a new webform with .aspx extension.



    (2) Design your webform.
    In the example shown below, users can specify number of tasks and total number of simulations, e.g. Monte Carlo.


    (3) Implement workload submission code in your UI event. For example, you can create a button ("Run Simulation" button shown above) to send tasks. On button click event, you can initialize API, add code to create connection, session, tasks and send your tasks to the Symphony service as shown in the sample snippet of code below.

    Code:
    override protected void OnInit(EventArgs e)
    {
        //
        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
        //
        InitializeComponent();
        base.OnInit(e);
        // Initialize the Symphony API
        SoamFactory.Initialize();
    }
    		
        /// <summary>
        /// Required method for Designer support - do not modify	
        /// the contents of this method with the code editor.
        /// </summary>		
    private void InitializeComponent()
    {    
                this.NumTasksBox.TextChanged += new System.EventHandler(this.TextBox1_TextChanged);
                this.RunButton.Click += new System.EventHandler(this.RunButton_Click);
                this.Load += new System.EventHandler(this.Page_Load);
    
    }
    #endregion
    
    private void RunButton_Click(object sender, System.EventArgs e)
    {
        string tasks = NumTasksBox.Text;
        string simulation = NumSimsBox.Text;
        try
        {
            // Set up application specific information to be supplied to Symphony
            String applicationName = "SymphonyWebapplication";
    
            // Set up application authentication information using
            // the default security provider
            DefaultSecurityCallback securityCb = new
            DefaultSecurityCallback("Guest", "Guest");
    
            Connection connection = null;
            try
            {
                 // Connect to the specified application
                 connection = SoamFactory.Connect(applicationName, securityCb);
                    
                 // Retrieve and print our connection ID
                 Console.WriteLine("connection ID: " + connection.Id );
                 Session session = null;
                 try
                 {
                     // Set up session attributes
                     SessionCreationAttributes attributes = new SessionCreationAttributes();
                     attributes.SessionName = "mySession";
                     attributes.SessionType = "ShortRunningTasks";
                     attributes.SessionFlags = SessionFlags.AliasSync;
    
                     // Create a synchronous session
                     session = connection.CreateSession(attributes);
    
                     // Retrieve and print session ID
                     Console.WriteLine("Session ID: " + session.Id);
    
                     // Now we will send some messages to our service 
                     int numTasksToSend = int.Parse(tasks); 
    
                     Console.WriteLine (numTasksToSend);
                            
                     double totalSimulations = double.Parse(simulation);
                     Console.WriteLine (totalSimulations);
                     double numberOfSimulationsPerTask = totalSimulations / numTasksToSend; 
    
                     for (int taskCount = 0; taskCount < numTasksToSend; taskCount++) 
                     { 
                         // Create a message 
                         MyMessage myInput = new MyMessage(); 
                         myInput.numberOfSimulations = numberOfSimulationsPerTask;
    
                         // Set task submission attributes 
                         TaskSubmissionAttributes taskAttr = new TaskSubmissionAttributes(); 
                         taskAttr.SetTaskInput(myInput); 
                         TaskInputHandle input = session.SendTaskInput(taskAttr); 
                                
                       } 
                       // Continue your logic of retrieving the simulation result from service
                       . . . . . . 
                       . . . . . .
    
    3. Interaction with Symphony service
    Symphony service on the compute host is an executable that can be written in C++, Java or C#. The Service Instance Manager (SIM) will spawn it and then communicate with it via a TCP socket.
    The client code via the Symphony client library sends tasks to the Session Manager (SSM) that in turn distributes tasks to SIMs on the compute hosts.
    Last edited by Young; March 14th, 2008 at 09:16 PM.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts