📄 pi_impl.java
字号:
/**
*
* Program : Pi_Impl.java (Example Application Program)
*
* Author : Vijayakrishnan Menon
*
* Date : 20th Feb 2006
*
* Organization : Centre for Excellence in Computational Engineering and Networking (CEN)
* Amrita Viswa Vidyapeetham
*
**/
package JAMPack;
/** This is how an ideal user task should be written. The purpose of this program is
* to demostrate the use of the frame work by a commen end user. Though the package
* is not full fledged, it will under go additions in future and better versions will
* be released. The basic template will remain same. Additions will mainly be in the
* IPC services offered, and also in the network abstraction modules, that facilitate
* communications through the concept of Virtual organizations. Extragrids can also
* be realised inthe upcoming versions through SOAP-XML services and HTTP-tunelling. */
class Pi implements Task {
public void runTask(int rank, int size, JGrid grid) {
System.out.println("*********************************************************************");
System.out.println("Sample Pi program to demostrate JAMPack Grid Runtime 1.5");
double sum=0,U,L,x,range =0.0000001,buff=0;
Comm comm = new JComm();
L = (double)rank/(double)size;
U = (double)(rank + 1)/(double)size;
for(x = L;x<=U;x+=range) sum += (4.00/(1.00+x*x))*range;
System.out.println("Node "+rank+" calculated value :"+sum);
try {
if(rank==0)
{
if(size>1) {
for(int i=1;i<size;i++) {
buff = comm.receive(buff,i,grid,1);
sum += buff;
}
}
System.out.println("Value of Pi: "+sum);
}
else
{
comm.send(sum,0,grid,1);
System.out.println("Sending to node zero....");
}
}catch(Exception e) {e.printStackTrace();}
System.out.println("*********************************************************************");
}
}
public class Pi_Impl {
public static void main(String args[]) throws Exception
{
String []hosts = {"192.168.11.83","192.168.8.141","192.168.10.206","192.168.8.113","192.168.8.228"};
JScheduler scheduler = JScheduler.getInstance(hosts);
Task task = JBootStrap.getBootStrapedTask("JAMPack.Pi");
JScheduler.post(task,2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -