It\'s for parallel programming 1st Lab Exercise for Chapter 7-Load Balancing Usi
ID: 3866986 • Letter: I
Question
It's for parallel programming 1st Lab Exercise for Chapter 7-Load Balancing Using the Pipeline Structure This programming exercise is from the textbook Problem 7-2 in Page 225 Write a parallel Program that will implement the load-balancing technique using the pipeline structure described in Section 7.2.3 for any arbitrary set of independent arithmetic tasks. Please follow the following guidelines in writing your program: 1. Make Process O generate a set of tokens (e.g., integers). Process 0 doesn't participate in task processing. Instead, it passes tokens alone to pipeline to other processes, and print a message when the program is terminating. The number of tokens must be several times larger than the number of processes. 2. Use the structure in Figure 7.7 and the codes in Page 209 to organize your coding. Make each process sleep for 1 second when it takes a "task" to process, i.e, pulling out a token from the buffer to process. 3. When the program terminates, each process prints a message showing its rank and the number of "tasks" it has processes. 4. Process 0 sends a termination token to other processes when all tokens have been sent out. Each process terminates when it receives the termination token and has finished all "tasks" from the local buffer. 5. Demonstrate your program on the due date.Explanation / Answer
Here is the coding section as per the given condition, Please go through it thoroughly:-
using System;
using Eneter.Messaging.MessagingSystems.MessagingSystemBase;
using Eneter.Messaging.MessagingSystems.TcpMessagingSystem;
using Eneter.Messaging.Nodes.LoadBalancer;
namespace LoadBalancer
{
class Program
{
static void Main(string[] args)
{
// Create TCP messaging for the communication with the client
// and with services performing requests.
IMessagingSystemFactory aMessaging = new TcpMessagingSystemFactory();
// Create load balancer.
// It receives requests from the client and forwards them to available services
// to balance the workload.
ILoadBalancerFactory aLoadBalancerFactory= new RoundRobinBalancerFactory(aMessaging);
ILoadBalancer aLoadBalancer= aLoadBalancerFactory.CreateLoadBalancer();
// Addresses of available services.
string[] anAvailableServices = {"tcp://127.0.0.1:8071/", "tcp://127.0.0.1:8072/", "tcp://127.0.0.1:8073/" };
// Add IP addresses of services to the load balancer.
foreach (string anIpAddress in anAvailableServices)
{
aLoadBalancer.AddDuplexOutputChannel(anIpAddress);
}
// Create input channel that will listen to requests from clients.
IDuplexInputChannel anInputChannel= aMessaging.CreateDuplexInputChannel("tcp://127.0.0.1:8060/");
// Attach the input channel to the load balancer and start listening.
aLoadBalancer.AttachDuplexInputChannel(anInputChannel);
Console.WriteLine("Load Balancer is running. Press ENTER to stop.");
Console.ReadLine();
// Stop lisening.
aLoadBalancer.DetachDuplexInputChannel();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.