1. 程式人生 > >平行計算框架JPPF3.3.4試用

平行計算框架JPPF3.3.4試用

先說一個挺有意思的事情,就在OneCoder準備記錄試用過程的時候,給大家截圖下載頁面的時候,發現最新版本變成3.3.4了。於是,我也只好重新下載了:)

想要執行JPPF平行計算任務,需要至少一個Node節點(執行任務的節點),一個driver節點(排程任務的節點),和本地呼叫節點

依次分別執行driver包裡的startDriver.bat和node包裡的startNode.bat啟動driver和node
 

然後,開發jppf應用,JPPF在application-template包中提供了任務模版,只需參照文件稍作修改即可:

 public static void
main(String args[]) { TaskFlowOne taskOne = new TaskFlowOne(); try { // create the JPPFClient. This constructor call causes JPPF to read // the configuration file // and connect with one or multiple JPPF drivers. jppfClient
= new JPPFClient(); // create a JPPF job JPPFJob job = new JPPFJob(); // give this job a readable unique id that we can use to monitor and // manage it. job.setName( "Template Job Id"); // add a task to the job.
job.addTask(taskOne); job.setBlocking( true); // Submit the job and wait until the results are returned. // The results are returned as a list of JPPFTask instances, // in the same order as the one in which the tasks where initially // added the job. List<JPPFTask> results = jppfClient.submit(job); JPPFTask jTask = results.get(0); System. out.println(jTask.getResult()); // process the results TaskFlowTwo taskTwo = new TaskFlowTwo(); job.addTask(taskTwo); job.setBlocking( true); List<JPPFTask> resultsTow = jppfClient.submit(job); JPPFTask jTaskTow = resultsTow.get(1); System. out.println(jTaskTow.getResult()); } catch (Exception e) { e.printStackTrace(); } finally { if ( jppfClient != null) jppfClient.close(); } }

一個平行計算的任務,就是一個JPPFJob,每個job含有多個task,task之間是並行執行的,如果有多個nod節點,會按照其負載均衡策略分配到多個node上執行。通過client提交(submit)job後,會返回執行結果,為一個JPPFTask列表,列表裡包含你add到job中每個task及其執行結果,作為後續計算處理之用。任務呼叫支援阻塞和非阻塞。

admin-ui中還提供了對節點狀態和資源佔用,任務資訊等監控,總體來說上手很快,很好用: