private void SendPartialProblemToNode(Problem problem, ComputationalNode computationalNode, int problemIndex) { SolvePartialProblems partialProblem = new SolvePartialProblems() { CommonData = problem.Data, Id = problem.Id, ProblemType = problem.ProblemType, SolvingTimeoutSpecified = problem.timeoutSpecified, PartialProblems = new SolvePartialProblemsPartialProblem[1] { new SolvePartialProblemsPartialProblem() { TaskId = problem.problems[problemIndex].TaskId, Data = problem.problems[problemIndex].Data } } }; if (problem.timeoutSpecified) { partialProblem.SolvingTimeout = problem.solvingTimeout; } Send(SerializeMessage(partialProblem), computationalNode.state.m_socket); }
private ulong RegisterComponent(Register _registerMessage, ComponentObject _state) { ulong newComponentId = 0; switch (_registerMessage.Type) { case RegisterType.ComputationalNode: ComputationalNode computationalNode = new ComputationalNode() { lastStatus = DateTime.Now, statusThreads = new StatusThread[_registerMessage.ParallelThreads], solvableProblems = _registerMessage.SolvableProblems, state = _state }; // for (int i = 0; i < computationalNode.statusThreads.Length; i++) // { computationalNode.statusThreads[0] = new StatusThread() { TaskIdSpecified = false, ProblemInstanceIdSpecified = false, ProblemType = "", State = StatusThreadState.Idle, HowLong = 0 }; // } m_memoryLock.WaitOne(); newComponentId = computationalNode.Id = m_componentId++; m_nodes.Add(computationalNode); m_memoryLock.Release(); break; case RegisterType.TaskManager: TaskManager taskManager = new TaskManager() { lastStatus = DateTime.Now, statusThreads = new StatusThread[_registerMessage.ParallelThreads], solvableProblems = _registerMessage.SolvableProblems, state = _state }; // for (int i = 0; i < taskManager.statusThreads.Length; i++) // { taskManager.statusThreads[0] = new StatusThread() { TaskIdSpecified = false, ProblemInstanceIdSpecified = false, ProblemType = "", State = StatusThreadState.Idle, HowLong = 0 }; //} m_memoryLock.WaitOne(); newComponentId = taskManager.Id = m_componentId++; m_managers.Add(taskManager); m_memoryLock.Release(); break; } return(newComponentId); }
static void Main(string[] args) { Console.WriteLine("Run as:\n1 Task Manager\n2 Computational Node\n3 Computational Client"); string choise = Console.ReadLine(); switch (choise[0]) { case '1': TaskManager tm = new TaskManager(); Console.WriteLine("TASK MANAGER:"); tm.Start(); Console.ReadKey(); break; case '2': ComputationalNode c = new ComputationalNode(); Console.WriteLine("COMPUTATIONAL NODE:"); c.Start(); Console.ReadKey(); break; case '3': ComputationalClient computationalClient = new ComputationalClient(); Console.WriteLine("COMPUTATIONAL CLIENT:"); computationalClient.Start(); break; default: Console.WriteLine(choise[0] + " is not an option"); break; } //ComputationalNode c = new ComputationalNode(); //Console.WriteLine("NODE:"); //Console.ReadKey(); //c.RegisterComponent(); //Console.ReadKey(); // while (true) // { // c.ReceivePartialProblem(); // } // Console.WriteLine("Otrzymano odpowiedź {0} ", Encoding.ASCII.GetString(c.Receive())); // Console.ReadKey(); }