module demo; import java.io.*; import java.util.*; /* Trap.salsa -- Parallel Trapezoidal Rule * * Input: Optinal. a and b, the left and right endpoints of the integral.n the number of trapezoids. * Output: Estimate of the integral from a to b of f(x) * using the trapezoidal rule and n trapezoids. * * Algorithm: * 1. Each actor calculates "its" interval of * integration. * 2. Each actor estimates the integral of f(x) * over its interval using the trapezoidal rule. * 3a. Each actor sends its results to the main actor. * 3b. The main actor sums the calculations received from * the individual actors and prints the result. * * Note: f(x) is hardwired. * */ behavior Trap{ int noActors = 2; // The number of actors double a = 0.0; // Left endpoint double b = 1.0; // Right endpoint int n = 1024; // Number of trapezoids long initialTime; // Starting Time String nameServer = "jupiter.wcl.cs.rpi.edu"; // Name Server String theatersFile = "theatersFile.txt"; // File containing the theaters void act(String args[]){ int argc = args.length; if(argc>=1) a=Double.valueOf(args[0]).doubleValue(); if(argc>=2) b=Double.valueOf(args[1]).doubleValue(); if(argc>=3) n=Integer.parseInt(args[2]); if(argc>=4) noActors=Integer.parseInt(args[3]); if(argc>=5) nameServer=args[4]; if(argc>=6) theatersFile = args[5]; DistributeWork()@displayResults(token)@endTimer(); } double[ ][ ] DistributeWork(){ Double h = new Double((b-a)/n); // Trapezoid base length Integer local_n = new Integer((int) (n/noActors)); // Number of trapezoids for Double local_a; // Left endpoint my process Double local_b; // Right endpoint my process //create actors and assign data TrapWorker[] workers = new TrapWorker[noActors]; for (int i=0; i>>>>>Starting the computation"); initialTime = System.currentTimeMillis(); join{ for (int i=0;i