mpj-v0_38/0000775000000000000000000000000011706605647011215 5ustar rootrootmpj-v0_38/README0000664000000000000000000000557211514103605012066 0ustar rootroot QuickStart Guide: Running MPJ Express on UNIX/Linux/Mac platform Last Updated: Fri Jan 14 12:11:47 EST 2011 Version 0.38 Introduction ============ MPJ Express is a reference implementation of the mpiJava 1.2 API, which is an MPI-like API for Java defined by the Java Grande forum. MPJ Express can be configured in two ways: 1. Multicore Configuration: This configuration is used by developers who want to execute their parallel Java applications on multicore or shared memory machines (laptops and desktops). 2. Cluster Configuration: This configuration is used by developers who want to execute their parallel Java applications on distributed memory platforms including clusters and network of computers. This document contains steps to help you execute your first MPJ Express program on UNIX/Linux/Mac platforms. Windows users should consult README-win.txt. Pre-requisites ============== 1. Java 1.5 (stable) or higher 2. Apache ant 1.6.2 or higher (Optional) 3. Perl (Optional) Running MPJ Express Programs in the Multicore Configuration =========================================================== 1. Download MPJ Express and unpack it. 2. Set MPJ_HOME and PATH environmental variables: export MPJ_HOME=/path/to/mpj/ export PATH=$PATH:$MPJ_HOME/bin (These above two lines can be added to ~/.bashrc) 3. Write your MPJ Express program (HelloWorld.java) and save it. 4. Compile: javac -cp .:$MPJ_HOME/lib/mpj.jar HelloWorld.java 5. Execute: mpjrun.sh -np 4 HelloWorld Running MPJ Express Programs in the Cluster Configuration ========================================================= 1. Download MPJ Express and unpack it. 2. Set MPJ_HOME and PATH environmental variables: export MPJ_HOME=/path/to/mpj/ export PATH=$PATH:$MPJ_HOME/bin (These above two lines can be added to ~/.bashrc) 3. Write your MPJ Express program (HelloWorld.java) and save it. 4. Write a machines file (name it "machines") stating host names or IP addresses of all machines involved in the parallel execution. 5. Start daemons: mpjboot machines 6. Compile: javac -cp .:$MPJ_HOME/lib/mpj.jar HelloWorld.java 7. Execute: mpjrun.sh -np 4 -dev niodev HelloWorld 8. Stop daemons: mpjhalt machines Additional Documentation ======================== For more details, see $MPJ_HOME/doc/linuxguide.pdf Contact and Support =================== In case you run into issues please consult $MPJ_HOME/doc/linuxguide.pdf. If your query/problem is still not resolved, contact us by emailing: 1. MPJ mailing list: http://www.lists.rdg.ac.uk/mailman/listinfo/mpj-user 2. Aamir Shafi (aamir.shafi@seecs.edu.pk) 3. Bryan Carpenter (bryan.carpenter@port.ac.uk) 4. Mark Baker (http://acet.rdg.ac.uk/~mab) 5. Guillermo Lopez Taboada (http://www.des.udc.es/~gltaboada) mpj-v0_38/src/0000775000000000000000000000000011514104227011765 5ustar rootrootmpj-v0_38/src/mpjdev/0000775000000000000000000000000011514104252013250 5ustar rootrootmpj-v0_38/src/mpjdev/MPJDevException.java0000775000000000000000000000343611004030775017072 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Aamir Shafi (2005 - 2008) 3. Bryan Carpenter (2005 - 2008) 4. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : MPJDevException.java * Author : Aamir Shafi, Bryan Carpenter * Created : Sat Oct 9 12:22:15 BST 2004 * Revision : $Revision: 1.3 $ * Updated : $Date: 2005/07/29 14:03:10 $ * */ package mpjdev; import xdev.XDevException; public class MPJDevException extends XDevException { public MPJDevException() { super(); } public MPJDevException(Throwable cause) { super(cause); } public MPJDevException(String s) { super(s); } } mpj-v0_38/src/mpjdev/MPJDev.java0000664000000000000000000001024611306135403015204 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2010 1. Distributed Systems Group, University of Portsmouth (2005) 2. Aamir Shafi (2005 - 2010) 3. Bryan Carpenter (2005 - 2010) 4. Mark Baker (2005 - 2010) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : MPJDev.java * Author : Aamir Shafi, Bryan Carpenter * Created : Mon Nov 1 12:22:15 BST 2004 * Revision : $Revision: 1.12 $ * Updated : $Date: 2005/12/05 11:58:20 $ * */ package mpjdev; import xdev.Device; import xdev.ProcessID; import org.apache.log4j.Logger ; public class MPJDev { public static Comm WORLD = null; static Device dev = null; static Logger logger = Logger.getLogger( "mpj" ); public static Device init(String args[]) throws MPJDevException { if (args.length < 3) { throw new MPJDevException("Usage: " + "java MPJDev " +"conf_file can be, ../conf/xdev.conf " +"OR http://holly.dsg.port.ac.uk:15000/xdev.conf "); } /* we want multiple threads to see the same object */ synchronized (MPJDev.class) { if (dev == null) { //dev = Device.newInstance(args[2]); String device = args[2]; if (device.equals("niodev")) { dev = new xdev.niodev.NIODevice(); } else if (device.equals("mxdev")) { dev = new xdev.mxdev.MXDevice(); } else if (device.equals("smpdev")) { dev = new xdev.smpdev.SMPDevice(); } else { throw new MPJDevException("No matching device found for <" + dev + ">"); } } } if (dev == null) { System.out.println("Specified device: " + args[2]); System.out.println("Available devices, niodev, smpdev, gmdev"); System.out.println("Error, cant execute, correct the device first"); return dev ; } ProcessID[] ids = dev.init(args); ProcessID myID = dev.id(); int myRank = -1; for(int i=0 ; i"); //System.out.println("r=<"+r+">"); if(w.reqs[i] == r) { //System.out.println("setting the index "); w.index = i; } if(w.reqs[i] != null) { w.reqs[i].waitany = null; } } waitanyQue.remove(w); return w; } /* * invoke all completion handlers in order they were * defined */ protected void complete(mpjdev.Status status) { Iterator iter = list.iterator(); CompletionHandler handler = null; while (iter.hasNext()) { handler = (CompletionHandler) iter.next(); handler.handleCompletion(status); } } /* * add handler (logically) to the end of a list */ public void addCompletionHandler(mpjdev.CompletionHandler handler) { list.add(handler); } } mpj-v0_38/src/mpjdev/Comm.java0000664000000000000000000010677711312066045015033 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Aamir Shafi (2005 - 2008) 3. Bryan Carpenter (2005 - 2008) 4. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : Comm.java * Author : Aamir Shafi, Bryan Carpenter * Created : Thu Apr 9 12:22:15 BST 2004 * Revision : $Revision: 1.17 $ * Updated : $Date: 2005/12/21 13:18:17 $ * */ package mpjdev; import xdev.Device; import mpjbuf.Buffer; import mpjbuf.Type ; import mpjbuf.NIOBuffer ; import mpjbuf.BufferFactory ; import xdev.ProcessID; import java.util.UUID; import java.util.Random; import mpi.MPI; public class Comm { Device device = null; public int sendctxt = 0; public int recvctxt = 0; int collctxt = 0; public Group group = null; public Group localgroup = null; int calContextTag = (34*1000)+20 ; int mpjdevBarrierTag = (34*1000)+21 ; int splitTag = (34*1000)+22 ; int bCount = 1000; static int staticContext = 2; /** * constructor used for MPJDev.WORLD intracomm. * how will coll. operations use different contexts ? */ Comm(xdev.Device device, Group group) throws MPJDevException { this.device = device; this.group = group; int highestContext = -1; int nextContext = 0; synchronized(Comm.class) { nextContext = ++staticContext ; } try { highestContext = calculateContext(10, false, nextContext); } catch (Exception e) { throw new MPJDevException ( e ); } sendctxt = highestContext; recvctxt = highestContext; collctxt = highestContext + (2 * highestContext); //collctxt = highestContext + (2 * highestContext); } /** * This method creates intercommunicator. Actually, the code may * suggest that this is a very complex function, but the truth is, * i don't have broadcast, reduce like functions at mpjdev level, which * makes this method look difficult ..the implementation. Anyway, * * There is a local leader, and a remote leader. There's a concept of * peer comm for creating intercommunicator. The peer comm is actually * the communicator, that allows the two leaders to communicate * their groups information with each other. The local leader, * sends the ranks of all of its members (these ranks are w.r.t peer comm) * to remote leader. The local leader then receives the ranks of all * processes from remote-leader. These ranks are used by local leader * to find out ProcessID, and thus create a remotegroup object that would * represent the remote group. This remote group is required because in * all communications using intercomm, the user will use the ranks * of processes in remote groups. So once localleader, and remote leader * have exchanged information, and created group objects representing * remote groups, they need to broadcast this 'set of ranks' to all * processes within their intracommunicator. Once this info. is broadcasted * , then all processes create group objects. Once this group creation * stufff is done, now its time to agree on contexts ... * * Both the intracommunictors (of which localleader, and remoteleader are * members) broadcast in order to calculate context, and once each group * has agreed on the contexts, localleaders and remoteleaders share * this information. If this context is not same, then intercomm is created, * if they are same, then i do some plus/minuses to agree on something * that is unique ..you may see this in the code ....i don't know how * to explain it in words. */ //if (peergroup.ids[localleader].uuid().equals( // peergroup.myID.uuid())) { Comm(xdev.Device device, Group localgroup, Group peergroup, int localleader, int remoteleader, int tag, int peercontext, int context) throws MPJDevException { mpjdev.Request req = null; // added by me int value = 5 ; int me = peergroup.rank(); //System.out.println("--- intercomm constructor ---"+me ); //System.out.println(" peercontext (comm_world) "+peercontext); //System.out.println(" context (local_comm)"+context); this.device = device; this.localgroup = localgroup; int sendOverhead = MPJDev.getSendOverhead() ; int recvOverhead = MPJDev.getRecvOverhead() ; int capacity = sendOverhead + 23; Buffer sbuf = new Buffer(BufferFactory.create(capacity), sendOverhead ,capacity ); Buffer rbuf = new Buffer(BufferFactory.create(capacity), recvOverhead , 16+recvOverhead ); int[] intdata = new int[1]; if (localgroup.ids[localleader].uuid().equals( localgroup.myID.uuid())) { //System.out.println("local leader ..."+me); intdata[0] = localgroup.size(); //System.out.println(me +"sending size of localgrp to remoteleader " // +intdata[0]); try { sbuf.putSectionHeader(Type.INT); sbuf.write(intdata, 0, 1); sbuf.commit(); System.out.println("sending ..") ; req = device.isend(sbuf, peergroup.ids[remoteleader], tag, peercontext); // added by me } catch(Exception e ) { throw new MPJDevException ( e ); } mpjdev.Request []localgroupreq = new mpjdev.Request[localgroup.size()] ; mpjbuf.Buffer wBuffer [] = new mpjbuf.Buffer[localgroup.size()] ; for (int i = 0; i < localgroup.size(); i++) { int prank = 0; for (int j = 0; j < peergroup.size(); j++) { if (localgroup.ids[i].uuid().equals( peergroup.ids[j].uuid())) { prank = j; //peergroup.ids[j].rank(); } } //System.out.println("sending the rank(WORLD) of process"+me // +" to remote leader"+prank); intdata[0] = prank; try { wBuffer[i] = new mpjbuf.Buffer( BufferFactory.create(capacity), sendOverhead, capacity); wBuffer[i].putSectionHeader(Type.INT); wBuffer[i].write(intdata, 0, 1); wBuffer[i].commit(); // System.out.println("sending ..") ; localgroupreq[i]= device.isend(wBuffer[i], peergroup.ids[remoteleader], tag, peercontext); // added by me } catch(Exception e ){ throw new MPJDevException( e ); } } //System.out.println("now the local leader is receiving ..."+me ); device.recv(rbuf, peergroup.ids[remoteleader], tag, peercontext); //System.out.println(me + "now the local leader has received ..." // +peercontext ); try { rbuf.commit(); rbuf.getSectionHeader(); rbuf.getSectionSize() ; rbuf.read(intdata, 0, 1); // commented by me rbuf.clear(); } catch(Exception e ) { System.out.println(me +"has failed ..") ; throw new MPJDevException( e ); } req.iwait(); //Kamran: Completing isend of localleader to remote //leader try { sbuf.clear() ; } catch(Exception e ) { throw new MPJDevException( e ); } int rgroupsize = intdata[0]; ProcessID[] rids = new ProcessID[rgroupsize]; int[] rranks = new int[rgroupsize]; //System.out.println("local leader size "+rgroupsize); for (int i = 0; i < rgroupsize; i++) { try { device.recv(rbuf, peergroup.ids[remoteleader], tag, peercontext); rbuf.commit(); rbuf.getSectionHeader(); rbuf.getSectionSize() ; rbuf.read(intdata, 0, 1); rbuf.clear(); } catch(Exception e) { throw new MPJDevException( e ); } rranks[i] = intdata[0]; rids[i] = new ProcessID(peergroup.ids[rranks[i]].uuid()); //, -1); } for (int i = 0; i < localgroup.size(); i++) { localgroupreq[i].iwait() ; try { wBuffer[i].clear() ; } catch(Exception e ) { throw new MPJDevException( e ); } BufferFactory.destroy(wBuffer[i].getStaticBuffer()) ; } // done by Aamir // this.group = peergroup.incl(rranks); //check ? for (int i = 0; i < localgroup.size(); i++) { /* dont send recv to myself */ if (localgroup.ids[localleader].uuid().equals( localgroup.ids[i].uuid())) { continue; } intdata[0] = rgroupsize; try { sbuf.putSectionHeader(Type.INT); sbuf.write(intdata, 0, 1); sbuf.commit(); //System.out.println(me +"localleader sending group size to process"+i); device.send(sbuf, localgroup.ids[i], tag, context); sbuf.clear(); } catch(Exception e) { throw new MPJDevException( e ); } for (int j = 0; j < rgroupsize; j++) { intdata[0] = rranks[j]; try { sbuf.putSectionHeader(Type.INT); sbuf.write(intdata, 0, 1); sbuf.commit(); device.send(sbuf, localgroup.ids[i], tag, context); sbuf.clear(); } catch(Exception e) { throw new MPJDevException( e ); } } } } else { //System.out.println("not localleader"+ me); try { device.recv(rbuf, localgroup.ids[localleader], tag, context); rbuf.commit(); rbuf.getSectionHeader(); rbuf.getSectionSize() ; rbuf.read(intdata, 0, 1); rbuf.clear(); } catch(Exception e) { throw new MPJDevException ( e ); } int rgroupsize = intdata[0]; //System.out.println(me +"received group size from local leader " // +rgroupsize); ProcessID[] rids = new ProcessID[rgroupsize]; int[] rranks = new int[rgroupsize]; for (int i = 0; i < rgroupsize; i++) { //device.recv(rbuf, peergroup.ids[localleader], try { device.recv(rbuf, localgroup.ids[localleader], tag, context); rbuf.commit(); rbuf.getSectionHeader(); rbuf.getSectionSize() ; rbuf.read(intdata, 0, 1); rbuf.clear(); } catch(Exception e) { throw new MPJDevException( e ); } rranks[i] = intdata[0]; //System.out.println("received world rank of process"+i // +"which is,"+rranks[i]); rids[i] = new ProcessID(peergroup.ids[rranks[i]].uuid()); //, -1); } this.group = peergroup.incl(rranks); //check? //System.out.println("built non-local leader which is, "+group); } //System.out.println(" calling calculateContext"+me); int nextContext = 0 ; synchronized(Comm.class) { nextContext = (staticContext+2) ; } int hcontext = calculateContext(context, true, nextContext); //System.out.println(" called calculateContext"+me); //if (peergroup.ids[localleader].uuid().equals( // peergroup.myID.uuid())) if (localgroup.ids[localleader].uuid().equals( localgroup.myID.uuid())) { intdata[0] = hcontext; try { sbuf.putSectionHeader(Type.INT); sbuf.write(intdata, 0, 1); sbuf.commit(); req = device.isend(sbuf, peergroup.ids[remoteleader], tag, peercontext); device.recv(rbuf, peergroup.ids[remoteleader], tag, peercontext); rbuf.commit(); rbuf.getSectionHeader(); rbuf.getSectionSize() ; rbuf.read(intdata, 0, 1); rbuf.clear(); req.iwait() ; sbuf.clear(); } catch(Exception e) { throw new MPJDevException( e ); } int rhcontext = intdata[0]; if (hcontext == rhcontext) { // if both group's highest context is same, then we need some sort // of conflict resolution approahc. The way current i am doing it is // by passing remoteleaders rank to each other. These are ranks in // some communicator like WORLD ..and cannot be equal ... int peersRemoteLeader = 0 ; try { sbuf.putSectionHeader(Type.INT); intdata[0] = remoteleader ; sbuf.write(intdata, 0, 1); sbuf.commit(); req = device.isend(sbuf, peergroup.ids[remoteleader], tag, peercontext); device.recv(rbuf, peergroup.ids[remoteleader], tag, peercontext); rbuf.commit(); rbuf.getSectionHeader(); rbuf.getSectionSize() ; rbuf.read(intdata, 0, 1); rbuf.clear(); req.iwait() ; sbuf.clear(); peersRemoteLeader = intdata[0] ; } catch(Exception e) { throw new MPJDevException( e ); } /* get on with it ...doesnt matter */ //sendctxt = hcontext; //recvctxt = rhcontext; if (peersRemoteLeader > remoteleader) { //System.out.println(" localleader > remoteleader "); sendctxt = hcontext ; //+1; // localleader; recvctxt = hcontext -1; // localleader; } else { //System.out.println(" remoteleader > localleader "); sendctxt = hcontext-1 ; //-1 ;//localleader; //remoteleader; recvctxt = hcontext ; //1 localleader; //remoteleader; } } else { sendctxt = hcontext; recvctxt = rhcontext; } //System.out.println("context selected (leader)"+sendctxt); //System.out.println("context selected (leader)"+recvctxt); for (int i = 0; i < localgroup.size(); i++) { /* dont send recv to myself */ //if (peergroup.ids[localleader].uuid().equals( // localgroup.ids[i].uuid())) if (localgroup.ids[localleader].uuid().equals( localgroup.ids[i].uuid())) { continue; } intdata[0] = sendctxt; try { sbuf.putSectionHeader(Type.INT); sbuf.write(intdata, 0, 1); sbuf.commit(); //System.out.println("localleader sending contexts to process "+i); device.send(sbuf, localgroup.ids[i], tag, context); sbuf.clear(); } catch(Exception e) { throw new MPJDevException( e ); } intdata[0] = recvctxt; try { sbuf.putSectionHeader(Type.INT); sbuf.write(intdata, 0, 1); sbuf.commit(); //System.out.println("localleader sending contexts to process "+i); device.send(sbuf, localgroup.ids[i], tag, context); sbuf.clear(); } catch(Exception e) { throw new MPJDevException ( e) ; } } } else { //device.recv(rbuf, peergroup.ids[localleader], try { device.recv(rbuf, localgroup.ids[localleader], tag, context); rbuf.commit(); rbuf.getSectionHeader(); rbuf.getSectionSize() ; rbuf.read(intdata, 0, 1); rbuf.clear(); sendctxt = intdata[0]; //device.recv(rbuf, peergroup.ids[localleader], device.recv(rbuf, localgroup.ids[localleader], tag, context); rbuf.commit(); rbuf.getSectionHeader(); rbuf.getSectionSize() ; rbuf.read(intdata, 0, 1); rbuf.clear(); } catch(Exception e) { throw new MPJDevException ( e ); } recvctxt = intdata[0]; //System.out.println("context selected (non-leader)"+sendctxt); //System.out.println("context selected (non-leader)"+recvctxt); } collctxt = -1; // intercomms dont need one. //System.out.println(" finished "+me); //System.out.println(" sendctxt "+sendctxt); //System.out.println(" recvctxt "+recvctxt); BufferFactory.destroy(rbuf.getStaticBuffer()) ; BufferFactory.destroy(sbuf.getStaticBuffer()) ; //for(i =0 ; i starting to send"); int[] contextArray = new int[1]; contextArray[0] = nextContext ; //(new Random()).nextInt(1024); int i; mpjdev.Request[] req = new mpjdev.Request[mySize]; int sendOverhead = MPJDev.getSendOverhead () ; int recvOverhead = MPJDev.getRecvOverhead () ; int cap = sendOverhead+23; //FIXME: What's this magic number? mpjbuf.Buffer wBuffer [] = new mpjbuf.Buffer[mySize] ; for (i = 0; i < mySize; i++) { if (i == myRank) { continue; } //System.out.println("process <"+group.rank()+"> sending to <"+i ); try { wBuffer[i] = new mpjbuf.Buffer( BufferFactory.create(cap), sendOverhead, cap); wBuffer[i].putSectionHeader(mpjbuf.Type.INT); wBuffer[i].write(contextArray, 0, 1); wBuffer[i].commit(); req[i] = device.isend(wBuffer[i], ids[i], (calContextTag+i), context); } catch(Exception e) { throw new MPJDevException( e ); } //System.out.println("process <"+group.rank()+"> sent to "+i ); } mpjbuf.Buffer rBuffer = new mpjbuf.Buffer( BufferFactory.create(recvOverhead+16), recvOverhead , recvOverhead+16); //FIXME: What's this magic number? int highestContext = contextArray[0]; for (i = 0; i < mySize; i++) { if (i == myRank) { continue; } try { //System.out.println("rank<"+myRank+"> recving from"+i); device.recv(rBuffer, ids[i], (calContextTag+myRank), context); //System.out.println("rank<"+myRank+"> recved from"+i); rBuffer.commit(); Type type = rBuffer.getSectionHeader(); rBuffer.getSectionSize() ; rBuffer.read(contextArray, 0, 1); rBuffer.clear(); } catch (Exception e) { throw new MPJDevException ( e ); } if (contextArray[0] > highestContext) { highestContext = contextArray[0]; } } //System.out.println("rank<"+myRank+"> recv completed "); //System.out.println("rank<"+myRank+"> is last loop"); for (i = 0; i < mySize; i++) { if (i == myRank) { continue; } req[i].iwait(); try { wBuffer[i].clear(); } catch(Exception e) { e.printStackTrace() ; } } for(i =0 ; i= this.size() && src != -2) { throw new MPJDevException("In Comm.iprobe(), requested source " + src + " does not exist in communicator of size " + this.size()); } ProcessID srcID = null; if (src == MPI.ANY_SOURCE) { srcID = xdev.Device.ANY_SRC; } else { srcID = group.ids[src]; } Status status = device.probe(srcID, tag, recvctxt); /* This loop is trying to find the matching receive */ for (int j = 0; j < group.ids.length; j++) { if (group.ids[j].uuid().equals(status.srcID)) { status.source = j; break; } } return status; } public Status iprobe(int src, int tag) throws MPJDevException { if (src < 0 && src != -2) { throw new MPJDevException( "In Comm.iprobe(), requested negative message destination: " + src); } else if (src >= this.size() && src != -2) { throw new MPJDevException("In Comm.iprobe(), requested source " + src + " does not exist in communicator of size " + this.size()); } ProcessID srcID = null; if (src == MPI.ANY_SOURCE) { srcID = xdev.Device.ANY_SRC; } else { srcID = group.ids[src]; } Status status = device.iprobe(srcID, tag, recvctxt); if(status != null) { /* This loop is trying to find the matching receive */ for (int j = 0; j < group.ids.length; j++) { if (group.ids[j].uuid().equals(status.srcID)) { status.source = j; break; } } } return status; } public Request irecv(mpjbuf.Buffer buf, int src, int tag, mpjdev.Status status, boolean pt2pt) throws MPJDevException { if (buf == null) { throw new MPJDevException("In Comm.irecv(), buffer is null."); } if (src < 0 && src != -2) { throw new MPJDevException( "In Comm.irecv(), requested negative message destination: " + src); } else if (src >= this.size() && src != -2) { throw new MPJDevException("In Comm.irecv(), requested source " + src + " does not exist in communicator of size " + this.size()); } int context = 0; if (pt2pt) { context = recvctxt; } else { context = collctxt; } ProcessID srcID = null; if (src == MPI.ANY_SOURCE) { srcID = xdev.Device.ANY_SRC; } else { srcID = group.ids[src]; } Request request = device.irecv(buf, srcID, tag, context, status); request.addCompletionHandler(new mpjdev.CompletionHandler() { public void handleCompletion(mpjdev.Status status) { /* This loop is trying to find the matching receive */ for (int j = 0; j < group.ids.length; j++) { if (group.ids[j].uuid().equals(status.srcID)) { status.source = j; break; } } } }); return request; } public Status recv(mpjbuf.Buffer buf, int src, int tag, boolean pt2pt) throws MPJDevException { if (buf == null) { throw new MPJDevException("In Comm.irecv(), buffer is null."); } if (src < 0 && src != -2) { throw new MPJDevException( "In Comm.irecv(), requested negative message destination: " + src); } else if (src >= this.size() && src != -2) { throw new MPJDevException("In Comm.irecv(), requested source " + src + " does not exist in communicator of size " + this.size()); } int context = 0; mpjdev.Status status = null; if (pt2pt) { context = recvctxt; } else { context = collctxt; } ProcessID srcID = null; if (src == MPI.ANY_SOURCE) { srcID = xdev.Device.ANY_SRC; } else { srcID = group.ids[src]; } status = device.recv(buf, srcID, tag, context); /* This loop is trying to find the matching receive */ for (int j = 0; j < group.ids.length; j++) { if (group.ids[j].uuid().equals(status.srcID)) { status.source = j; break; } } return status; } public void barrier() throws MPJDevException { if (this.localgroup != null) { System.out.println("mpjdev_barrier cannot be called for intercomm"); return; } bCount++; int size = this.group.size(); int rank = this.group.rank(); int stuff[] = new int[1]; int x = 1; int y = (int) Math.pow(2d, Math.floor(Math.log(size) / Math.log(2))); int sendOverhead = MPJDev.getSendOverhead() ; int cap = sendOverhead + 23; mpjbuf.Buffer wBuffer = new mpjbuf.Buffer(BufferFactory.create(cap), sendOverhead, cap); mpjbuf.Buffer rBuffer = new mpjbuf.Buffer(BufferFactory.create(16), 0, 16); try { wBuffer.putSectionHeader(mpjbuf.Type.INT); wBuffer.write(stuff, 0, 1); wBuffer.commit(); }catch(Exception e) { throw new MPJDevException( e ); } if (rank >= y) { //send(rank-y,(-176+rank-y+bCount)); try { send(wBuffer, rank-y, ( ( mpjdevBarrierTag+rank-y) * bCount), false); recv(rBuffer, rank-y, ( ( mpjdevBarrierTag+rank) * bCount), false); rBuffer.clear(); } catch(Exception e) { throw new MPJDevException ( e ); } } else { if ( (size - y) > rank) { try { recv(rBuffer, rank + y, ((mpjdevBarrierTag+rank) * bCount), false); rBuffer.clear(); } catch(Exception e) { throw new MPJDevException( e ); } } int round = -1; int peer = 0; do { round = round + 1; peer = rank ^ (int) Math.pow(2d, round); try { send(wBuffer, peer, ( (mpjdevBarrierTag+peer) * bCount), false); recv(rBuffer, peer, ( (mpjdevBarrierTag+rank) * bCount), false); rBuffer.clear(); } catch(Exception e) { throw new MPJDevException( e ); } } while (round != ( (int) (Math.log(y) / Math.log(2)) - 1)); if ( (size - y) > rank) { //Send(stuff,0,1,MPI.INT,rank+y,(-176+rank+y+bCount)); try { send(wBuffer, rank + y, ((mpjdevBarrierTag+rank+y) * bCount), false); } catch(Exception e) { throw new MPJDevException( e ); } } } if (bCount == Integer.MAX_VALUE - 1) { bCount = 1000; } BufferFactory.destroy(wBuffer.getStaticBuffer()) ; BufferFactory.destroy(rBuffer.getStaticBuffer()) ; } public Request isend(mpjbuf.Buffer buf, int dest, int tag, boolean pt2pt) throws MPJDevException { if (buf == null) { throw new MPJDevException("In Comm.isend(), buffer is null."); } if (dest < 0) { throw new MPJDevException( "In Comm.isend(), requested negative message destination: " + dest); } else if (dest >= size()) { throw new MPJDevException("In Comm.isend(), requested destination " + dest + " does not exist in communicator of size " + size()); } int context = 0; if (pt2pt) { context = sendctxt; } else { context = collctxt; } //is status important here? .. .. .. return device.isend(buf, group.ids[dest], tag, context); } public void send(mpjbuf.Buffer buf, int dest, int tag, boolean pt2pt) throws MPJDevException { if (buf == null) { throw new MPJDevException("In Comm.isend(), buffer is null."); } if (dest < 0) { throw new MPJDevException( "In Comm.isend(), requested negative message destination: " + dest); } else if (dest >= size()) { throw new MPJDevException("In Comm.isend(), requested destination " + dest + " does not exist in communicator of size " + size()); } int context = 0; //System.out.println(" sendctxt (send) mpjdev "+sendctxt); //System.out.println(" recvctxt (send) mpjdev "+recvctxt); if (pt2pt) { context = sendctxt; } else { context = collctxt; } device.send(buf, group.ids[dest], tag, context); } public Request issend(mpjbuf.Buffer buf, int dest, int tag, boolean pt2pt) throws MPJDevException { if (buf == null) { throw new MPJDevException("In Comm.isend(), buffer is null."); } if (dest < 0) { throw new MPJDevException( "In Comm.isend(), requested negative message destination: " + dest); } else if (dest >= size()) { throw new MPJDevException("In Comm.isend(), requested destination " + dest + " does not exist in communicator of size " + size()); } int context = 0; if (pt2pt) { context = sendctxt; } else { context = collctxt; } // again is status important here ..we can define a completion // handler here if it is .. return device.issend(buf, group.ids[dest], tag, context); } public void ssend(mpjbuf.Buffer buf, int dest, int tag, boolean pt2pt) throws MPJDevException { if (buf == null) { throw new MPJDevException("In Comm.isend(), buffer is null."); } if (dest < 0) { throw new MPJDevException( "In Comm.isend(), requested negative message destination: " + dest); } else if (dest >= size()) { throw new MPJDevException("In Comm.isend(), requested destination " + dest + " does not exist in communicator of size " + size()); } int context = 0; if (pt2pt) { context = sendctxt; } else { context = collctxt; } device.ssend(buf, group.ids[dest], tag, context); } public int size() { return this.group.size(); } public int id() { //System.out.println(" this.group.rank() <"+this.group.rank()+">"); return this.group.rank(); } public void free() throws MPJDevException { //cleaning up resources ... } /* all processes with same color would be form one sub-group ... all processes send their color and key to all other processes ... all processes receive color and key from all other processes ... now classify how many colors you've ... assign ranks depending on keys ...lower the key, lower the new rank .. but if the keys are same ..still its not a problem ..its my responsibility to assigning new ascending ranks to each process ... */ public Comm split(int color, int key) throws MPJDevException { int[][] b = new int[group.size()][3]; int len = 0; int a[] = new int[2]; a[0] = color; a[1] = key; b[len][0] = color; b[len][1] = key; b[len][2] = group.rank(); len++; int size = group.size(); int rank = group.rank(); int tag = splitTag ; int sOverhead = MPJDev.getSendOverhead() ; int cap = sOverhead + 23; Buffer buf = new Buffer(BufferFactory.create(cap), sOverhead, cap); try { buf.putSectionHeader(Type.INT); buf.write(a, 0, 2); buf.commit(); } catch(Exception e) { throw new MPJDevException( e ); } mpjdev.Request[] reqs = new mpjdev.Request[size]; /* send to all processes */ for (int i = 0; i < size; i++) { if (i == rank)continue; reqs[i] = isend(buf, i, rank + tag + i, false); } try { buf.clear(); } catch(Exception e) { throw new MPJDevException( e ); } Buffer rbuf = new Buffer(BufferFactory.create(16), 0, 16); /* now receive from all other processes */ for (int i = 0; i < size; i++) { if (i == rank)continue; //System.out.print("p<"+rank+"> receving from <"+i+">"); try { recv(rbuf, i, tag + i + rank, false); rbuf.commit(); rbuf.getSectionHeader(); rbuf.getSectionSize() ; rbuf.read(a, 0, 2); rbuf.clear(); } catch(Exception e) { throw new MPJDevException( e ); } if (a[0] == color) { b[len][0] = a[0]; b[len][1] = a[1]; b[len][2] = i; len++; } } /* complete send operation */ for (int i = 0; i < size; i++) { if (i == rank)continue; reqs[i].iwait(); } int keys[] = new int[len]; for (int i = 0; i < len; i++) { keys[i] = b[i][1]; } java.util.Arrays.sort(keys); int nids[] = new int[len]; for (int i = 0; i < len; i++) { for (int j = 0; j < len; j++) { if (keys[i] == b[j][1]) nids[i] = b[j][2]; } } StringBuffer buffer = new StringBuffer(); buffer.append("rank " + rank); for (int i = 0; i < nids.length; i++) { buffer.append("nids[" + i + "]=" + nids[i]); } //if(rank == 0) //System.out.println("\n "+buffer.toString()); // System.exit(0); BufferFactory.destroy(buf.getStaticBuffer()) ; BufferFactory.destroy(rbuf.getStaticBuffer()) ; return create(nids); } } mpj-v0_38/src/mpjdev/CompletionHandler.java0000664000000000000000000000315611004030775017531 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Aamir Shafi (2005 - 2008) 3. Bryan Carpenter (2005 - 2008) 4. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : CompletionHandler.java * Author : Aamir Shafi, Bryan Carpenter * Created : Sun Dec 19 12:22:15 BST 2004 * Revision : $Revision: 1.5 $ * Updated : $Date: 2005/07/29 14:03:10 $ * */ /* *@author Aamir Shafi, Bryan Carpenter */ package mpjdev; public interface CompletionHandler { public void handleCompletion(mpjdev.Status status); } mpj-v0_38/src/mpjdev/Group.java0000775000000000000000000005016011004030775015216 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Aamir Shafi (2005 - 2008) 3. Bryan Carpenter (2005 - 2008) 4. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : Group.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Oct 15 12:22:15 BST 2004 * Revision : $Revision: 1.13 $ * Updated : $Date: 2005/11/27 19:40:12 $ * */ package mpjdev; import java.util.UUID; import xdev.ProcessID; public class Group { public ProcessID[] ids = null; public final static int NO_RANK = -1; ProcessID myID = null; int rank, size; public static final int IDENT = 0, CONGRUENT = 3, SIMILAR = 1, UNEQUAL = 2; static final int UNDEFINED = -1; //indexes of this array are ranks, remember this public Group(ProcessID[] ids, ProcessID myID, int rank) { this.ids = ids; this.size = ids.length; if (myID != null) { this.rank = rank; // myID.rank(); //this rank is index of myID on ids array ... this.myID = myID; if(!(ids[rank].uuid().equals(myID.uuid()))) { System.out.println("The group should contain itself "+ "Error in mpjdev.Group constructor "); } } else this.rank = NO_RANK; } /** * This method frees this group object. Though automatic garbage collector * will take care of it, but we mark this object for gc, by declaring it * null ... * implement at the end. */ public void free() { //this.group = null; //this = null; } /** * This method returns the size of the group. It is a count of the number * of process encapsulated by this group object. * @return int The number of processes in this group */ public int size() { return this.size; } /** * This method returns the rank of the group. It is the rank (id) of the calling thread/process in this group. * @return int The rank of the callling process in this group. */ public int rank() { return this.rank; } /** * ranks1 should be a valid argument in Translate_ranks * ranks2.length = ranks1.length */ public static int[] transRanks(Group group1, int[] ranks1, Group group2) { int[] ranks2 = new int[ranks1.length]; int i, j, k; for (k = 0; k < ranks2.length; k++) { ranks2[k] = UNDEFINED ; } ProcessID[] ids1 = group1.ids; int size1 = group1.size; ProcessID[] ids2 = group2.ids; int size2 = group2.size; UUID temp1 = null, temp2 = null; for (i = 0; i < ranks1.length; i++) { temp1 = ids1[i].uuid(); for (j = 0; j < size2; j++) { temp2 = ids2[j].uuid(); if (temp1.equals(temp2)) { ranks2[i] = j; //ranks2[i] = ids2[j].rank(); break; } } } return ranks2; } /** */ public static int compare(Group group1, Group group2) { /* Null will be replaced by GROUP_EMPTY */ if (group1 == null && group2 == null) { System.out.println("compare why are you comparing two null groups :( ?"); return -1; } else if (group1 == null && group2 != null) { System.out.println("compare group1 is null" + group1); return -1; } else if (group1 != null && group2 == null) { System.out.println("compare group2 is null" + group2); return -1; } else { ProcessID[] ids1 = group1.ids; ProcessID myID1 = group1.myID; int size1 = group1.size; int rank1 = group1.rank; ProcessID[] ids2 = group2.ids; ProcessID myID2 = group2.myID; int size2 = group2.size; int rank2 = group2.rank; /* debugging loop ... System.out.println("size1 "+size1); System.out.println("size2 "+size2); for(int g=0 ; g"+uuid2); for (i = 0; i < size; i++) { //System.out.println("tempids["+i+"]="+tempids[i]); //System.out.println("uids1["+i+"].uuid() "+tempids[i].uuid()); if (tempids[i].uuid().equals(uuid2)) { present = true; break; } } //its not in there, so add it if (!present) { tempids[size] = ids2[j]; //new ProcessID(ids2[j].uuid(), size); //tempids[size].rank(size); if (myID2 != null && tempids[size].uuid().equals(myID2.uuid())) { myID = tempids[size]; //new ProcessID(tempids[size].uuid(), size); //myID.rank(size); rank = size ; } size++; } present = false; } ids = new ProcessID[size]; for (j = 0; j < size; j++) ids[j] = tempids[j]; return new Group(ids, myID, rank); } } /** * */ public static Group intersection(Group group1, Group group2) { /* Null will be replaced by GROUP_EMPTY */ if (group1 == null || group2 == null) { return null; } else { ProcessID[] ids1 = group1.ids; ProcessID myID1 = group1.myID; int size1 = group1.size; int rank1 = group1.rank; ProcessID[] ids2 = group2.ids; ProcessID myID2 = group2.myID; int size2 = group2.size; int rank2 = group2.rank; ProcessID[] tempids = new ProcessID[size1 + size2], ids = null; ProcessID myID = null; int rank = NO_RANK; int size = 0; int i, j; UUID temp1, temp2; for (i = 0; i < size1; i++) { temp1 = ids1[i].uuid(); for (j = 0; j < size2; j++) { temp2 = ids2[j].uuid(); if (temp1.equals(temp2)) { //rank = size; tempids[size] = ids1[i]; //new ProcessID(temp1, rank); //tempids[size].rank(rank); if ( (myID2 != null && tempids[size].uuid().equals(myID2.uuid())) || (myID1 != null && tempids[size].uuid().equals(myID1.uuid()))) { rank = size; myID = tempids[size];//new ProcessID(tempids[size].uuid(), rank); //myID.rank(rank); } size++; break; } } } ids = new ProcessID[size]; for (j = 0; j < size; j++) ids[j] = tempids[j]; return new Group(ids, myID, rank); } } /** * Processes in group1, which are not in group2 make another grp. */ public static Group difference(Group group1, Group group2) throws MPJDevException { /* Null will be replaced by GROUP_EMPTY */ if (group1 == null && group2 == null) { return null; } else if (group1 == null && group2 != null) { return null; } else if (group1 != null && group2 == null) { ProcessID[] ids1 = group1.ids; ProcessID myID1 = group1.myID; return new Group(ids1, myID1,group1.rank); } else { ProcessID[] ids1 = group1.ids; ProcessID myID1 = group1.myID; int size1 = group1.size; int rank1 = group1.rank; ProcessID[] ids2 = group2.ids; ProcessID myID2 = group2.myID; int size2 = group2.size; int rank2 = group2.rank; ProcessID[] tempids = new ProcessID[size1], ids = null; ProcessID myID = null; int rank = NO_RANK; int size = 0; int i, j; UUID temp1 = null, temp2 = null; for (i = 0; i < size1; i++) { temp1 = ids1[i].uuid(); boolean present = false, sid = false; for (j = 0; j < size2; j++) { temp2 = ids2[j].uuid(); if (temp1.equals(temp2)) { present = true; break; } } if (!present) { tempids[size] = ids1[i]; //new ProcessID(temp1, size); //ids1[i].rank(rank); if ( (rank1 != NO_RANK && temp1.equals(myID1.uuid()))) { //|| //( rank2 != NO_RANK && temp2.equals(myID2.uuid()) ) ) { //System.out.println("\nfixing my id to " + size + "where, rank1=" + // rank1 + ",rank2" + rank2 + "\n"); myID = tempids[size]; //new ProcessID(tempids[size].uuid(), size); //myID.rank(size); rank = size; } size++; } present = false; } ids = new ProcessID[size]; for (j = 0; j < size; j++) ids[j] = tempids[j]; return new Group(ids, myID, rank); } } /** * This method returns a new group object including all the ranks specified in the argument array. * Each item of the argument array should be a valid rank in the calling group. The total number of * items in argument array should not be more than the size of the existing group. This method is a local * operation. * @param ranks Integer array specifying the ranks of the processes that will be part of the new group * @return Group The group object of the new process or null if the calling process is not in the new group. */ public Group incl(int[] ranks) throws MPJDevException { StringBuffer buffer = new StringBuffer(); /* buffer.append("rank "+rank); for(int g=0 ; g this.size) { throw new MPJDevException("Error in Group Incl method: length of "+ "array "+ranks.length+" is greater than size <"+ this.size + ">" ); } for (i = 0; i < ranks.length; i++) { if (ranks[i] > (this.size - 1) || ranks[i] < 0) { throw new MPJDevException("Error in Group Incl method: arg["+i+"] "+ "of array is bounded by [0-"+(this.size-1)+"]" ); } } ProcessID[] newIds = new ProcessID[ranks.length]; ProcessID myID = null; for (j = 0; j < ranks.length; j++) { newIds[j] = ids[ranks[j]]; //new ProcessID(ids[ranks[j]].uuid(), j); //newIds[j].rank(j); if (ranks[j] == this.rank) { myID = newIds[j]; //new ProcessID(newIds[j].uuid(), j); rank = j; //myID.rank(j); } } /* StringBuffer nbuffer = new StringBuffer(); nbuffer.append("rank "+rank); for(int g=0 ; g this.size) { throw new MPJDevException("Error in Group Excl method: length of "+ "array "+ranks.length+" is greater than size <"+ this.size + ">" ); } for (i = 0; i < ranks.length; i++) { if (ranks[i] > (this.size - 1) || ranks[i] < 0) { throw new MPJDevException("Error in Group Excl method: arg["+i+"] "+ "of array is bounded by [0-"+(this.size-1)+"]" ); } } ProcessID[] newIds = new ProcessID[this.size - ranks.length]; ProcessID myID = null; int rank = NO_RANK; int nrank = 0; boolean present = false; for (j = 0; j < this.size; j++) { for (i = 0; i < ranks.length; i++) { //if (ids[j].rank() == ranks[i]) if (j == ranks[i]) { present = true; } } if (!present) { newIds[nrank] = ids[j]; //new ProcessID(ids[j].uuid(), nrank); //newIds[nrank].rank(nrank); //if (ids[j].rank() == this.rank) { if (j == this.rank) { myID = newIds[nrank]; //new ProcessID(newIds[nrank].uuid(), nrank); rank = nrank; //myID.rank(nrank); } nrank++; } present = false; } return new Group(newIds, myID, rank); } /** */ public Group rangeIncl(int[][] ranges) throws MPJDevException { int len = ranges.length, fRank, lRank, str, i, j, k, np = 0, ranks; for (i = 0; i < len; i++) { fRank = ranges[i][0]; lRank = ranges[i][1]; str = ranges[i][2]; if (str != 0) { if ( str > 0 && fRank > lRank) { throw new MPJDevException( "Error in rangeIncl: stride <"+str+">"+ "is greater than zero and firstRank <"+fRank+ "> is greater than lastRank <"+lRank+ ">" ); } if (str < 0 && fRank < lRank) { throw new MPJDevException( "Error in rangeIncl: stride <"+str+">"+ "is less than zero and firstRank <"+fRank+ "> is less than lastRank <"+lRank+ ">" ); } if ( (ranks = ( ( (lRank - fRank) / str) + 1)) > 0) { np += ranks; } } else { throw new MPJDevException( "Error in rangeIncl: stride <"+str+">"+ "is zero"); } } if (np == 0) { throw new MPJDevException( "Error in rangeIncl: number of processes <" +np+"> to be included in new group is zero"); } int[] npp = new int[np]; //for(int l=0 ; l= 0) { npp[k] = j; k++; } } } else { throw new MPJDevException( "Error in rangeIncl: stride <"+str+">"+ "is zero"); } } return incl(npp); } /** * implemented, not sure what it does and thus not tested at the moment. */ public Group rangeExcl(int[][] ranges) throws MPJDevException { int len = ranges.length, fRank, lRank, str, i, j, k, np = 0, ranks; for (i = 0; i < len; i++) { fRank = ranges[i][0]; lRank = ranges[i][1]; str = ranges[i][2]; if (str != 0) { if ( str > 0 && fRank > lRank) { throw new MPJDevException( "Error in rangeExcl: stride <"+str+">"+ "is greater than zero and firstRank <"+fRank+ "> is greater than lastRank <"+lRank+ ">" ); } if (str < 0 && fRank < lRank) { throw new MPJDevException( "Error in rangeExcl: stride <"+str+">"+ "is less than zero and firstRank <"+fRank+ "> is less than lastRank <"+lRank+ ">" ); } if ( (ranks = ( ( (lRank - fRank) / str) + 1)) > 0) { np += ranks; } } else { throw new MPJDevException( "Error in rangeExcl: stride <"+str+">"+ "is zero"); } } if (np == 0) { throw new MPJDevException( "Error in rangeExcl: number of processes <" +np+"> to be included in new group is zero"); } k = 0; int[] npp = new int[np]; for (i = 0; i < len; i++) { fRank = ranges[i][0]; lRank = ranges[i][1]; str = ranges[i][2]; if (str != 0) { //does this start with fRank ? for (j = fRank; j * str <= lRank * str; j += str) { if (j < this.size() && j >= 0) { npp[k] = j; k++; } } } else { throw new MPJDevException( "Error in rangeExcl: stride <"+str+">"+ "is zero"); } } return excl(npp); } //implement at the end. public void finalize() throws MPJDevException { } } mpj-v0_38/src/mpjdev/Status.java0000775000000000000000000000547411004030775015415 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Aamir Shafi (2005 - 2008) 3. Bryan Carpenter (2005 - 2008) 4. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package mpjdev; import xdev.ProcessID; import java.util.UUID; /* * File : Status.java * Author : Sang Lim, Bryan Carpenter, Aamir Shafi * Created : Thu Jan 17 17:20:40 2002 * Revision : $Revision: 1.11 $ * Updated : $Date: 2005/11/27 19:40:12 $ */ /** * Status object describing a completed communication. */ public class Status { /** * For a receive operation, the source of the message. */ public int source; /** * For a receive operation, the tag in the message. */ public int tag; /** * For a `waitany()' operation in class `Request'. * This field defines which communication in the `reqs' array was selected. */ public int index; public int count; public int countInBytes ; public int numEls; public mpjbuf.Type type; public java.util.UUID srcID = null; public Status() { } public Status(UUID uid, int tag, int index) { this.srcID = uid; this.tag = tag; this.index = index; } public Status(UUID srcID, int tag, int index, mpjbuf.Type type, int numEls) { this.srcID = srcID; this.tag = tag; this.index = index; this.type = type; this.numEls = numEls; } public Status(int source, int tag, int index, mpjbuf.Type type, int numEls) { this.source = source; this.tag = tag; this.index = index; this.type = type; this.numEls = numEls; } public Status(int source, int tag, int index) { this.source = source; this.tag = tag; this.index = index; } } mpj-v0_38/src/mpi/0000775000000000000000000000000011514104252012550 5ustar rootrootmpj-v0_38/src/mpi/MultistridedPackerShort.java0000664000000000000000000001405611514104243020240 0ustar rootroot/* This file generated automatically from template MultistridedPackerType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : MultistridedPackerShort.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/07/29 14:03:09 $ */ package mpi; import mpjbuf.*; public class MultistridedPackerShort extends MultistridedPacker { public MultistridedPackerShort(int rank, int [] indexes, int extent, int size) { super(rank, indexes, extent, size); } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { mpjbuf.strGather((short []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { mpjbuf.strScatter((short []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } // In following methods, tempting to try to temporarily modify the // existing `indexes' array, to avoid temporary allocations. // But if `indexes' is not immutable we lose the ability to safely // share the datatype object across threads. public void unpackPartial(mpjbuf.Buffer mpjbuf, int length, Object buf, int offset) throws MPIException { int [] cIndexes = new int [2 * rank] ; for(int i = 0 ; i < 2 * rank ; i++) cIndexes [i] = indexes [i] ; int cubeRank = rank - 1; int cubeSize = size ; while(length > 0) { cubeSize /= indexes [cubeRank] ; // size of next smallest dimension cube. int numCubes = length / cubeSize ; // Number of whole cubes. if(numCubes > 0) { cIndexes [cubeRank] = numCubes ; int blockSize = numCubes * cubeSize ; try { mpjbuf.strScatter((short []) buf, offset, cubeRank + 1, 0, rank, cIndexes) ; } catch(Exception e) { throw new MPIException(e); } // Unpack block of cubes. offset += blockSize ; length -= blockSize ; // If cubeRank = 0, then // cubeSize = 1, blockSize = numCubes = length // => This assignment puts length to zero. } cubeRank-- ; } } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { if(count == 1) { try { mpjbuf.strGather((short []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } else { int cRank = rank + 1 ; int [] cIndexes = new int [2 * cRank] ; for(int i = 0 ; i < rank ; i++) cIndexes [i] = indexes [i] ; cIndexes [rank] = count ; for(int i = 0 ; i < rank ; i++) cIndexes [cRank + i] = indexes [rank + i] ; cIndexes [cRank + rank] = extent ; try { mpjbuf.strGather((short []) buf, offset, cRank, 0, cRank, cIndexes) ; } catch(Exception e) { throw new MPIException(e); } } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { if(count == 1) { try { mpjbuf.strScatter((short []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } else { int cRank = rank + 1 ; int [] cIndexes = new int [2 * cRank] ; for(int i = 0 ; i < rank ; i++) cIndexes [i] = indexes [i] ; cIndexes [rank] = count ; for(int i = 0 ; i < rank ; i++) cIndexes [cRank + i] = indexes [rank + i] ; cIndexes [cRank + rank] = extent ; try { mpjbuf.strScatter((short []) buf, offset, cRank, 0, cRank, cIndexes) ; }catch(Exception e) { throw new MPIException(e); } } } } mpj-v0_38/src/mpi/MinlocType.java.in0000664000000000000000000000531711004030775016113 0ustar rootroot /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : Minloc@Type@.java * Author : Aamir Shafi, Bryan Carpenter */ package mpi; import mpjbuf.*; public class Minloc@Type@ extends Minloc { @type@ [] arr = null; Minloc@Type@() { } void createInitialBuffer(Object buf) throws MPIException { @type@[] tempArray = (@type@[]) buf; arr = new @type@[tempArray.length]; } void perform(Object buf1, int offset, int count) throws MPIException { Call(buf1,0,arr,offset,count); } void getResultant(Object buf, int offset, int count) throws MPIException { @type@[] tempArray = (@type@[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } public void Call(Object invec, int inoffset, Object outvec, int outoffset, int count) throws MPIException { @type@[] arr1 = (@type@[]) invec; int indisp = inoffset; int outdisp = outoffset; for(int i=0 ; i"); } else { int numFull = length / size; for (int i = 0; i < numFull; i++) { unpack(mpjbuf, buf, offset); offset += extent ; } int residue = length - numFull * size; if (residue > 0) { unpackPartial(mpjbuf, residue, buf, offset); } } } /** * this method was not there, but putting it exactly as * pack method above offcourse changing pack to unpack. */ public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { for (int i = 0; i < count; i++) { unpack(mpjbuf, buf, offset); offset += extent; } } } mpj-v0_38/src/mpi/BorType.java.in0000664000000000000000000000440111004030775015405 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : Bor@Type@.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/08/01 22:31:40 $ */ package mpi; import mpjbuf.*; public class Bor@Type@ extends Bor { @type@ [] arr = null; Bor@Type@() { } void perform (Object buf1, Object buf2, int count) throws MPIException { @type@[] arr1 = (@type@[]) buf1; for (int i = 0; i < count; i++) { arr[i] = (@type@) (arr1[i] | arr[i]); } } void createInitialBuffer(Object buf, int offset, int count) throws MPIException { @type@[] tempArray = (@type@[]) buf; arr = new @type@[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { @type@[] tempArray = (@type@[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/BxorByte.java0000664000000000000000000000446511514104243015162 0ustar rootroot/* This file generated automatically from template BxorType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : BxorByte.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/08/01 22:31:40 $ */ package mpi; import mpjbuf.*; public class BxorByte extends Bxor { byte [] arr = null; BxorByte() { } void perform(Object buf1, Object buf2, int count) throws MPIException { byte[] arr1 = (byte[]) buf1; for (int i = 0; i < count; i++) { arr[i] = (byte) (arr1[i] ^ arr[i]); } } void createInitialBuffer(Object buf, int offset, int count) throws MPIException { byte[] tempArray = (byte[]) buf; arr = new byte[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { byte[] tempArray = (byte[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/GatherPackerType.java.in0000664000000000000000000000531611004030775017231 0ustar rootroot /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : GatherPacker@Type@.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.6 $ * Updated : $Date: 2005/07/29 14:03:09 $ */ package mpi; import mpjbuf.*; public class GatherPacker@Type@ extends GenericPacker { public int [] displacements ; public GatherPacker@Type@(int numEls, int [] displacements, int extent) { super(extent, numEls) ; this.displacements = displacements ; } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { @WRITEBUF(mpjbuf)@.gather((@type@ []) buf, size, offset, displacements) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { @READBUF(mpjbuf)@.scatter((@type@ []) buf, size, offset, displacements) ; } catch(Exception e) { throw new MPIException(e); } } public void unpackPartial(mpjbuf.Buffer mpjbuf, int length, Object buf, int offset) throws MPIException { try { @READBUF(mpjbuf)@.scatter((@type@ []) buf, size, offset, displacements) ; } catch(Exception e) { throw new MPIException(e); } } } mpj-v0_38/src/mpi/MinShort.java0000664000000000000000000000455011514104243015162 0ustar rootroot/* This file generated automatically from template MinType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : MinShort.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/08/01 22:31:40 $ */ package mpi; import mpjbuf.*; public class MinShort extends Min { short [] arr = null; MinShort() { } void perform(Object buf1, int offset, int count) throws MPIException { short[] arr1 = (short[]) buf1; for (int i = 0; i < count; i++) { if(arr1[i] < arr[i]) arr[i] = arr1[i]; } } void createInitialBuffer(Object buf, int offset, int count) throws MPIException { short[] tempArray = (short[]) buf; arr = new short[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { short[] tempArray = (short[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/MultistridedPackerObject.java0000664000000000000000000001426611514104243020352 0ustar rootroot/* This file generated automatically from template MultistridedPackerType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : MultistridedPackerObject.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/07/29 14:03:09 $ */ package mpi; import mpjbuf.*; public class MultistridedPackerObject extends MultistridedPacker { public MultistridedPackerObject(int rank, int [] indexes, int extent, int size) { super(rank, indexes, extent, size); } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { ((mpjbuf.Buffer) mpjbuf).strGather((Object []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { ((mpjbuf.Buffer) mpjbuf).strScatter((Object []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } // In following methods, tempting to try to temporarily modify the // existing `indexes' array, to avoid temporary allocations. // But if `indexes' is not immutable we lose the ability to safely // share the datatype object across threads. public void unpackPartial(mpjbuf.Buffer mpjbuf, int length, Object buf, int offset) throws MPIException { int [] cIndexes = new int [2 * rank] ; for(int i = 0 ; i < 2 * rank ; i++) cIndexes [i] = indexes [i] ; int cubeRank = rank - 1; int cubeSize = size ; while(length > 0) { cubeSize /= indexes [cubeRank] ; // size of next smallest dimension cube. int numCubes = length / cubeSize ; // Number of whole cubes. if(numCubes > 0) { cIndexes [cubeRank] = numCubes ; int blockSize = numCubes * cubeSize ; try { ((mpjbuf.Buffer) mpjbuf).strScatter((Object []) buf, offset, cubeRank + 1, 0, rank, cIndexes) ; } catch(Exception e) { throw new MPIException(e); } // Unpack block of cubes. offset += blockSize ; length -= blockSize ; // If cubeRank = 0, then // cubeSize = 1, blockSize = numCubes = length // => This assignment puts length to zero. } cubeRank-- ; } } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { if(count == 1) { try { ((mpjbuf.Buffer) mpjbuf).strGather((Object []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } else { int cRank = rank + 1 ; int [] cIndexes = new int [2 * cRank] ; for(int i = 0 ; i < rank ; i++) cIndexes [i] = indexes [i] ; cIndexes [rank] = count ; for(int i = 0 ; i < rank ; i++) cIndexes [cRank + i] = indexes [rank + i] ; cIndexes [cRank + rank] = extent ; try { ((mpjbuf.Buffer) mpjbuf).strGather((Object []) buf, offset, cRank, 0, cRank, cIndexes) ; } catch(Exception e) { throw new MPIException(e); } } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { if(count == 1) { try { ((mpjbuf.Buffer) mpjbuf).strScatter((Object []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } else { int cRank = rank + 1 ; int [] cIndexes = new int [2 * cRank] ; for(int i = 0 ; i < rank ; i++) cIndexes [i] = indexes [i] ; cIndexes [rank] = count ; for(int i = 0 ; i < rank ; i++) cIndexes [cRank + i] = indexes [rank + i] ; cIndexes [cRank + rank] = extent ; try { ((mpjbuf.Buffer) mpjbuf).strScatter((Object []) buf, offset, cRank, 0, cRank, cIndexes) ; }catch(Exception e) { throw new MPIException(e); } } } } mpj-v0_38/src/mpi/LxorWorker.java0000664000000000000000000000471711004030775015544 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : LxorWorker.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.6 $ * Updated : $Date: 2005/07/29 14:03:09 $ */ package mpi; import mpjbuf.*; public class LxorWorker implements OpWorker { LxorWorker() { } public Op getWorker(Datatype datatype) throws MPIException { switch (datatype.baseType) { case Datatype.BYTE: throw new MPIException("MPI.LXOR is invalid for MPI.BYTE"); case Datatype.CHAR: throw new MPIException("MPI.LXOR is invalid for MPI.CHAR"); case Datatype.SHORT: throw new MPIException("MPI.LXOR is invalid for MPI.SHORT"); case Datatype.BOOLEAN: return new LxorBoolean(); case Datatype.INT: throw new MPIException("MPI.LXOR is invalid for MPI.INT"); case Datatype.LONG: throw new MPIException("MPI.LXOR is invalid for MPI.LONG"); case Datatype.FLOAT: throw new MPIException("MPI.LXOR is invalid for MPI.FLOAT"); case Datatype.DOUBLE: throw new MPIException("MPI.LXOR is invalid for MPI.DOUBLE"); default: return null; } } } mpj-v0_38/src/mpi/CartParms.java0000775000000000000000000000335011004030775015315 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : CartParms.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.6 $ * Updated : $Date: 2005/07/29 14:03:09 $ */ package mpi; public class CartParms { CartParms() { } public int[] dims; public boolean[] periods; public int[] coords; //coords[0] is x-axis, coords[1] is y-axis //shouldn't it just be x and y ? //public int x; //public int y; } mpj-v0_38/src/mpi/SimplePackerObject.java0000664000000000000000000000730211514104243017123 0ustar rootroot/* This file generated automatically from template SimplePackerType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : SimplePackerObject.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/07/29 14:03:10 $ */ package mpi; import mpjbuf.*; public class SimplePackerObject extends SimplePacker{ public SimplePackerObject(int numEls) { super(numEls); } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { ((mpjbuf.Buffer) mpjbuf).write((Object []) buf, offset, numEls) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { ((mpjbuf.Buffer) mpjbuf).read((Object []) buf, offset, numEls) ; } catch(Exception e) { throw new MPIException(e); } } public void unpackPartial(mpjbuf.Buffer mpjbuf, int length, Object buf, int offset) throws MPIException { try { ((mpjbuf.Buffer) mpjbuf).read((Object []) buf, offset, length) ; } catch(Exception e) { throw new MPIException(e); } } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { try { ((mpjbuf.Buffer) mpjbuf).write((Object []) buf, offset, count * numEls) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { try { ((mpjbuf.Buffer) mpjbuf).read((Object []) buf, offset, count*numEls ) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, int length, Object buf, int offset, int count) throws MPIException { if(count * numEls < length) { throw new MPIException ("Error in SimplePacker : count <"+ (count*numEls)+"> is less than length <"+length+">"); } try { ((mpjbuf.Buffer) mpjbuf).read((Object []) buf, offset, length) ; }catch(Exception e){ throw new MPIException(e); } } } mpj-v0_38/src/mpi/LorWorker.java0000664000000000000000000000464211004030775015351 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : LorWorker.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.6 $ * Updated : $Date: 2005/07/29 14:03:09 $ */ package mpi; import mpjbuf.*; public class LorWorker implements OpWorker { LorWorker() { } public Op getWorker(Datatype datatype) throws MPIException { switch (datatype.baseType) { case Datatype.BYTE: throw new MPIException(" MPI.LOR is invalid for MPI.BYTE"); case Datatype.CHAR: throw new MPIException(" MPI.LOR is invalid for MPI.CHAR"); case Datatype.SHORT: throw new MPIException(" MPI.LOR is invalid for MPI.SHORT"); case Datatype.BOOLEAN: return new LorBoolean(); case Datatype.INT: throw new MPIException(" MPI.LOR is invalid for MPI.INT"); case Datatype.LONG: throw new MPIException(" MPI.LOR is invalid for MPI.LONG"); case Datatype.FLOAT: throw new MPIException(" MPI.LOR is invalid for MPI.FLOAT"); case Datatype.DOUBLE: throw new MPIException(" MPI.LOR is invalid for MPI.DOUBLE"); default: return null; } } } mpj-v0_38/src/mpi/ProdByte.java0000664000000000000000000000452311514104243015147 0ustar rootroot/* This file generated automatically from template ProdType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : ProdByte.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/08/01 22:31:40 $ */ package mpi; import mpjbuf.*; public class ProdByte extends Prod { byte [] arr = null; ProdByte() { } void perform (Object buf1, int offset, int count) throws MPIException { byte[] arr1 = (byte[]) buf1; for (int i = 0; i < count; i++) { arr[i] = (byte) (arr1[i] * arr[i]); } } void createInitialBuffer(Object buf, int offset, int count) throws MPIException { byte[] tempArray = (byte[]) buf; arr = new byte[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { byte[] tempArray = (byte[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/Min.java0000664000000000000000000000315211004030775014141 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : Min.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.6 $ * Updated : $Date: 2005/07/29 14:03:09 $ */ package mpi; import mpjbuf.*; public class Min extends Op { Min() { worker = new MinWorker(); } } mpj-v0_38/src/mpi/MaxInt.java0000664000000000000000000000453511514104243014622 0ustar rootroot/* This file generated automatically from template MaxType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : MaxInt.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.8 $ * Updated : $Date: 2005/09/03 12:48:06 $ */ package mpi; import mpjbuf.*; public class MaxInt extends Max { int [] arr = null; MaxInt() { } void perform (Object buf1, int offset, int count) throws MPIException { int[] arr1 = (int[]) buf1; for (int i = 0+offset; i < count; i++) { if (arr1[i] > arr[i]) { arr[i] = arr1[i]; } } } void createInitialBuffer(Object buf, int offset, int count) throws MPIException { int[] tempArray = (int[]) buf; arr = new int[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { int[] tempArray = (int[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/BorShort.java0000664000000000000000000000447411514104243015166 0ustar rootroot/* This file generated automatically from template BorType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : BorShort.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/08/01 22:31:40 $ */ package mpi; import mpjbuf.*; public class BorShort extends Bor { short [] arr = null; BorShort() { } void perform (Object buf1, Object buf2, int count) throws MPIException { short[] arr1 = (short[]) buf1; for (int i = 0; i < count; i++) { arr[i] = (short) (arr1[i] | arr[i]); } } void createInitialBuffer(Object buf, int offset, int count) throws MPIException { short[] tempArray = (short[]) buf; arr = new short[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { short[] tempArray = (short[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/ProdShort.java0000664000000000000000000000453711514104243015350 0ustar rootroot/* This file generated automatically from template ProdType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : ProdShort.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/08/01 22:31:40 $ */ package mpi; import mpjbuf.*; public class ProdShort extends Prod { short [] arr = null; ProdShort() { } void perform (Object buf1, int offset, int count) throws MPIException { short[] arr1 = (short[]) buf1; for (int i = 0; i < count; i++) { arr[i] = (short) (arr1[i] * arr[i]); } } void createInitialBuffer(Object buf, int offset, int count) throws MPIException { short[] tempArray = (short[]) buf; arr = new short[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { short[] tempArray = (short[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/GatherPackerObject.java0000664000000000000000000000546211514104243017111 0ustar rootroot/* This file generated automatically from template GatherPackerType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : GatherPackerObject.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.6 $ * Updated : $Date: 2005/07/29 14:03:09 $ */ package mpi; import mpjbuf.*; public class GatherPackerObject extends GenericPacker { public int [] displacements ; public GatherPackerObject(int numEls, int [] displacements, int extent) { super(extent, numEls) ; this.displacements = displacements ; } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { ((mpjbuf.Buffer) mpjbuf).gather((Object []) buf, size, offset, displacements) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { ((mpjbuf.Buffer) mpjbuf).scatter((Object []) buf, size, offset, displacements) ; } catch(Exception e) { throw new MPIException(e); } } public void unpackPartial(mpjbuf.Buffer mpjbuf, int length, Object buf, int offset) throws MPIException { try { ((mpjbuf.Buffer) mpjbuf).scatter((Object []) buf, size, offset, displacements) ; } catch(Exception e) { throw new MPIException(e); } } } mpj-v0_38/src/mpi/Struct.java0000664000000000000000000004402011004030775014701 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : Struct.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.16 $ * Updated : $Date: 2005/08/25 10:22:07 $ */ package mpi; import mpjbuf.*; import java.nio.ByteBuffer; /** * Subclass of `Datatype' representing a derived datatype created using * `Struct()'. * createWriteBuffer doesn't write the sectionHeader because Struct datatype * may consist of various different datatypes, thus the best place to write * these section headers (and read them as well) are pack() and unpack() * methods in StructPacker class. This behaviour is only exhibited, * (writing various different kind of sections) by Struct datatype. * Thus, it has be dealt here only. This * may not be the best way of doing this, but at the mom. it looks *the best*. */ public class Struct extends Datatype { private int[] blockLengths, displacements; private Datatype[] oldTypes; private boolean unitsOfOldExtent; // true => Indexed, false => Hindexed. private boolean unitBlocks; // Case where all blocks have unit length is detected and // treated specially. private Datatype oldType; private int numBlocks; //int extent = 0; /** you want to pack multiple type of non-contigous or contigous elements. */ public Struct(int[] array_of_blocklengths, int[] array_of_displacements, Datatype[] array_of_types) throws MPIException { numBlocks = array_of_blocklengths.length; if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("\n\n--struct--"); MPI.logger.debug("numBlocks " + numBlocks); } blockLengths = new int[numBlocks]; displacements = new int[numBlocks]; oldTypes = new Datatype[numBlocks]; if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("iterating over numBlocks "); } for (int i = 0; i < numBlocks; i++) { blockLengths[i] = array_of_blocklengths[i]; displacements[i] = array_of_displacements[i]; oldTypes[i] = array_of_types[i]; if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("numBlocks[" + i + "] bkln<" + blockLengths[i] + ">,dis<" +displacements[i] + ">,otype<" + oldTypes[i] + ">"); } } // Compute base type, type size baseType = UNDEFINED; for (int i = 0; i < numBlocks; i++) { Datatype oldType = oldTypes[i]; int oldBaseType = oldType.baseType; if (oldBaseType != UNDEFINED) { if (baseType == UNDEFINED) { baseType = oldBaseType; bufferType = oldType.bufferType; } else if (oldBaseType != baseType) { /*MPIException.processMpiJavaException(MPI.ERR_TYPE, "Base types of all component types in a Struct " + "must agree.");*/ throw new MPIException( "Base types of all component types in a Struct " + "must agree"); } if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("numBlocks[" + i + "] bkln<" + blockLengths[i] + ">,dis<" + displacements[i] + ">,otype<" + oldTypes[i] + ">"); } size += blockLengths[i] * oldType.Size(); } if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("numBlocks[" + i + "] size<" + size + ">,otype<" + oldTypes[i] + ">"); MPI.logger.debug("baseType " + baseType); } } computeBounds(); if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("bufferType " + bufferType); MPI.logger.debug("after calling computeBounds"); MPI.logger.debug("extent " + extent); MPI.logger.debug("lb " + lb); MPI.logger.debug("ub " + ub); MPI.logger.debug("lbSet " + lbSet); MPI.logger.debug("ubSet " + ubSet); MPI.logger.debug( "bufferType for struct hasn't been set, "+ " and it won't work like this"); } } private void computeBounds() throws MPIException { if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("--computeBounds--"); // Compute `ub' and `lb', which define the `extent' of the new type. // Also defines `ubSet', `lbSet' for this type. ubSet = false; lbSet = false; lb = Integer.MAX_VALUE; ub = Integer.MIN_VALUE; // Because currently we don't save the true lb (ub) of old types, // following will be an upper bound (lower bound), obtained // from precursor types for which lbSet (ubSet) is false. int trueLb = Integer.MAX_VALUE; int trueUb = Integer.MIN_VALUE; extent = 0; // Follow MPICH in defining extent to be zero if // bounds are undefined (i.e. empty type). if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("initial values on computeBounds"); MPI.logger.debug("extent " + extent); MPI.logger.debug("lb " + lb); MPI.logger.debug("ub " + ub); MPI.logger.debug("lbSet " + lbSet); MPI.logger.debug("ubSet " + ubSet); MPI.logger.debug("trueLb " + trueLb); MPI.logger.debug("trueUb " + trueUb); MPI.logger.debug("--iterating over the numBlocks<" + numBlocks); } for (int i = 0; i < numBlocks; i++) { int blockLen = blockLengths[i]; if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug(" iteration<" + i + ">"); MPI.logger.debug(" blklen <" + blockLen + ">"); } if (blockLen < 0) { /*MPIException.processMpiJavaException(MPI.ERR_COUNT, "All block-lengths for Struct " + "must be non-negative.") ;*/ throw new MPIException( "All block-lengths for Struct must be non-negative"); } if (blockLen > 0) { if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("if blklen > 0"); Datatype oldtype = oldTypes[i]; int oldBaseType = oldtype.baseType; if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("getting old type" + oldtype); MPI.logger.debug("old base type" + oldBaseType); } int oldSize = oldtype.Size(); if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("old size " + oldSize); boolean oldUbSet = oldtype.ubSet; boolean oldLbSet = oldtype.lbSet; if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("oldubset " + oldUbSet); MPI.logger.debug("oldlbset" + oldLbSet); } if (oldSize != 0 || oldLbSet || oldUbSet) { if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("within oldSize != 0 or oldLbSet or oldUbSet "); } // `oldtype.ub', `oldtype.lb', `oldtype.extent' // all well-defined. int oldExtent = oldtype.Extent(); if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("oldextent" + oldExtent); } int max_ub = displacements[i] + (blockLen - 1) * oldExtent + oldtype.ub; if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("max_ub" + max_ub); } if (oldUbSet) { ubSet = true; if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("(MPI.uB) max_ub" + max_ub); MPI.logger.debug("(MPI.uB) true" + trueUb); MPI.logger.debug("(MPI.uB) ub" + ub); MPI.logger.debug("(MPI.uB) oldtype.ub" + oldtype.ub); } //aamir -- removed this if condition //if (max_ub > ub) ub = max_ub; if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("(after((MPI.uB) ub" + ub); } } else { if (max_ub > trueUb) { trueUb = max_ub; /* aamir (start) */ if (max_ub > displacements[i]) ub = max_ub; // + oldSize; else ub = displacements[i]; //+oldSize; //ub = (max_ub*displacements[i])+oldSize; //aamir + (what is epsolon here ??) //MPI.logger.debug("ub aamir "); /* aamir (end) */ } /* else { ub = displacements[i] + oldSize;//aamir }*/ } if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("trueUb" + trueUb); } int min_lb = displacements[i] + oldtype.lb; if (oldLbSet) { lbSet = true; if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("(MPI.lB) min_lb" + min_lb); MPI.logger.debug("(MPI.lB) true" + trueLb); MPI.logger.debug("(MPI.lB) lb" + lb); MPI.logger.debug("(MPI.LB) oldtype.lb" + oldtype.lb); } //aamir -- removed this if condition //if (min_lb < lb) lb = min_lb; if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug(")after((MPI.UB) lb" + lb); } } else { if (min_lb < trueLb) { trueLb = min_lb; /* aamir (start) */ if (min_lb < displacements[i]) lb = min_lb; else lb = displacements[i]; //lb = min_lb*displacements[i]; //lb = min_lb; /* aamir (end) */ } /* else lb = displacements[i];//aamir */ } if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("trueLb" + trueLb); } /* Following "correct" according to standard, but likely to cause compatibility problems with MPICH? int maxStartElement = startBlock + oldExtent > 0 ? (blockLen - 1) * oldExtent : 0 // `ubSet' acts like a most significant positive bit in // the maximization operation. if (oldUbSet == ubSet) { int max_ub = maxStartElement + oldtype.ub ; if (max_ub > ub) ub = max_ub ; } else if(oldUbSet) { ub = maxStartElement + oldtype.ub ; ubSet = true ; } int minStartElement = startBlock + oldExtent > 0 ? 0 : (blockLen - 1) * oldExtent ; // `lbSet' acts like a most significant negative bit in // the minimization operation. if (oldLbSet == lbSet) { int min_lb = minStartElement + oldtype.lb ; if (min_lb < lb) lb = min_lb ; } else if(oldLbSet) { lb = minStartElement + oldtype.lb ; lbSet = true ; } */ } } //end if blkLen > 0 if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("lb<" + lb + ">"); MPI.logger.debug("ub<" + ub + ">"); MPI.logger.debug("trueLb<" + trueLb + ">"); MPI.logger.debug("trueUb<" + trueUb + ">"); } } if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("(e)lb<" + lb + ">"); MPI.logger.debug("(e)ub<" + ub + ">"); MPI.logger.debug("(e)trueLb<" + trueLb + ">"); MPI.logger.debug("(e)trueUb<" + trueUb + ">"); } /* if(lb > trueLb) { // MPIException.processMpiJavaException(MPI.ERR_TYPE, // "Compatibility restriction: in Struct, lb defined by MPI_LB " + // "may not be higher than \"true\" lb.") ; throw new MPIException("Compatibility restriction"); } if(ub < trueUb) { // MPIException.processMpiJavaException(MPI.ERR_TYPE, // "Compatibility restriction: in Struct, ub defined by MPI_UB " + // "may not be lower than \"true\" ub.") ; // throw new MPIException("Compatibility restriction"); } */ if (lb != Integer.MAX_VALUE || ub != Integer.MIN_VALUE) extent = ub - lb; } mpjbuf.Buffer createWriteBuffer(ByteBuffer slicedBuffer, int messageSize) { return new mpjbuf.Buffer( new NIOBuffer(messageSize, slicedBuffer), MPI.BSEND_OVERHEAD , messageSize ) ; } mpjbuf.Buffer createWriteBuffer(int count) throws MPIException { int capacity = packedSize(count) +MPI.SEND_OVERHEAD ; int offset = MPI.SEND_OVERHEAD ; mpjbuf.RawBuffer rawBuffer = BufferFactory.create(capacity); mpjbuf.Buffer wBuffer = new mpjbuf.Buffer(rawBuffer, offset, capacity); try { wBuffer.putSectionHeader(this.bufferType); } catch (Exception e) { throw new MPIException(e); } return wBuffer; } mpjbuf.Buffer createReadBuffer(int count) { int capacity = packedSize(count)+ MPI.RECV_OVERHEAD ; int offset = MPI.RECV_OVERHEAD ; mpjbuf.RawBuffer rawBuffer = BufferFactory.create (capacity); mpjbuf.Buffer mpjbuf = new mpjbuf.Buffer( rawBuffer , offset, capacity) ; return mpjbuf; } int packedSize(int count) { /* calculate the size of each block, add them */ int sectionHeader = 8; //what about multiple sections. for (int i = 0; i < blockLengths.length; i++) { int blockLen = blockLengths[i]; Datatype oldtype = oldTypes[i]; int sectionSize = 0; sectionSize = (blockLen * oldtype.byteSize); // int padding = 0; // if (sectionSize % 8 != 0) // padding = sectionSize % 8; // sectionSize += padding; byteSize += sectionSize; } /* calculate the size of each block, add them */ return ((byteSize * count)+sectionHeader) ; } void setPacker() { packer = new StructPacker(); } private class StructPacker extends GenericPacker { StructPacker() { super(Struct.this.extent, Struct.this.size); //what is size ? } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { int numBlocks = displacements.length; for (int i = 0; i < numBlocks; i++) { int boffset = offset + displacements[i]; int blockLen = blockLengths[i]; Datatype oldtype = oldTypes[i]; Packer itemPacker = oldtype.getPacker(); int itemExtent = oldtype.extent; for (int j = 0; j < blockLen; j++) { itemPacker.pack(mpjbuf, buf, boffset); boffset += itemExtent; } } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { int numBlocks = displacements.length; for (int i = 0; i < numBlocks; i++) { int boffset = offset + displacements[i]; int blockLen = blockLengths[i]; Datatype oldtype = oldTypes[i]; Packer itemPacker = oldtype.getPacker(); int itemExtent = oldtype.extent; for (int j = 0; j < blockLen; j++) { itemPacker.unpack(mpjbuf, buf, boffset, itemExtent); boffset += itemExtent; } if (oldtype.bufferType == null) System.out.println("bufferType is null in createWriteBuffer"); } } public void unpackPartial(mpjbuf.Buffer mpjbuf, int length, Object buf, int offset) throws MPIException { int numBlocks = displacements.length; int residue = length; int boffset = 0; Datatype oldtype = null; //Packer itemPacker; for (int i = 0; i < numBlocks; i++) { boffset = offset + displacements[i]; int blockLen = blockLengths[i]; oldtype = oldTypes[i]; int blockSize = blockLen * oldtype.size; if (residue < blockSize)break; Packer itemPacker = oldtype.getPacker(); //just to avoid errors int itemLen = oldtype.extent; for (int j = 0; j < blockLen; j++) { itemPacker.unpack(mpjbuf, buf, boffset); boffset += itemLen; } residue -= blockSize; } // Precondition is `length < size'. // So `size > 0'. So `numBlocks > 0'. // So `boffset', `oldtype' always defined on exit from above loop. int remFull = residue / oldtype.size; for (int j = 0; j < remFull; j++) { //is this itemPacker good enough here ? Packer itemPacker = oldtype.getPacker(); //just to avoid errors int itemLen = oldtype.extent; itemPacker.unpack(mpjbuf, buf, boffset); boffset += itemLen; } residue -= remFull * oldtype.size; Packer itemPacker = oldtype.getPacker(); //jsut to avoid errors if (residue > 0) itemPacker.unpackPartial(mpjbuf, residue, buf, boffset); } } } // Things to do: // mpj-v0_38/src/mpi/Intracomm.java0000775000000000000000000020101111354712317015353 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : Intracomm.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.30 $ * Updated : $Date: 2006/10/20 17:24:47 $ */ package mpi; import mpjdev.*; import mpjbuf.*; public class Intracomm extends Comm { int bcast_tag = 35*1000 ; int nBARRIER_TAG = (34*1000)+1 ; int gatherTag = (34*1000)+2 ; int gathervTag = (34*1000)+3 ; int scatterTag = (34*1000)+4 ; int scattervTag = (34*1000)+5 ; int allgatherTag = (34*1000)+6 ; int allgathervTag = (34*1000)+7 ; int alltoallTag = (34*1000)+8 ; int alltoallvTag = (34*1000)+9; int reduceTag = (34*1000)+10; int allreduceTag = (34*1000)+11; int reducescatterTag = (34*1000)+12 ; int scanTag = (34*1000)+13 ; Intracomm() { } int bCount = 1000; ProcTree procTree = null ; /** * Constructor used to create an intracomm * @param mpjdev.Comm * The "obvious" way for allocating contexts is each process independently * increments a "next context" variable (a static variable if you like, but * local to the process). Then the processes in the group do a collective * "maxval" of the candidates, and agree to accept the largest proposal. * This is returned as the result of the collective context allocation, and * all processes also store it in the static variable they use as a starting * point next time round. This algorithm can also allocate several * consecutive contexts in a single phase, which is useful here. **/ Intracomm(mpjdev.Comm mpjdevComm, mpjdev.Group group) throws MPIException { //MPI.logger.debug("--Intracomm--"); this.mpjdevComm = mpjdevComm; this.group = new Group(group); procTree = new ProcTree(); int root = 0 ; int index = Rank() ; int extent = Size(); int places = ProcTree.PROCTREE_A * index; //MPI.logger.debug(" init places <"+places+">"); for (int i = 1; i <= ProcTree.PROCTREE_A; i++) { ++places; int ch = (ProcTree.PROCTREE_A * index) + i + root; //MPI.logger.debug("places "+places); ch %= extent; //MPI.logger.debug("ch "+ch); if (places < extent) { //MPI.logger.debug("ch <"+i+">"+"=<"+ch+">"); //MPI.logger.debug("adding to the tree at index <"+(i-1) +">\n\n"); procTree.child[i - 1] = ch; procTree.numChildren++; } else { //MPI.logger.debug("not adding to the tree"); } } //MPI.logger.debug("procTree.numChildren <"+procTree.numChildren+">"); if (index == root) { procTree.isRoot = true; //MPI.logger.debug("setting the root flag for root"); } else { procTree.isRoot = false; int pr = (index - 1) / ProcTree.PROCTREE_A; procTree.parent = pr; //MPI.logger.debug("setting parent for non-root == procTree.parent "+ // procTree.parent); } procTree.root = root; } /** * Partition the group associated with this communicator and create * a new communicator within each subgroup. *

* * * * *
color control of subset assignment
key control of rank assignment
returns: new communicator
*

* Java binding of the MPI operation MPI_COMM_SPLIT. */ public Intracomm Split(int color, int key) throws MPIException { Intracomm icomm = null; int[][] b = new int[this.group.Size()][3]; int len = 0; int a[] = new int[2], ra[] = new int[2]; a[0] = color; a[1] = key; ra[0] = 0; ra[1] = 0; b[len][0] = color; b[len][1] = key; b[len][2] = this.group.Rank(); len++; int size = this.group.Size(); int rank = this.group.Rank(); int tag = 1110; mpi.Request[] reqs = new mpi.Request[size]; /* send to all processes */ for (int i = 0; i < size; i++) { if (i == rank)continue; reqs[i] = isend(a, 0, 2, MPI.INT, i, rank + tag + i, false); } /* now receive from all other processes */ for (int i = 0; i < size; i++) { if (i == rank)continue; //MPI.out.print("p<"+rank+"> receving from <"+i+">"); recv(ra, 0, 2, MPI.INT, i, (tag + i + rank), false); if (ra[0] == color) { b[len][0] = ra[0]; b[len][1] = ra[1]; b[len][2] = i; len++; } } /* complete send operation */ for (int i = 0; i < size; i++) { if (i == rank)continue; reqs[i].Wait(); } int keys[] = new int[len]; for (int i = 0; i < len; i++) { keys[i] = b[i][1]; } java.util.Arrays.sort(keys); int nids[] = new int[len]; for (int i = 0; i < len; i++) { for (int j = 0; j < len; j++) { if (keys[i] == b[j][1]) nids[i] = b[j][2]; } } /* StringBuffer nbuffer = new StringBuffer(); nbuffer.append("rank "+rank); for(int i=0 ; i * * * *
group group which is a subset of the * group of this communicator
returns: new communicator
*

* Java binding of the MPI operation MPI_COMM_CREATE. */ public Intracomm Create(Group group) throws MPIException { mpjdev.Comm tcomm = mpjdevComm.create( group.mpjdevGroup ); return (new Intracomm(tcomm, group.mpjdevGroup)); } void nBarrier() throws MPIException { /* int index = Rank(); int root = 0; ProcTree procTree = new ProcTree(); int extent = Size(); int places = ProcTree.PROCTREE_A * index; for (int i = 1; i <= ProcTree.PROCTREE_A; i++) { ++places; int ch = (ProcTree.PROCTREE_A * index) + i + root; ch %= extent; if (places < extent) { procTree.child[i - 1] = ch; procTree.numChildren++; } } if (index == root) { procTree.isRoot = true; } else { procTree.isRoot = false; int pr = (index - 1) / ProcTree.PROCTREE_A; procTree.parent = pr; } procTree.root = root; */ int offset =0; Datatype type = MPI.INT; int[] buf = new int[1]; int count = 1; int btag = nBARRIER_TAG ; //------------------anti-bcast------------------- if (procTree.isRoot) { for (int i = 0; i < procTree.child.length; i++) { if (procTree.child[i] != -1) recv(buf, offset, count, type, procTree.child[i], btag - procTree.child[i], false); } } else { if (procTree.parent == -1) { System.out.println("non root's node parent doesn't exist"); } for (int i = 0; i < procTree.child.length; i++) { if (procTree.child[i] != -1) recv(buf, offset, count, type, procTree.child[i], btag - procTree.child[i], false); } send(buf, offset, count, type, procTree.parent, btag - Rank(), false); } //------------------bcast------------------- if (procTree.isRoot) { for (int i = 0; i < procTree.child.length; i++) { if (procTree.child[i] != -1) send(buf, offset, count, type, procTree.child[i], btag - procTree.child[i], false); } } else { if (procTree.parent == -1) { System.out.println("non root's node parent doesn't exist"); } recv(buf, offset, count, type, procTree.parent, btag - Rank(), false); for (int i = 0; i < procTree.child.length; i++) { if (procTree.child[i] != -1) send(buf, offset, count, type, procTree.child[i], btag - procTree.child[i], false); } } } void newBarrier() throws MPIException { if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("--new Barrier starts--"); } int size = Size(); int rank = Rank(); Request req = null; int stuff[] = new int[1]; int y = (int) Math.pow(2d, Math.floor(Math.log(size) / Math.log(2))); if (rank >= y) { try { req = isend(stuff, 0, 1, MPI.INT, rank - y, ( (999 + rank - y) * bCount), false); recv(stuff, 0, 1, MPI.INT, rank - y, ( (999 + rank) * bCount), false); } catch (Exception e) { e.printStackTrace(); return; } req.Wait(); } else { if ( (size - y) > rank) { try { recv(stuff, 0, 1, MPI.INT, rank + y, (999 + rank) * bCount, false); } catch (Exception e) { e.printStackTrace(); return; } } int round = -1; int peer = 0; do { round = round + 1; peer = rank ^ (int) Math.pow(2d, round); try { req = isend(stuff, 0, 1, MPI.INT, peer, (999 + peer) * bCount, false); recv(stuff, 0, 1, MPI.INT, peer, (999 + rank) * bCount, false); } catch (Exception e) { e.printStackTrace(); return; } } while (round != ( (int) (Math.log(y) / Math.log(2)) - 1)); if ( (size - y) > rank) { try { req = isend(stuff, 0, 1, MPI.INT, rank + y, (999 + rank + y) * bCount, false); } catch(Exception e) { e.printStackTrace(); return; } } } if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("--new Barrier ends--"); } private void exoticBarrier() throws MPIException { int size, rank, src, dst, mask ; size = Size() ; rank = Rank() ; byte[] barrierMsg = new byte[1] ; mask = 0x1 ; while(mask < size) { dst = (rank + mask) % size; src = (rank - mask + size) % size; sendrecv(barrierMsg, 0, 1, MPI.BYTE, dst, nBARRIER_TAG, barrierMsg, 0, 1, MPI.BYTE, src, nBARRIER_TAG) ; mask <<= 1; } } /** * Broadcast a message from the process with rank root * to all processes of the group. *

* * * * * /** * A call to Barrier blocks the caller until all process * in the group have called it. *

* Java binding of the MPI operation MPI_BARRIER. */ public void Barrier() throws MPIException { if(Size() == 1) { return ; } if(EXOTIC_BARRIER) { exoticBarrier() ; return ; } nBarrier(); //newBarrier(); /* MPI.logger.debug("--Barrier starts--"); bCount++; int size = Size(); int rank = Rank(); Request req = null; int stuff[] = new int[1]; int y = (int) Math.pow(2d, Math.floor(Math.log(size) / Math.log(2))); MPI.logger.debug("y " + y); if (rank >= y) { MPI.logger.debug("Group B"); MPI.logger.debug(" pro<" + rank + "> sending a message with tag<" + ( (999 + rank - y) * bCount) + "> to pro<" + (rank - y)); req = isend(stuff, 0, 1, MPI.INT, rank - y, ( (999 + rank - y) * bCount), false); MPI.logger.debug(" pro<" + rank + "> receiving a message with tag<" + ( (999 + rank) * bCount) + "> from pro<" + (rank - y)); try { recv(stuff, 0, 1, MPI.INT, rank - y, ( (999 + rank) * bCount), false); } catch (Exception e) { throw new MPIException( e ); } req.Wait(); } else { MPI.logger.debug("Group A"); if ( (size - y) > rank) { MPI.logger.debug("this process got partners in Group B"); MPI.logger.debug(" pro<" + rank + "> sending a message with tag<" + ( (999 + rank) * bCount) + "> to pro<" + (rank + y)); try { recv(stuff, 0, 1, MPI.INT, rank + y, (999 + rank) * bCount, false); } catch (Exception e) { throw new MPIException( e ); } } int round = -1; int peer = 0; do { round = round + 1; MPI.logger.debug("round " + round); MPI.logger.debug("round limit <" + (Math.log(y) / Math.log(2))); peer = rank ^ (int) Math.pow(2d, round); MPI.logger.debug("peer " + peer); MPI.logger.debug(" pro<" + rank + "> sending a message with tag<" + ( (999 + peer) * bCount) + "> to pro<" + peer + ">"); req = isend(stuff, 0, 1, MPI.INT, peer, (999 + peer) * bCount, false); MPI.logger.debug(" pro<" + rank + "> receiving a message with tag<" + ( (999 + rank) * bCount) + "> from pro<" + peer + ">"); try { recv(stuff, 0, 1, MPI.INT, peer, (999 + rank) * bCount, false); } catch (Exception e) { throw new MPIException( e ); } req.Wait(); } while (round != ( (int) (Math.log(y) / Math.log(2)) - 1)); if ( (size - y) > rank) { MPI.logger.debug(" pro<" + rank + "> sending a message with tag<" + ( (999 + rank + y) * bCount) + "> to pro<" + (rank + y) + ">"); req = isend(stuff, 0, 1, MPI.INT, rank + y, (999 + rank + y) * bCount, false); req.Wait(); } } if (bCount == Integer.MAX_VALUE - 1) bCount = 1000; MPI.logger.debug("--Barrier ends--"); */ } /** * Broadcast a message from the process with rank root * to all processes of the group. *

*

buf buffer array
offset initial offset in buffer
count number of items in buffer
datatype datatype of each item in * buffer
* * * * * *
buf buffer array
offset initial offset in buffer
count number of items in buffer
datatype datatype of each item in * buffer
root rank of broadcast root
*

* Java binding of the MPI operation MPI_BCST. */ public void Bcast(Object buf, int offset, int count, Datatype type, int root) throws MPIException { int index = Rank(); if (root != 0) { if (root == index) send(buf, offset, count, type, 0, bcast_tag, false); if (index == 0) recv(buf, offset, count, type, root, bcast_tag - Rank(), false); } root = 0; /* ProcTree procTree = new ProcTree(); int extent = Size(); int places = ProcTree.PROCTREE_A * index; //MPI.logger.debug(" init places <"+places+">"); for (int i = 1; i <= ProcTree.PROCTREE_A; i++) { ++places; int ch = (ProcTree.PROCTREE_A * index) + i + root; //MPI.logger.debug("places "+places); ch %= extent; //MPI.logger.debug("ch "+ch); if (places < extent) { //MPI.logger.debug("ch <"+i+">"+"=<"+ch+">"); //MPI.logger.debug("adding to the tree at index <"+(i-1) +">\n\n"); procTree.child[i - 1] = ch; procTree.numChildren++; } else { //MPI.logger.debug("not adding to the tree"); } } //MPI.logger.debug("procTree.numChildren <"+procTree.numChildren+">"); if (index == root) { procTree.isRoot = true; //MPI.logger.debug("setting the root flag for root"); } else { procTree.isRoot = false; int pr = (index - 1) / ProcTree.PROCTREE_A; procTree.parent = pr; //MPI.logger.debug("setting parent for non-root == procTree.parent "+ // procTree.parent); } procTree.root = root; //for (int i = 0; i < procTree.PROCTREE_A; i++) { //MPI.out.print(" child["+i+"]=>"+procTree.child[i]); //} //MPI.logger.debug(" ------- End --------"); //MPI.logger.debug("---Bcast---"); */ if (procTree.isRoot) { //MPI.logger.debug("This process is root"); for (int i = 0; i < procTree.child.length; i++) { //MPI.logger.debug("sending to children <"+i+">"); //MPI.logger.debug("procTree.child[i] <"+procTree.child[i]+">"); if (procTree.child[i] != -1) send(buf, offset, count, type, procTree.child[i], bcast_tag - procTree.child[i], false); //MPI.logger.debug("Sent"); } } else { if (procTree.parent == -1) { System.out.println("non root's node parent doesn't exist"); } //MPI.logger.debug("This process is not root"); //MPI.logger.debug("receiving from parent "); //MPI.logger.debug("procTree.parent <"+procTree.parent+">"); recv(buf, offset, count, type, procTree.parent, bcast_tag - Rank(), false); for (int i = 0; i < procTree.child.length; i++) { //MPI.logger.debug("sending to children <"+i+">"); //MPI.logger.debug("procTree.child[i] <"+procTree.child[i]+">"); if (procTree.child[i] != -1) send(buf, offset, count, type, procTree.child[i], bcast_tag - procTree.child[i], false); //MPI.logger.debug("Sent"); } } /* 0(N) algorithm ... if(root == Rank()) { for(int i=0;i * * * * * * * * * * *
sendbuf send buffer array
sendoffset initial offset in send buffer
sendcount number of items to send
sendtype datatype of each item in send * buffer
recvbuf receive buffer array
recvoffset initial offset in receive * buffer
recvcount number of items to receive
recvtype datatype of each item in receive * buffer
root rank of receiving process
*

* Java binding of the MPI operation MPI_GATHER. */ public void Gather(Object sendbuf, int sendoffset, int sendcount, Datatype sendtype, Object recvbuf, int recvoffset, int recvcount, Datatype recvtype, int root) throws MPIException { if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("--Gather--"); int rcount = -1, roffset = -1, soffset = -1, scount = -1; Request req = null; if (root != Rank()) { req = isend(sendbuf, sendoffset, sendcount, sendtype, root, gatherTag+Rank(), false); if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("ssent to " + root); } } else { scount = sendcount; soffset = sendoffset; } if (root == Rank()) { for (int i = 0; i < Size(); i++) { if (i != root) { if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("root " + root + " getting from " + i); recv(recvbuf, recvoffset, recvcount, recvtype, i, gatherTag + i, false); if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("root " + root + " got from " + i); } else { roffset = recvoffset; rcount = recvcount; } recvoffset += recvcount; } } if (rcount != scount) { System.out.println(" scount != rcount, should not happen"); System.out.println(" this is Reduce method"); } if (root == Rank()) { System.arraycopy(sendbuf, soffset, recvbuf, roffset, rcount); } else { req.Wait(); } if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("--Gather ends--"); } /** * Extends functionality of Gather by allowing varying * counts of data from each process. *

* * * * * * * * * * * *
sendbuf send buffer array
sendoffset initial offset in send buffer
sendcount number of items to send
sendtype datatype of each item in send * buffer
recvbuf receive buffer array
recvoffset initial offset in receive * buffer
recvcounts number of elements received from * each process
displs displacements at which to place * incoming data
recvtype datatype of each item in receive * buffer
root rank of receiving process
*

* Java binding of the MPI operation MPI_GATHERV. *

* The sizes of arrays recvcounts and displs should be the * size of the group. Entry i of displs specifies the * displacement relative to element recvoffset of recvbuf * at which to place incoming data. */ public void Gatherv(Object sendbuf, int sendoffset, int sendcount, Datatype sendtype, Object recvbuf, int recvoffset, int[] recvcount, int[] displs, Datatype recvtype, int root) throws MPIException { if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("--Gatherv--"); int rcount = -1, roffset = -1; Request req = null; if (root != Rank()) { req = isend(sendbuf, sendoffset, sendcount, sendtype, root, gathervTag+Rank(), false); if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("ssent to " + root); } if (root == Rank()) { for (int i = 0; i < Size(); i++) { if (i != root) { if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("root " + root + " getting from " + i); recv(recvbuf, recvoffset + displs[i], recvcount[i], recvtype, i, gathervTag+i, false); if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("root " + root + " got from " + i); } else { roffset = recvoffset + displs[i]; rcount = recvcount[i]; } } } if (root == Rank()) { if (rcount != sendcount) { System.out.println(" scount != rcount, should not happen"); System.out.println(" this is Reduce method"); } System.arraycopy(sendbuf, sendoffset, recvbuf, roffset, rcount); } else { req.Wait(); } if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("--Gatherv ends--"); } /** * Inverse of the operation Gather. *

* * * * * * * * * * *
sendbuf send buffer array
sendoffset initial offset in send buffer
sendcount number of items to send
sendtype datatype of each item in send * buffer
recvbuf receive buffer array
recvoffset initial offset in receive * buffer
recvcount number of items to receive
recvtype datatype of each item in receive * buffer
root rank of sending process
*

* Java binding of the MPI operation MPI_SCATTER. */ public void Scatter(Object sendbuf, int sendoffset, int sendcount, Datatype sendtype, Object recvbuf, int recvoffset, int recvcount, Datatype recvtype, int root) throws MPIException { //MPI.logger.debug("--Scatter--"); Request[] reqs = new Request[Size()]; int soffset = -1, scount = -1; if (root == Rank()) { for (int i = 0; i < Size(); i++) { if (root != i) reqs[i] = isend(sendbuf, sendoffset, sendcount, sendtype, i, scatterTag+i, false); else { soffset = sendoffset; scount = sendcount; } sendoffset += sendcount; } } if (root != Rank()) recv(recvbuf, recvoffset, recvcount, recvtype, root, scatterTag+Rank(), false); else { if (scount != recvcount) { System.out.println(" scount shuld be equal to recvcount"); } System.arraycopy(sendbuf, soffset, recvbuf, recvoffset, recvcount); } if (root == Rank()) { for (int i = 0; i < Size(); i++) { if (i != root) reqs[i].Wait(); } } //MPI.logger.debug("--Scatter ends--"); } /** * Inverse of the operation Gatherv. *

* * * * * * * * * * * *
sendbuf send buffer array
sendoffset initial offset in send buffer
sendcounts number of items sent to each * process
displs displacements from which to take * outgoing data
sendtype datatype of each item in send * buffer
recvbuf receive buffer array
recvoffset initial offset in receive * buffer
recvcount number of items to receive
recvtype datatype of each item in receive * buffer
root rank of sending process
*

* Java binding of the MPI operation MPI_SCATTERV. */ public void Scatterv(Object sendbuf, int sendoffset, int[] sendcount, int[] displs, Datatype sendtype, Object recvbuf, int recvoffset, int recvcount, Datatype recvtype, int root) throws MPIException { //MPI.logger.debug("--Scatter--"); Request[] reqs = new Request[Size()]; int soffset = -1, scount = -1; if (root == Rank()) { for (int i = 0; i < Size(); i++) { if (root != i) reqs[i] = isend(sendbuf, sendoffset + displs[i], sendcount[i], sendtype, i, scattervTag+i, false); else { soffset = sendoffset + displs[i]; scount = sendcount[i]; } } } if (root != Rank()) recv(recvbuf, recvoffset, recvcount, recvtype, root, scattervTag+Rank(), false); else { if (scount != recvcount) { System.out.println(" scount shuld be equal to recvcount"); } System.arraycopy(sendbuf, soffset, recvbuf, recvoffset, recvcount); } if (root == Rank()) { for (int i = 0; i < Size(); i++) { if (i != root) reqs[i].Wait(); } } //MPI.logger.debug("--Scatter ends--"); } /** * Similar to Gather, but all processes receive the result. *

* * * * * * * * * *
sendbuf send buffer array
sendoffset initial offset in send buffer
sendcount number of items to send
sendtype datatype of each item in send * buffer
recvbuf receive buffer array
recvoffset initial offset in receive * buffer
recvcount number of items to receive
recvtype datatype of each item in receive * buffer
*

* Java binding of the MPI operation MPI_ALLGATHER. */ public void Allgather(Object sendbuf, int sendoffset, int sendcount, Datatype sendtype, Object recvbuf, int recvoffset, int recvcount, Datatype recvtype) throws MPIException { if(EXOTIC_ALLGATHER) { int me = Rank() ; int size = Size() ; int pof2 = 1; while (pof2 < size) pof2 *= 2; if (pof2 == size) pof2 = 1; else pof2 = 0; System.arraycopy(sendbuf, sendoffset, recvbuf, recvcount*me, recvcount) ; int curr_cnt = recvcount; int mask = 0x1; int i = 0, dst ; int dst_tree_root, my_tree_root ; int send_offset, recv_offset ; int last_recv_cnt ; while(mask < size) { dst = me ^ mask ; dst_tree_root = dst >> i; dst_tree_root <<= i; my_tree_root = me >> i; my_tree_root <<= i; send_offset = my_tree_root * recvcount ; recv_offset = dst_tree_root * recvcount ; Status status = sendrecv(recvbuf,send_offset, curr_cnt, sendtype, dst, allgatherTag, recvbuf, recv_offset, recvcount*mask, recvtype, dst, allgatherTag) ; last_recv_cnt = status.Get_count(recvtype); curr_cnt += last_recv_cnt ; mask <<= 1 ; i++ ; } //end while } // end if(true) else { //MPI.logger.debug("--Allgather--"); Request req[] = new Request[Size()]; int rcount = -1, roffset = -1; for (int i = 0; i < Size(); i++) { if (i != Rank()) req[i] = isend(sendbuf, sendoffset, sendcount, sendtype, i, allgatherTag + i + Rank(), false); } for (int i = 0; i < Size(); i++) { if (i != Rank()) recv(recvbuf, recvoffset, recvcount, recvtype, i, allgatherTag + Rank() + i, false); else { rcount = recvcount; roffset = recvoffset; } recvoffset += recvcount; } //if (rcount != sendcount) { // System.out.println("rcount not equal to sendcount"); // System.out.println("this is not possible, should not happen!"); //} System.arraycopy(sendbuf, sendoffset, recvbuf, roffset, rcount); for (int i = 0; i < Size(); i++) { if (i != Rank()) req[i].Wait(); } } //MPI.logger.debug("--Allgather Ends--"); } static boolean EXOTIC_ALLGATHER = false ; static boolean EXOTIC_ALLGATHERV = false ; static boolean EXOTIC_BARRIER = false ; /** * Similar to Gatherv, but all processes receive the result. *

* * * * * * * * * * *
sendbuf send buffer array
sendoffset initial offset in send buffer
sendcount number of items to send
sendtype datatype of each item in send * buffer
recvbuf receive buffer array
recvoffset initial offset in receive * buffer
recvcounts number of elements received from * each process
displs displacements at which to place * incoming data
recvtype datatype of each item in receive * buffer
*

* Java binding of the MPI operation MPI_ALLGATHERV. */ public void Allgatherv(Object sendbuf, int sendoffset, int sendcount, Datatype sendtype, Object recvbuf, int recvoffset, int[] recvcount, int[] displs, Datatype recvtype) throws MPIException { if(EXOTIC_ALLGATHERV) { int total_count=0 ; Object tmp_buf = null ; int me = Rank() ; int size = Size() ; for(int i=0 ; i> i; dst_tree_root <<= i; my_tree_root = me >> i; my_tree_root <<= i; send_offset = 0; for (int j=0; jAllgather to the case where each process sends * distinct data to each of the receivers. *

* * * * * * * * *
sendbuf send buffer array
sendoffset initial offset in send buffer
sendcount number of items sent to each * process
sendtype datatype send buffer items
recvbuf receive buffer array
recvoffset initial offset in receive * buffer
recvcount number of items received from any * process *
recvtype datatype of receive buffer * items
*

* Java binding of the MPI operation MPI_ALLTOALL. */ public void Alltoall(Object sendbuf, int sendoffset, int sendcount, Datatype sendtype, Object recvbuf, int recvoffset, int recvcount, Datatype recvtype) throws MPIException { if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("--All to all--"); Request req[] = new Request[Size()]; int soffset = -1, scount = -1, roffset = -1, rcount = -1; for (int i = 0; i < Size(); i++) { if (i != Rank()) { if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("proc <" + Rank() + ">-sending message to proc<" + i + ">"); req[i] = isend(sendbuf, sendoffset, sendcount, sendtype, i, alltoallTag * (76 + (i + 1)), false); } else { soffset = sendoffset; scount = sendcount; } if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("soffset" + soffset); MPI.logger.debug("scount" + scount); MPI.logger.debug("process " + Rank() + "sent to process " + i); } sendoffset += sendcount; } for (int i = 0; i < Size(); i++) { if (i != Rank()) { if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("proc <" + Rank() + "> recving from proc<" + i + ">"); } recv(recvbuf, recvoffset, recvcount, recvtype, i, alltoallTag * (76 + (Rank() + 1)), false); if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("recvoffset " + recvoffset); MPI.logger.debug("recvcount " + recvcount); MPI.logger.debug("process " + Rank() + "recvd from process " + i); } } else { roffset = recvoffset; rcount = recvcount; } recvoffset += recvcount; } //copy from sendbuffer to recvbuffer ... if (scount != rcount) { System.out.println("Alltoall, rcount not equal to scount"); System.out.println("this can never happen ..."); } if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("copying the message from sendbuffer to recvbuffer"); } System.arraycopy(sendbuf, soffset, recvbuf, roffset, rcount); for (int i = 0; i < Size(); i++) { if (i == Rank()) continue; req[i].Wait(); } } /** * Adds flexibility to Alltoall: location of data for send is * specified by sdispls and location to place data on receive * side is specified by rdispls. *

* * * * * * * * * * *
sendbuf send buffer array
sendoffset initial offset in send buffer
sendcounts number of items sent to each * process
sdispls displacements from which to take * outgoing data
sendtype datatype send buffer items
recvbuf receive buffer array
recvoffset initial offset in receive * buffer
recvcounts number of elements received from * each process *
rdispls displacements at which to place * incoming data
recvtype datatype of each item in receive * buffer
*

* Java binding of the MPI operation MPI_ALLTOALLV. */ public void Alltoallv(Object sendbuf, int sendoffset, int[] sendcount, int[] sdispls, Datatype sendtype, Object recvbuf, int recvoffset, int[] recvcount, int[] rdispls, Datatype recvtype) throws MPIException { //MPI.logger.debug("--All to all--"); Request req[] = new Request[Size()]; int soffset = -1, scount = -1, roffset = -1, rcount = -1; for (int i = 0; i < Size(); i++) { if (i != Rank()) { req[i] = isend(sendbuf, sendoffset + sdispls[i], sendcount[i], sendtype, i, alltoallvTag, false); } else { soffset = sendoffset + sdispls[i]; scount = sendcount[i]; } //MPI.logger.debug("sendoffset "+sendoffset); //MPI.logger.debug("sendcount "+sendcount); //MPI.logger.debug("process "+Rank()+"sent to process "+i); } for (int i = 0; i < Size(); i++) { //MPI.logger.debug("process "+Rank()+"recving from process "+i); if (i != Rank()) { recv(recvbuf, recvoffset + rdispls[i], recvcount[i], recvtype, i, alltoallvTag, false); } else { roffset = recvoffset + rdispls[i]; rcount = recvcount[i]; } //MPI.logger.debug("recvoffset "+recvoffset); //MPI.logger.debug("recvcount "+recvcount); //MPI.logger.debug("process "+Rank()+"recvd from process "+i); } //copy from sendbuffer to recvbuffer ... if (scount != rcount) { System.out.println("Alltoall, rcount not equal to scount"); System.out.println("this can never happen ..."); } System.arraycopy(sendbuf, soffset, recvbuf, roffset, rcount); for (int i = 0; i < Size(); i++) { if (i == Rank()) continue; req[i].Wait(); } } /** * Combine elements in input buffer of each process using the reduce * operation, and return the combined value in the output buffer of the * root process. *

* * * * * * * * * *
sendbuf send buffer array
sendoffset initial offset in send buffer
recvbuf receive buffer array
recvoffset initial offset in receive * buffer
count number of items in send buffer
datatype data type of each item in send * buffer
op reduce operation
root rank of root process
*

* Java binding of the MPI operation MPI_REDUCE. *

* The predefined operations are available in Java as MPI.MAX, * MPI.MIN, MPI.SUM, MPI.PROD, MPI.LAND, * MPI.BAND, MPI.LOR, MPI.BOR, MPI.LXOR, * MPI.BXOR, MPI.MINLOC and MPI.MAXLOC. */ public void Reduce(Object sendbuf, int sendoffset, Object recvbuf, int recvoffset, int count, Datatype datatype, Op op, int root) throws MPIException { if(op.worker == null) { Request req = null; //BUG: //Object tmpbuf = sendbuf; Object tmpbuf = createTemporaryBuffer(datatype, count) ; if(root != Rank()) req = isend(sendbuf, sendoffset, count, datatype, root, reduceTag, false); else System.arraycopy(sendbuf, sendoffset, tmpbuf, sendoffset, count*datatype.size); if (Rank() == root) { for (int i = 0; i < Size(); i++) { if (i == Rank()) { continue; } recv(recvbuf, recvoffset, count, datatype, i, reduceTag, false); op.funct.Call(recvbuf, recvoffset, tmpbuf, sendoffset, count, datatype); } } if (root != Rank()) req.Wait(); System.arraycopy(tmpbuf, sendoffset, recvbuf, recvoffset, count*datatype.size); return; }//end if user_defined datatypes. /* Code for pre-defined operations */ Op op2 = op.worker.getWorker(datatype); op2.createInitialBuffer(sendbuf, sendoffset, count); Request req = null; if (root != Rank()) req = isend(sendbuf, sendoffset, count, datatype, root, reduceTag, false); //else //op2.perform(sendbuf, sendoffset, count); if (Rank() == root) { for (int i = 0; i < Size(); i++) { if (i == Rank()) { continue; } recv(recvbuf, recvoffset, count, datatype, i, reduceTag, false); op2.perform(recvbuf, recvoffset, count); } } op2.getResultant(recvbuf, recvoffset, count); if (root != Rank()) req.Wait(); } static boolean EXOTIC_ALLREDUCE = false ; /** * Same as reduce except that the result appears in receive * buffer of all process in the group. *

* * * * * * * * *
sendbuf send buffer array
sendoffset initial offset in send buffer
recvbuf receive buffer array
recvoffset initial offset in receive * buffer
count number of items in send buffer
datatype data type of each item in send * buffer
op reduce operation
*

* Java binding of the MPI operation MPI_ALLREDUCE. */ Object createTemporaryBuffer(Datatype datatype, int count) { Object tempBuffer = null ; switch (datatype.baseType) { case Datatype.UNDEFINED: System.out.println("Intracomm.createTemporaryBuffer() - "+ "UNDEFINED datatype"); break; case Datatype.NULL: System.out.println("Intracomm.createTemporaryBuffer() - "+ "NULL datatype"); break; case Datatype.BYTE: tempBuffer = new byte[count*datatype.Size()] ; break; case Datatype.CHAR: tempBuffer = new char[count*datatype.Size()] ; break; case Datatype.SHORT: tempBuffer = new short[count*datatype.Size()] ; break; case Datatype.BOOLEAN: tempBuffer = new byte[count*datatype.Size()] ; break; case Datatype.INT: tempBuffer = new int[count*datatype.Size()] ; break; case Datatype.LONG: tempBuffer = new long[count*datatype.Size()] ; break; case Datatype.FLOAT: tempBuffer = new float[count*datatype.Size()] ; break; case Datatype.DOUBLE: tempBuffer = new double[count*datatype.Size()] ; break; case Datatype.PACKED: System.out.println("Intracomm.createTemporaryBuffer() - "+ "PACKED datatype"); break; case Datatype.OBJECT: //System.out.println("Intracomm.createTemporaryBuffer() - "+ // "OBJECT datatype"); tempBuffer = new Object[count*datatype.Size()] ; break; default: System.out.println("Intracomm.createTemporaryBuffer() - "+ "default datatype"); break; } return tempBuffer ; } public void Allreduce(Object sendbuf, int sendoffset, Object recvbuf, int recvoffset, int count, Datatype datatype, Op op) throws MPIException { if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("Allreduce called"); } if(op.worker == null) { if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("User-defined ops ..but should not "+ "see this for MAXLOC "); } Request req[] = new Request[Size()]; //BUG: this is a bug, identified by Sarah Nakao //Object tmpbuf = sendbuf; Object tmpbuf = createTemporaryBuffer(datatype, count) ; for (int i = 0; i < req.length; i++) { if(i != Rank()) req[i] = isend(sendbuf, sendoffset, count, datatype, i, allreduceTag, false); else System.arraycopy(sendbuf, sendoffset, tmpbuf, sendoffset, count*datatype.size); } for (int i = 0; i < Size(); i++) { if (i != Rank()) { recv(recvbuf, recvoffset, count, datatype, i, allreduceTag, false); op.funct.Call(recvbuf, recvoffset, tmpbuf, sendoffset, count, datatype); } } for (int i = 0; i < Size(); i++) { if (i != Rank()) req[i].Wait(); } //why is it count.datatype.size ??? System.arraycopy(tmpbuf, sendoffset, recvbuf, recvoffset, count*datatype.size); return; } //end if user_defined datatypes. else { if(EXOTIC_ALLREDUCE) { Op op2 = op.worker.getWorker(datatype); op2.createInitialBuffer(sendbuf, sendoffset, count*datatype.size ); op2.getResultant(recvbuf, recvoffset, count); int mask = 0x1 ; int i=0, dst ; int me = Rank() ; int size = Size() ; while(mask < size) { dst = me ^ mask ; sendrecv(recvbuf, sendoffset, count, datatype, dst, allreduceTag, sendbuf, recvoffset, count, datatype, dst, allreduceTag) ; op2.perform(sendbuf, recvoffset, count); op2.getResultant(recvbuf, recvoffset, count); mask <<= 1; } return ; } if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("Pre defined ops"); Op op2 = op.worker.getWorker(datatype); if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("got worker"); op2.createInitialBuffer(sendbuf, sendoffset, count*datatype.size ); if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("created initial buffer "); Request req[] = new Request[Size()]; if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("sending messages "); for (int i = 0; i < req.length; i++) { if (i != Rank()) req[i] = isend(sendbuf, sendoffset, count, datatype, i, allreduceTag, false); } if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("receiving messages "); for (int i = 0; i < Size(); i++) { if (i != Rank()) { recv(recvbuf, recvoffset, count, datatype, i, allreduceTag, false); op2.perform(recvbuf, recvoffset, count); } } op2.getResultant(recvbuf, recvoffset, count); if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("got resultant .."); for (int i = 0; i < Size(); i++) { if (i != Rank()) req[i].Wait(); } if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug(" All reduce ends "); return ; } } //end Allreduce /** * Combine elements in input buffer of each process using the reduce * operation, and scatter the combined values over the output buffers * of the processes. *

* * * * * * * * *
sendbuf send buffer array
sendoffset initial offset in send buffer
recvbuf receive buffer array
recvoffset initial offset in receive * buffer
recvcounts numbers of result elements * distributed to each process
datatype data type of each item in send * buffer
op reduce operation
*

* Java binding of the MPI operation MPI_REDUCE_SCATTER. */ public void Reduce_scatter(Object sendbuf, int sendoffset, Object recvbuf, int recvoffset, int[] recvcounts, Datatype datatype, Op op) throws MPIException { int root = 0, myself = Rank(); int sendcount = 0; for (int k = 0; k < recvcounts.length; k++) { sendcount += recvcounts[k]; } Reduce(sendbuf, sendoffset, recvbuf, recvoffset, sendcount, datatype, op, root); Scatter(recvbuf, recvoffset, recvcounts[myself], datatype, recvbuf, recvoffset, recvcounts[myself], datatype, root); } /** * Perform a prefix reduction on data distributed across the group. *

* * * * * * * * *
sendbuf send buffer array
sendoffset initial offset in send buffer
recvbuf receive buffer array
recvoffset initial offset in receive * buffer
count number of items in input * buffer
datatype data type of each item in input * buffer
op reduce operation
*

* Java binding of the MPI operation MPI_SCAN. */ public void Scan(Object sendbuf, int sendoffset, Object recvbuf, int recvoffset, int count, Datatype datatype, Op op) throws MPIException { if(op.worker == null) { Request req[] = new Request[Size()]; //BUG: //Object tmpbuf = sendbuf; Object tmpbuf = createTemporaryBuffer(datatype, count) ; System.arraycopy(sendbuf, sendoffset, tmpbuf, sendoffset, count*datatype.size); for (int i = (Size() - 1); i > Rank(); i--) { req[i] = isend(sendbuf, sendoffset, count, datatype, i, scanTag , false); } for (int i = 0; i < Rank(); i++) { recv(recvbuf, recvoffset, count, datatype, i, scanTag , false); op.funct.Call(recvbuf, recvoffset, tmpbuf, sendoffset, count, datatype); } for (int i = (Size() - 1); i > Rank(); i--) { req[i].Wait(); } System.arraycopy(tmpbuf, sendoffset, recvbuf, recvoffset, count*datatype.size); return; }//end if user_defined datatypes. Op op2 = op.worker.getWorker(datatype); op2.createInitialBuffer(sendbuf , sendoffset, count); Request req[] = new Request[Size()]; //op2.perform(sendbuf, sendoffset, count); for (int i = (Size() - 1); i > Rank(); i--) { req[i] = isend(sendbuf, sendoffset, count, datatype, i, scanTag, false); } for (int i = 0; i < Rank(); i++) { recv(recvbuf, recvoffset, count, datatype, i, scanTag, false); op2.perform(recvbuf, recvoffset, count); } op2.getResultant(recvbuf, recvoffset, count); for (int i = (Size() - 1); i > Rank(); i--) { req[i].Wait(); } } //Topology constructors /** * Create a Cartesian topology communicator whose group is a subset * of the group of this communicator. *

* * * * * *
dims the number of processes in each * dimension
periods true if grid is periodic, * false if not, in each * dimension
reorder true if ranking may be * reordered, false if not
returns: new Cartesian topology * communicator
*

* Java binding of the MPI operation MPI_CART_CREATE. *

* The number of dimensions of the Cartesian grid is taken to be the size * of the dims argument. The array periods must be the * same size. */ public Cartcomm Create_cart(int[] dims, boolean[] periods, boolean reorder) throws MPIException { int totalProcess = this.group.Size(); int places = 1; mpjdev.Comm ncomm = mpjdevComm; mpi.Group ngroup = this.group; for (int i = 0; i < dims.length; i++) { if (dims[i] < 0) { throw new MPIException("dims["+i+"] is less than than zero"); } places *= dims[i]; } //MPI.logger.debug("places "+places); //MPI.logger.debug("totalProcesses "+totalProcess); if (places > totalProcess) { throw new MPIException(" Error in Intracomm.Create_cart: "+ "total grid positions <"+places+"> are greater than "+ " total processes <"+totalProcess+">"); } else if (places < totalProcess) { //MPI.logger.debug("dropping some processes ..."); int[] excl = new int[totalProcess - places]; //MPI.logger.debug("length of excl array "+excl.length); for (int i = 0; i < excl.length; i++) { excl[i] = i + places; } try { //MPI.logger.debug("calling excl method ."); ngroup = ngroup.Excl(excl); //MPI.logger.debug( "called excl .. creating "+ // "new group now" ); ncomm = ncomm.create(ngroup.mpjdevGroup); //MPI.logger.debug("created the new comm"); } catch (Exception e) { throw new MPIException(e); } } else { //MPI.logger.debug("All OK"); ngroup = group; try { ncomm = ncomm.create(ngroup.mpjdevGroup); } catch (Exception e) { throw new MPIException(e ); } } //MPI.logger.debug("oldRank "+group.Rank()+">,nrank<"+ngroup.Rank()); if (ngroup.Rank() == -1) { //MPI.logger.debug("means this process is not in the "+ // "new group"); return null; //comm stuff ... } return new Cartcomm(dims, periods, reorder, ncomm, ngroup.mpjdevGroup); } /** * Create a graph topology communicator whose group is a subset * of the group of this communicator. *

* * * * * *
index node degrees
edges graph edges
reorder true if ranking may be * reordered, false if not
returns: new graph topology communicator
*

* Java binding of the MPI operation MPI_GRAPH_CREATE. *

* The number of nodes in the graph, nnodes, is taken * to be size of the index argument. The size of array * edges must be index [nnodes} - 1]. */ public Graphcomm Create_graph(int[] index, int[] edges, boolean reorder) { int size = this.group.Size(); int nnodes = index.length; mpjdev.Comm ncomm = mpjdevComm; mpi.Group ngroup = this.group; //MPI.logger.debug("nnodes "+nnodes); //MPI.logger.debug("size "+size); if (nnodes > size) { throw new MPIException(" Error in Intracomm.Create_graphs: "+ "total nodes <"+nnodes+"> are greater than "+ " total processes <"+ size +">"); } else if (nnodes < size) { //MPI.logger.debug("dropping some processes ..."); int[] excl = new int[size - nnodes]; //MPI.logger.debug("length of excl array "+excl.length); for (int i = 0; i < excl.length; i++) { excl[i] = i + nnodes; } try { //MPI.logger.debug("calling excl method ."); ngroup = ngroup.Excl(excl); //MPI.logger.debug( "called excl .. creating "+ // "new group now" ); ncomm = ncomm.create(ngroup.mpjdevGroup); //MPI.logger.debug("created the new comm"); } catch (Exception e) { throw new MPIException(e ); } } else { //MPI.logger.debug("All OK"); ngroup = group; try { ncomm = ncomm.create(ngroup.mpjdevGroup); } catch (Exception e) { throw new MPIException(e); } } //MPI.logger.debug("oldRank "+group.Rank()+">,nrank<"+ngroup.Rank()); if (ngroup.Rank() == -1) { //MPI.logger.debug("means this process is not in the "+ // "new group"); return null; //comm stuff ... } return new Graphcomm(index, edges, reorder, ncomm, ngroup.mpjdevGroup); } } mpj-v0_38/src/mpi/Lor.java0000664000000000000000000000315211004030775014152 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : Lor.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.6 $ * Updated : $Date: 2005/07/29 14:03:09 $ */ package mpi; import mpjbuf.*; public class Lor extends Op { Lor() { worker = new LorWorker(); } } mpj-v0_38/src/mpi/BxorChar.java0000664000000000000000000000446511514104243015134 0ustar rootroot/* This file generated automatically from template BxorType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : BxorChar.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/08/01 22:31:40 $ */ package mpi; import mpjbuf.*; public class BxorChar extends Bxor { char [] arr = null; BxorChar() { } void perform(Object buf1, Object buf2, int count) throws MPIException { char[] arr1 = (char[]) buf1; for (int i = 0; i < count; i++) { arr[i] = (char) (arr1[i] ^ arr[i]); } } void createInitialBuffer(Object buf, int offset, int count) throws MPIException { char[] tempArray = (char[]) buf; arr = new char[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { char[] tempArray = (char[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/BandChar.java0000664000000000000000000000451511514104243015062 0ustar rootroot/* This file generated automatically from template BandType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : BandChar.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/08/01 22:31:40 $ */ package mpi; import mpjbuf.*; public class BandChar extends Band { char [] arr = null; BandChar() { } void perform(Object buf1, int offset, int count) throws MPIException { char[] arr1 = (char[]) buf1; for (int i = offset; i < count; i++) { arr[i] = (char) (arr1[i] & arr[i]); } } void createInitialBuffer(Object buf, int offset, int count ) throws MPIException { char[] tempArray = (char[]) buf; arr = new char[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { char[] tempArray = (char[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/BorChar.java0000664000000000000000000000446011514104243014737 0ustar rootroot/* This file generated automatically from template BorType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : BorChar.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/08/01 22:31:40 $ */ package mpi; import mpjbuf.*; public class BorChar extends Bor { char [] arr = null; BorChar() { } void perform (Object buf1, Object buf2, int count) throws MPIException { char[] arr1 = (char[]) buf1; for (int i = 0; i < count; i++) { arr[i] = (char) (arr1[i] | arr[i]); } } void createInitialBuffer(Object buf, int offset, int count) throws MPIException { char[] tempArray = (char[]) buf; arr = new char[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { char[] tempArray = (char[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/Request.java0000775000000000000000000003154011004030775015053 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : Request.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.26 $ * Updated : $Date: 2006/10/20 17:24:47 $ */ package mpi; import mpjdev.*; import java.util.ArrayList; public class Request { public mpjdev.Request req = null; Datatype datatype = null; boolean isNull = false; static final int NULL = 2; int code = -1; Request() { } Request(int code) { this.code = code; } Request(boolean isNull) { this.isNull = isNull; } /** */ public Request(mpjdev.Request req) { this.req = req; } /** * Blocks until the operation identified by the request is complete. *

* * *
returns: status object
*

* Java binding of the MPI operation MPI_WAIT. *

* After the call returns, the request object becomes inactive. */ public Status Wait() throws MPIException { if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("--Wait--"); } if (isNull) { return MPI.EMPTY_STATUS; } if (this.req == null) { System.out.println(" mpjdev Request is null in Wait() "); return null; } if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("calling wait of niodev "); mpjdev.Status mpjdevStatus = this.req.iwait(); if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("called wait of niodev "); isNull = true; if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("--Wait ends --"); Status status = new mpi.Status(mpjdevStatus); //status.source = ? ; return status ; } private Status Test(boolean nothing) throws MPIException { if (isNull == true) { return new Status(); } if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("-- Test (boolean) "); mpi.Status status = null; mpjdev.Status devStatus = null; if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("this.req " + this.req); if (this.req != null) { devStatus = this.req.itest(); } else return null; if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug(" returned devStatus "); if (devStatus == null) { return null; } return new Status(); } /** * Returns a status object if the operation identified by the request * is complete, or a null reference otherwise. *

* * *
returns: status object or null reference
*

* Java binding of the MPI operation MPI_TEST. *

* After the call, if the operation is complete (ie, if the return value * is non-null), the request object becomes inactive. */ public Status Test() throws MPIException { if (isNull) { return MPI.EMPTY_STATUS; } mpi.Status status = null; mpjdev.Status devStatus = null; if (this.req != null) { devStatus = this.req.itest(); } else return null; if (devStatus == null) { return null; } status = Wait(); return status; } /** * Tests for completion of either one or none of the operations associated * with active requests. *

* * * *
array_of_requests array of requests
returns: status object or * null reference
*

* Java binding of the MPI operation MPI_TESTANY. *

* If some request completed, the index in array_of_requests * for that request can be obtained from the returned status object * through the. The corresponding element of array_of_requests * becomes inactive. * If no request completed, Testany returns a null reference. */ public static Status Testany(Request[] r) throws MPIException { Status s = null; for (int i = 0; i < r.length; i++) { if (r[i] == null) { continue; } if (r[i].Is_null()) { continue; } s = r[i].Test(); if (s != null) { s.index = i; return s; } } return null; } /** */ public void finalize() throws MPIException { } /** * Test if request object is void. *

* * *
returns: true if the request object is void, * false otherwise
*/ public boolean Is_null() throws MPIException { return isNull; } /** * Blocks until all of the operations associated with the active * requests in the array have completed. *

* * * *
array_of_requests array of requests
returns: array of status objects
*

* Java binding of the MPI operation MPI_WAITALL. *

* The result array will be the same size as array_of_requests. * On exit, requests become inactive. If the input value of * arrayOfRequests contains inactive requests, corresponding * elements of the result array will contain null status references. */ public static Status[] Waitall(Request[] r) throws MPIException { Status[] s = new Status[r.length]; for (int i = 0; i < r.length; i++) { if (r[i] != null) { s[i] = r[i].Wait(); } } return s; } /** * Blocks until one of the operations associated with the active * requests in the array has completed. *

* * * *
array_of_requests array of requests
returns: status object
*

* Java binding of the MPI operation MPI_WAITANY. *

* The index in array_of_requests for the request that completed * can be obtained from the returned status object through the * Status.index field. The corresponding element * of array_of_requests becomes inactive. */ public static Status Waitany(Request[] r) throws MPIException { /* mpjdev.Request requests[] = new mpjdev.Request[r.length] ; for(int i=0 ; iall of the operations associated * with active requests. *

* * * *
array_of_requests array of requests
returns: array of status objects
*

* Java binding of the MPI operation MPI_TESTALL. *

* If all operations have completed, the exit value of the argument array * and the result array are as for Waitall. If any * operation has not completed, the result value is null and no * element of the argument array is modified. */ public static Status[] Testall(Request[] r) throws MPIException { Status[] s = new Status[r.length]; for (int i = 0; i < r.length; i++) { if (r[i] != null) { s[i] = r[i].Test(true); if (s[i] == null) { /* for( int j=i-1; j>-1 ; j--) { r[j].isNull = false; } */ try { Thread.currentThread().sleep(500); } catch (Exception e) {} // return null; } } } for (int i = 0; i < r.length; i++) { s[i] = r[i].Wait(); } return s; } /** * Blocks until at least one of the operations associated with the active * requests in the array has completed. *

* * * *
array_of_requests array of requests
returns: array of status objects
*

* Java binding of the MPI operation MPI_WAITSOME. *

* The size of the result array will be the number of operations that * completed. The index in array_of_requests for each request that * completed can be obtained from the returned status objects through the * Status.index field. The corresponding element in * array_of_requests becomes inactive. */ public static Status[] Waitsome(Request[] r) throws MPIException { ArrayList list = new ArrayList (); boolean break_flag = false; for (int i = 0; i < r.length; i++) { Status s = null; if (r[i].Is_null()) { if (break_flag && i == r.length - 1) { break; } else if (i == r.length - 1) { i = -1; } continue; } s = r[i].Test(true); if (s != null) { s = r[i].Wait(); s.index = i; list.add(s); break_flag = true; } if (break_flag && i == r.length - 1) { break; } else if (i == r.length - 1) { i = -1; } } return list.toArray(new Status[0]); } /** * Behaves like Waitsome, except that it returns immediately. *

* * * *
array_of_requests array of requests
returns: array of status objects
*

* Java binding of the MPI operation MPI_TESTSOME. *

* If no operation has completed, TestSome returns an array of * length zero and elements of array_of_requests are unchanged. * Otherwise, arguments and return value are as for Waitsome. */ public static Status[] Testsome(Request[] r) throws MPIException { if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug(" Testsome "); ArrayList list = new ArrayList (); for (int i = 0; i < r.length; i++) { if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug("i " + i); Status s = null; if (r[i].Is_null()) { if(MPI.DEBUG && MPI.logger.isDebugEnabled()) MPI.logger.debug(" its null, continuing"); continue; } if(MPI.DEBUG && MPI.logger.isDebugEnabled()) { MPI.logger.debug("calling test again."); } s = r[i].Test(); if (s != null) { s.index = i; list.add(s); } } return list.toArray(new Status[0]); } /** * Mark a pending nonblocking communication for cancellation. * Java binding of the MPI operation MPI_CANCEL. */ public void Cancel() throws MPIException { System.out.println("Request.Cancel(): Not implemented in this release"); if (this.req.cancel()) { isNull = true; } else { isNull = false; } } } mpj-v0_38/src/mpi/SumDouble.java0000664000000000000000000000455111514104243015317 0ustar rootroot/* This file generated automatically from template SumType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : SumDouble.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/08/01 22:31:40 $ */ package mpi; import mpjbuf.*; public class SumDouble extends Sum { double [] arr = null; SumDouble() { } void perform(Object buf1, int offset, int count) throws MPIException { double[] arr1 = (double[]) buf1; for (int i = 0+offset; i < count; i++) { arr[i] = (double) (arr1[i] + arr[i]); } } void createInitialBuffer(Object buf, int offset, int count) throws MPIException { double[] tempArray = (double[]) buf; arr = new double[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { double[] tempArray = (double[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/MinByte.java0000664000000000000000000000453511514104243014771 0ustar rootroot/* This file generated automatically from template MinType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : MinByte.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/08/01 22:31:40 $ */ package mpi; import mpjbuf.*; public class MinByte extends Min { byte [] arr = null; MinByte() { } void perform(Object buf1, int offset, int count) throws MPIException { byte[] arr1 = (byte[]) buf1; for (int i = 0; i < count; i++) { if(arr1[i] < arr[i]) arr[i] = arr1[i]; } } void createInitialBuffer(Object buf, int offset, int count) throws MPIException { byte[] tempArray = (byte[]) buf; arr = new byte[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { byte[] tempArray = (byte[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/MaxFloat.java0000664000000000000000000000456311514104243015136 0ustar rootroot/* This file generated automatically from template MaxType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : MaxFloat.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.8 $ * Updated : $Date: 2005/09/03 12:48:06 $ */ package mpi; import mpjbuf.*; public class MaxFloat extends Max { float [] arr = null; MaxFloat() { } void perform (Object buf1, int offset, int count) throws MPIException { float[] arr1 = (float[]) buf1; for (int i = 0+offset; i < count; i++) { if (arr1[i] > arr[i]) { arr[i] = arr1[i]; } } } void createInitialBuffer(Object buf, int offset, int count) throws MPIException { float[] tempArray = (float[]) buf; arr = new float[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { float[] tempArray = (float[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/LandWorker.java0000664000000000000000000000501711004030775015470 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : LandWorker.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.6 $ * Updated : $Date: 2005/07/29 14:03:09 $ */ package mpi; import mpjbuf.*; public class LandWorker implements OpWorker { LandWorker() { } public Op getWorker(Datatype datatype) throws MPIException { switch (datatype.baseType) { case Datatype.BYTE: throw new MPIException(" MPI.LAND is invalid for MPI.BYTE"); case Datatype.CHAR: throw new MPIException(" MPI.LAND is invalid for MPI.CHAR"); case Datatype.SHORT: throw new MPIException(" MPI.LAND is invalid for MPI.SHORT"); case Datatype.BOOLEAN: return new LandBoolean(); case Datatype.INT: throw new MPIException(" MPI.LAND is invalid for MPI.INT"); case Datatype.LONG: throw new MPIException(" MPI.LAND is invalid for MPI.LONG"); case Datatype.FLOAT: throw new MPIException(" MPI.LAND is invalid for MPI.FLOAT"); case Datatype.DOUBLE: throw new MPIException(" MPI.LAND is invalid for MPI.DOUBLE"); default: return null; } } } mpj-v0_38/src/mpi/BandInt.java0000664000000000000000000000450111514104243014732 0ustar rootroot/* This file generated automatically from template BandType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : BandInt.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/08/01 22:31:40 $ */ package mpi; import mpjbuf.*; public class BandInt extends Band { int [] arr = null; BandInt() { } void perform(Object buf1, int offset, int count) throws MPIException { int[] arr1 = (int[]) buf1; for (int i = offset; i < count; i++) { arr[i] = (int) (arr1[i] & arr[i]); } } void createInitialBuffer(Object buf, int offset, int count ) throws MPIException { int[] tempArray = (int[]) buf; arr = new int[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { int[] tempArray = (int[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/MultistridedPackerBoolean.java0000664000000000000000000001410211514104243020510 0ustar rootroot/* This file generated automatically from template MultistridedPackerType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : MultistridedPackerBoolean.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/07/29 14:03:09 $ */ package mpi; import mpjbuf.*; public class MultistridedPackerBoolean extends MultistridedPacker { public MultistridedPackerBoolean(int rank, int [] indexes, int extent, int size) { super(rank, indexes, extent, size); } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { mpjbuf.strGather((boolean []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { mpjbuf.strScatter((boolean []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } // In following methods, tempting to try to temporarily modify the // existing `indexes' array, to avoid temporary allocations. // But if `indexes' is not immutable we lose the ability to safely // share the datatype object across threads. public void unpackPartial(mpjbuf.Buffer mpjbuf, int length, Object buf, int offset) throws MPIException { int [] cIndexes = new int [2 * rank] ; for(int i = 0 ; i < 2 * rank ; i++) cIndexes [i] = indexes [i] ; int cubeRank = rank - 1; int cubeSize = size ; while(length > 0) { cubeSize /= indexes [cubeRank] ; // size of next smallest dimension cube. int numCubes = length / cubeSize ; // Number of whole cubes. if(numCubes > 0) { cIndexes [cubeRank] = numCubes ; int blockSize = numCubes * cubeSize ; try { mpjbuf.strScatter((boolean []) buf, offset, cubeRank + 1, 0, rank, cIndexes) ; } catch(Exception e) { throw new MPIException(e); } // Unpack block of cubes. offset += blockSize ; length -= blockSize ; // If cubeRank = 0, then // cubeSize = 1, blockSize = numCubes = length // => This assignment puts length to zero. } cubeRank-- ; } } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { if(count == 1) { try { mpjbuf.strGather((boolean []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } else { int cRank = rank + 1 ; int [] cIndexes = new int [2 * cRank] ; for(int i = 0 ; i < rank ; i++) cIndexes [i] = indexes [i] ; cIndexes [rank] = count ; for(int i = 0 ; i < rank ; i++) cIndexes [cRank + i] = indexes [rank + i] ; cIndexes [cRank + rank] = extent ; try { mpjbuf.strGather((boolean []) buf, offset, cRank, 0, cRank, cIndexes) ; } catch(Exception e) { throw new MPIException(e); } } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { if(count == 1) { try { mpjbuf.strScatter((boolean []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } else { int cRank = rank + 1 ; int [] cIndexes = new int [2 * cRank] ; for(int i = 0 ; i < rank ; i++) cIndexes [i] = indexes [i] ; cIndexes [rank] = count ; for(int i = 0 ; i < rank ; i++) cIndexes [cRank + i] = indexes [rank + i] ; cIndexes [cRank + rank] = extent ; try { mpjbuf.strScatter((boolean []) buf, offset, cRank, 0, cRank, cIndexes) ; }catch(Exception e) { throw new MPIException(e); } } } } mpj-v0_38/src/mpi/BasicType.java0000664000000000000000000001253311004030775015304 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : BasicType.java * Author : Sang Lim, Sung-Hoon Ko, Xinying Li, Bryan Carpenter, * Aamir Shafi * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.13 $ * Updated : $Date: 2005/08/12 19:12:08 $ */ package mpi; import mpjbuf.*; import java.nio.ByteBuffer ; public class BasicType extends Datatype { int type; BasicType(int type) { // It is an error if type < 0 or type > Datatype.OBJECT. // But since this constructor should not be called from user // code we do not check for this condition. this.type = type; if (type == LB || type == UB) { baseType = UNDEFINED; size = 0; byteSize = 0; } else { baseType = type; switch (type) { case UNDEFINED: size = 0; byteSize = 0; break; case NULL: size = 0; byteSize = 0; break; case BYTE: bufferType = mpjbuf.Type.BYTE; byteSize = 1; break; case CHAR: bufferType = mpjbuf.Type.CHAR; byteSize = 2; break; case SHORT: bufferType = mpjbuf.Type.SHORT; byteSize = 2; break; case BOOLEAN: bufferType = mpjbuf.Type.BOOLEAN; byteSize = 1; break; case INT: bufferType = mpjbuf.Type.INT; byteSize = 4; break; case LONG: bufferType = mpjbuf.Type.LONG; byteSize = 8; break; case FLOAT: bufferType = mpjbuf.Type.FLOAT; byteSize = 4; break; case DOUBLE: bufferType = mpjbuf.Type.DOUBLE; byteSize = 8; break; case PACKED: //is this right ? size = 0; byteSize = 0; break; case OBJECT: //remember, object type is not copied onto static buffer. bufferType = mpjbuf.Type.OBJECT; size = 0; byteSize = 0; break; default: break; } size = 1; } computeBounds(); } private void computeBounds() { // Compute `ub' and `lb', which define the `extent' of the new type. // Also defines `ubSet', `lbSet' for this type. switch (type) { case LB: lb = 0; ub = 0; lbSet = true; ubSet = false; break; case UB: lb = 0; ub = 0; lbSet = false; ubSet = true; break; default: // **** what about PACKED? **** lb = 0; ub = 1; lbSet = false; ubSet = false; break; } extent = ub - lb; } mpjbuf.Buffer createWriteBuffer(ByteBuffer slicedBuffer, int messageSize) { return new mpjbuf.Buffer(new NIOBuffer(messageSize, slicedBuffer), MPI.BSEND_OVERHEAD, messageSize ); } mpjbuf.Buffer createWriteBuffer(int count) throws MPIException { int capacity = packedSize(count) + MPI.SEND_OVERHEAD ; int offset = MPI.SEND_OVERHEAD ; mpjbuf.RawBuffer rawBuffer = BufferFactory.create(capacity); mpjbuf.Buffer wBuffer = new mpjbuf.Buffer (rawBuffer, offset, capacity) ; try { wBuffer.putSectionHeader(this.bufferType); // need conversion } catch (Exception e) { throw new MPIException(e); } return wBuffer; } mpjbuf.Buffer createReadBuffer(int count) { int capacity = packedSize(count) + MPI.RECV_OVERHEAD ; int offset = MPI.RECV_OVERHEAD ; mpjbuf.RawBuffer rawBuffer = BufferFactory.create(capacity); mpjbuf.Buffer mpjbuf = new mpjbuf.Buffer(rawBuffer, offset, capacity) ; return mpjbuf; } int packedSize(int count) { int dataSize = count * byteSize; int totalSize = 0; int sectionHeader = 8; //what about multiple sections. totalSize = sectionHeader + dataSize; int padding = 0; if (totalSize % 8 != 0) padding = totalSize % 8; return totalSize + padding; } void setPacker() { packer = SimplePackerFactory.create(1, baseType); } } // Things to do: // mpj-v0_38/src/mpi/Minloc.java0000664000000000000000000001277211004030775014647 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : Minloc.java * Author : Sang Lim, Sung-Hoon Ko, Xinying Li, Bryan Carpenter * (contributions from MAEDA Atusi), Aamir Shafi * Created : Thu Apr 9 12:22:15 1998 * Revision : $Revision: 1.8 $ * Updated : $Date: 2005/07/29 14:03:09 $ * Copyright: Northeast Parallel Architectures Center * at Syracuse University 1998 */ package mpi; // Minloc and Maxloc public class Minloc extends User_function{ public void Call(Object invec, int inoffset, Object outvec, int outoffset, int count, Datatype datatype){ if(datatype == MPI.SHORT2) { short [] in_array = (short[])invec; short [] out_array = (short[])outvec; int indisp = inoffset ; int outdisp = outoffset ; for (int i = 0; i < count; i++, indisp += 2, outdisp += 2){ short inval = in_array [indisp] ; short outval = out_array [outdisp] ; if(inval < outval) { out_array [outdisp ] = inval ; out_array [outdisp + 1] = in_array [indisp + 1] ; } else if(inval == outval) { short inloc = in_array [indisp + 1] ; if(inloc < out_array [outdisp + 1]) out_array [outdisp + 1] = inloc ; } } } else if(datatype == MPI.INT2) { int [] in_array = (int[])invec; int [] out_array = (int[])outvec; int indisp = inoffset ; int outdisp = outoffset ; for (int i = 0; i < count; i++, indisp += 2, outdisp += 2){ int inval = in_array [indisp] ; int outval = out_array [outdisp] ; if(inval < outval) { out_array [outdisp ] = inval ; out_array [outdisp + 1] = in_array [indisp + 1] ; } else if(inval == outval) { int inloc = in_array [indisp + 1] ; if(inloc < out_array [outdisp + 1]) out_array [outdisp + 1] = inloc ; } } } else if(datatype == MPI.LONG2) { long [] in_array = (long[])invec; long [] out_array = (long[])outvec; int indisp = inoffset ; int outdisp = outoffset ; for (int i = 0; i < count; i++, indisp += 2, outdisp += 2){ long inval = in_array [indisp] ; long outval = out_array [outdisp] ; if(inval < outval) { out_array [outdisp ] = inval ; out_array [outdisp + 1] = in_array [indisp + 1] ; } else if(inval == outval) { long inloc = in_array [indisp + 1] ; if(inloc < out_array [outdisp + 1]) out_array [outdisp + 1] = inloc ; } } } else if(datatype == MPI.FLOAT2) { float [] in_array = (float[])invec; float [] out_array = (float[])outvec; int indisp = inoffset ; int outdisp = outoffset ; for (int i = 0; i < count; i++, indisp += 2, outdisp += 2){ float inval = in_array [indisp] ; float outval = out_array [outdisp] ; if(inval < outval) { out_array [outdisp ] = inval ; out_array [outdisp + 1] = in_array [indisp + 1] ; } else if(inval == outval) { float inloc = in_array [indisp + 1] ; if(inloc < out_array [outdisp + 1]) out_array [outdisp + 1] = inloc ; } } } else if(datatype == MPI.DOUBLE2) { double [] in_array = (double[])invec; double [] out_array = (double[])outvec; int indisp = inoffset ; int outdisp = outoffset ; for (int i = 0; i < count; i++, indisp += 2, outdisp += 2){ double inval = in_array [indisp] ; double outval = out_array [outdisp] ; if(inval < outval) { out_array [outdisp ] = inval ; out_array [outdisp + 1] = in_array [indisp + 1] ; } else if(inval == outval) { double inloc = in_array [indisp + 1] ; if(inloc < out_array [outdisp + 1]) out_array [outdisp + 1] = inloc ; } } } else { System.out.println("MPI.MINLOC: invalid datatype") ; try { MPI.COMM_WORLD.Abort(1); } catch(MPIException e) {} } } } // Things to do: // // Check if `Maxloc'/`Minloc' should work with derived types. mpj-v0_38/src/mpi/MultistridedPackerInt.java0000664000000000000000000001403211514104243017665 0ustar rootroot/* This file generated automatically from template MultistridedPackerType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : MultistridedPackerInt.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/07/29 14:03:09 $ */ package mpi; import mpjbuf.*; public class MultistridedPackerInt extends MultistridedPacker { public MultistridedPackerInt(int rank, int [] indexes, int extent, int size) { super(rank, indexes, extent, size); } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { mpjbuf.strGather((int []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { mpjbuf.strScatter((int []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } // In following methods, tempting to try to temporarily modify the // existing `indexes' array, to avoid temporary allocations. // But if `indexes' is not immutable we lose the ability to safely // share the datatype object across threads. public void unpackPartial(mpjbuf.Buffer mpjbuf, int length, Object buf, int offset) throws MPIException { int [] cIndexes = new int [2 * rank] ; for(int i = 0 ; i < 2 * rank ; i++) cIndexes [i] = indexes [i] ; int cubeRank = rank - 1; int cubeSize = size ; while(length > 0) { cubeSize /= indexes [cubeRank] ; // size of next smallest dimension cube. int numCubes = length / cubeSize ; // Number of whole cubes. if(numCubes > 0) { cIndexes [cubeRank] = numCubes ; int blockSize = numCubes * cubeSize ; try { mpjbuf.strScatter((int []) buf, offset, cubeRank + 1, 0, rank, cIndexes) ; } catch(Exception e) { throw new MPIException(e); } // Unpack block of cubes. offset += blockSize ; length -= blockSize ; // If cubeRank = 0, then // cubeSize = 1, blockSize = numCubes = length // => This assignment puts length to zero. } cubeRank-- ; } } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { if(count == 1) { try { mpjbuf.strGather((int []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } else { int cRank = rank + 1 ; int [] cIndexes = new int [2 * cRank] ; for(int i = 0 ; i < rank ; i++) cIndexes [i] = indexes [i] ; cIndexes [rank] = count ; for(int i = 0 ; i < rank ; i++) cIndexes [cRank + i] = indexes [rank + i] ; cIndexes [cRank + rank] = extent ; try { mpjbuf.strGather((int []) buf, offset, cRank, 0, cRank, cIndexes) ; } catch(Exception e) { throw new MPIException(e); } } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { if(count == 1) { try { mpjbuf.strScatter((int []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } else { int cRank = rank + 1 ; int [] cIndexes = new int [2 * cRank] ; for(int i = 0 ; i < rank ; i++) cIndexes [i] = indexes [i] ; cIndexes [rank] = count ; for(int i = 0 ; i < rank ; i++) cIndexes [cRank + i] = indexes [rank + i] ; cIndexes [cRank + rank] = extent ; try { mpjbuf.strScatter((int []) buf, offset, cRank, 0, cRank, cIndexes) ; }catch(Exception e) { throw new MPIException(e); } } } } mpj-v0_38/src/mpi/SimplePackerFloat.java0000664000000000000000000000711511514104243016764 0ustar rootroot/* This file generated automatically from template SimplePackerType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : SimplePackerFloat.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/07/29 14:03:10 $ */ package mpi; import mpjbuf.*; public class SimplePackerFloat extends SimplePacker{ public SimplePackerFloat(int numEls) { super(numEls); } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { mpjbuf.write((float []) buf, offset, numEls) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { mpjbuf.read((float []) buf, offset, numEls) ; } catch(Exception e) { throw new MPIException(e); } } public void unpackPartial(mpjbuf.Buffer mpjbuf, int length, Object buf, int offset) throws MPIException { try { mpjbuf.read((float []) buf, offset, length) ; } catch(Exception e) { throw new MPIException(e); } } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { try { mpjbuf.write((float []) buf, offset, count * numEls) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { try { mpjbuf.read((float []) buf, offset, count*numEls ) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, int length, Object buf, int offset, int count) throws MPIException { if(count * numEls < length) { throw new MPIException ("Error in SimplePacker : count <"+ (count*numEls)+"> is less than length <"+length+">"); } try { mpjbuf.read((float []) buf, offset, length) ; }catch(Exception e){ throw new MPIException(e); } } } mpj-v0_38/src/mpi/SumType.java.in0000664000000000000000000000444211004030775015434 0ustar rootroot /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : Sum@Type@.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/08/01 22:31:40 $ */ package mpi; import mpjbuf.*; public class Sum@Type@ extends Sum { @type@ [] arr = null; Sum@Type@() { } void perform(Object buf1, int offset, int count) throws MPIException { @type@[] arr1 = (@type@[]) buf1; for (int i = 0+offset; i < count; i++) { arr[i] = (@type@) (arr1[i] + arr[i]); } } void createInitialBuffer(Object buf, int offset, int count) throws MPIException { @type@[] tempArray = (@type@[]) buf; arr = new @type@[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { @type@[] tempArray = (@type@[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/SumShort.java0000664000000000000000000000453511514104243015206 0ustar rootroot/* This file generated automatically from template SumType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : SumShort.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/08/01 22:31:40 $ */ package mpi; import mpjbuf.*; public class SumShort extends Sum { short [] arr = null; SumShort() { } void perform(Object buf1, int offset, int count) throws MPIException { short[] arr1 = (short[]) buf1; for (int i = 0+offset; i < count; i++) { arr[i] = (short) (arr1[i] + arr[i]); } } void createInitialBuffer(Object buf, int offset, int count) throws MPIException { short[] tempArray = (short[]) buf; arr = new short[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { short[] tempArray = (short[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/MPIException.java0000775000000000000000000000342511004030775015730 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : MPIException.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/07/29 14:03:09 $ */ package mpi; import mpjdev.MPJDevException; public class MPIException extends MPJDevException { public MPIException() { super(); } public MPIException(String message) { super(message); } public MPIException(Throwable cause) { super(cause); } } mpj-v0_38/src/mpi/GraphParms.java0000775000000000000000000000312511004030775015465 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : GraphParms.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.6 $ * Updated : $Date: 2005/07/29 14:03:09 $ */ package mpi; public class GraphParms { public int[] index; public int[] edges; } mpj-v0_38/src/mpi/Graphcomm.java0000775000000000000000000001173011312061142015331 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : Graphcomm.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.8 $ * Updated : $Date: 2005/09/28 13:33:59 $ */ package mpi; public class Graphcomm extends Intracomm { GraphParms graphParms = null; Graphcomm(int[] index, int[] edges, boolean reorder, mpjdev.Comm mpjdevComm, mpjdev.Group group) throws MPIException { super(mpjdevComm,group) ; int rank = group.rank(); //this.mpjdevComm = mpjdevComm; //this.group = new Group(group); graphParms = new GraphParms(); graphParms.index = new int[index.length]; System.arraycopy(index,0,graphParms.index,0,index.length); //graphParms.index = index; graphParms.edges = new int[edges.length]; System.arraycopy(edges,0,graphParms.edges,0,edges.length); //graphParms.edges = edges; //nedges = index[index.length-1]; } /** */ public Object clone() throws MPIException { return this.Create_graph(graphParms.index, graphParms.edges, false); } /** * Returns graph topology information. *

* * *
returns: object defining node degress and * edges of graph
*

* Java binding of the MPI operation MPI_GRAPHDIMS_GET. *

* The number of nodes and number of edges can be extracted * from the sizes of the index and edges fields * of the returned object. */ public GraphParms Get() throws MPIException { return graphParms; } /** * Provides adjacency information for general graph topology. *

* * * *
rank rank of a process in the group * of this communicator
returns: array of ranks of neighbouring * processes to one specified
*

* Java binding of the MPI operations MPI_GRAPH_NEIGHBOURS_COUNT * and MPI_GRAPH_NEIGHBOURS. *

* The number of neighbours can be extracted from the size of the result. */ public int[] Neighbours(int rank) throws MPIException { int nnbrs = graphParms.index[rank]; int i = 0; int p = 0; //index to graphParms edges if (rank > 0) { i = graphParms.index[rank - 1]; nnbrs -= i; p = i; } int[] nbrs = new int[nnbrs]; //MPI says there is a need for maxnbrs here //but mpiJava seems to get rid of it .. //so discuss with Bryan, and if you introduce //maxnbrs as an arg, then which ever is lesser //(maxnbrs, or nnbrs) would be the size of //nbrs array ... for (i = 0; i < nnbrs; ++i, ++p) { nbrs[i] = graphParms.edges[p]; } return nbrs; //current maxnbrs can be obtained by //nbrs.length ... } /** * Compute an optimal placement. *

* * * * *
index node degrees
edges graph edges
returns: reordered rank of calling * process
*

* Java binding of the MPI operation MPI_GRAPH_MAP. *

* The number of nodes is taken to be size of the index argument. */ public int Map(int[] index, int[] edges) throws MPIException { int myrank = this.group.Rank(); //-1 in the next line is MPI.UNDEFINED ... return ( (myrank < 0) || (myrank >= index.length)) ? -1 : myrank; } public int Topo_test() throws MPIException { return MPI.GRAPH; //this means no topology .... } } mpj-v0_38/src/mpi/MultistridedPackerChar.java0000664000000000000000000001404411514104243020013 0ustar rootroot/* This file generated automatically from template MultistridedPackerType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : MultistridedPackerChar.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/07/29 14:03:09 $ */ package mpi; import mpjbuf.*; public class MultistridedPackerChar extends MultistridedPacker { public MultistridedPackerChar(int rank, int [] indexes, int extent, int size) { super(rank, indexes, extent, size); } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { mpjbuf.strGather((char []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { mpjbuf.strScatter((char []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } // In following methods, tempting to try to temporarily modify the // existing `indexes' array, to avoid temporary allocations. // But if `indexes' is not immutable we lose the ability to safely // share the datatype object across threads. public void unpackPartial(mpjbuf.Buffer mpjbuf, int length, Object buf, int offset) throws MPIException { int [] cIndexes = new int [2 * rank] ; for(int i = 0 ; i < 2 * rank ; i++) cIndexes [i] = indexes [i] ; int cubeRank = rank - 1; int cubeSize = size ; while(length > 0) { cubeSize /= indexes [cubeRank] ; // size of next smallest dimension cube. int numCubes = length / cubeSize ; // Number of whole cubes. if(numCubes > 0) { cIndexes [cubeRank] = numCubes ; int blockSize = numCubes * cubeSize ; try { mpjbuf.strScatter((char []) buf, offset, cubeRank + 1, 0, rank, cIndexes) ; } catch(Exception e) { throw new MPIException(e); } // Unpack block of cubes. offset += blockSize ; length -= blockSize ; // If cubeRank = 0, then // cubeSize = 1, blockSize = numCubes = length // => This assignment puts length to zero. } cubeRank-- ; } } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { if(count == 1) { try { mpjbuf.strGather((char []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } else { int cRank = rank + 1 ; int [] cIndexes = new int [2 * cRank] ; for(int i = 0 ; i < rank ; i++) cIndexes [i] = indexes [i] ; cIndexes [rank] = count ; for(int i = 0 ; i < rank ; i++) cIndexes [cRank + i] = indexes [rank + i] ; cIndexes [cRank + rank] = extent ; try { mpjbuf.strGather((char []) buf, offset, cRank, 0, cRank, cIndexes) ; } catch(Exception e) { throw new MPIException(e); } } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { if(count == 1) { try { mpjbuf.strScatter((char []) buf, offset, rank, 0, rank, indexes) ; } catch(Exception e) { throw new MPIException(e); } } else { int cRank = rank + 1 ; int [] cIndexes = new int [2 * cRank] ; for(int i = 0 ; i < rank ; i++) cIndexes [i] = indexes [i] ; cIndexes [rank] = count ; for(int i = 0 ; i < rank ; i++) cIndexes [cRank + i] = indexes [rank + i] ; cIndexes [cRank + rank] = extent ; try { mpjbuf.strScatter((char []) buf, offset, cRank, 0, cRank, cIndexes) ; }catch(Exception e) { throw new MPIException(e); } } } } mpj-v0_38/src/mpi/BandShort.java0000664000000000000000000000453111514104243015302 0ustar rootroot/* This file generated automatically from template BandType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : BandShort.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/08/01 22:31:40 $ */ package mpi; import mpjbuf.*; public class BandShort extends Band { short [] arr = null; BandShort() { } void perform(Object buf1, int offset, int count) throws MPIException { short[] arr1 = (short[]) buf1; for (int i = offset; i < count; i++) { arr[i] = (short) (arr1[i] & arr[i]); } } void createInitialBuffer(Object buf, int offset, int count ) throws MPIException { short[] tempArray = (short[]) buf; arr = new short[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { short[] tempArray = (short[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/ShiftParms.java0000775000000000000000000000316011004030775015500 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : ShiftParms.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.6 $ * Updated : $Date: 2005/07/29 14:03:10 $ */ package mpi; public class ShiftParms { ShiftParms() { } public int rank_source; public int rank_dest; } mpj-v0_38/src/mpi/BandWorker.java0000664000000000000000000000446311004030775015462 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : BandWorker.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.6 $ * Updated : $Date: 2005/07/29 14:03:09 $ */ package mpi; public class BandWorker implements OpWorker { BandWorker() {} public Op getWorker(Datatype datatype) throws MPIException { switch (datatype.baseType) { case Datatype.BYTE: return new BandByte(); case Datatype.CHAR: return new BandChar(); case Datatype.SHORT: return new BandShort(); case Datatype.BOOLEAN: throw new MPIException("MPI.BAND is not valid for MPI.BOOLEAN" ); case Datatype.INT: return new BandInt(); case Datatype.LONG: return new BandLong(); case Datatype.FLOAT: throw new MPIException("MPI.BAND is not valid for MPI.FLOAT" ); case Datatype.DOUBLE: throw new MPIException("MPI.BAND is not valid for MPI.DOUBLE"); default: return null; } } } mpj-v0_38/src/mpi/LandBoolean.java0000664000000000000000000000500711514104243015573 0ustar rootroot/* This file generated automatically from template LandType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : LandBoolean.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/08/01 22:31:40 $ */ package mpi; import mpjbuf.*; public class LandBoolean extends Land { boolean [] arr = null; LandBoolean() { } public void perform (Object buf1, int offset, int count) throws MPIException { boolean[] arr1 = (boolean[]) buf1; for (int i = offset; i < count; i++) { arr[i] = arr1[i] && arr[i]; //this is bit-wise AND ..logical AND is && and its between //two conditions ...not two integers ..or any other type ... } } void createInitialBuffer(Object buf, int offset, int count) throws MPIException { boolean[] tempArray = (boolean[]) buf; arr = new boolean[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { boolean[] tempArray = (boolean[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/MinFloat.java0000664000000000000000000000455011514104243015130 0ustar rootroot/* This file generated automatically from template MinType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : MinFloat.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/08/01 22:31:40 $ */ package mpi; import mpjbuf.*; public class MinFloat extends Min { float [] arr = null; MinFloat() { } void perform(Object buf1, int offset, int count) throws MPIException { float[] arr1 = (float[]) buf1; for (int i = 0; i < count; i++) { if(arr1[i] < arr[i]) arr[i] = arr1[i]; } } void createInitialBuffer(Object buf, int offset, int count) throws MPIException { float[] tempArray = (float[]) buf; arr = new float[tempArray.length]; System.arraycopy(buf, offset, arr, offset, count) ; } void getResultant(Object buf, int offset, int count ) throws MPIException { float[] tempArray = (float[]) buf; System.arraycopy(arr, offset, tempArray, offset, count); } } mpj-v0_38/src/mpi/SimplePackerFactory.java0000664000000000000000000000522111004030775017324 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : SimplePackerFactory.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/08/16 21:44:02 $ */ package mpi; public class SimplePackerFactory { public static Packer create(int count, int datatype) { switch (datatype) { case Datatype.UNDEFINED: break; case Datatype.NULL: break; case Datatype.BYTE: return new SimplePackerByte(count); case Datatype.CHAR: return new SimplePackerChar(count); case Datatype.SHORT: return new SimplePackerShort(count); case Datatype.BOOLEAN: return new SimplePackerBoolean(count); case Datatype.INT: return new SimplePackerInt(count); case Datatype.LONG: return new SimplePackerLong(count); case Datatype.FLOAT: return new SimplePackerFloat(count); case Datatype.DOUBLE: return new SimplePackerDouble(count); case Datatype.PACKED: //return new NullPacker(); break ; case Datatype.LB: break; case Datatype.UB: break; case Datatype.OBJECT: return new SimplePackerObject(count); default: break; } return null; } } mpj-v0_38/src/mpi/Bxor.java0000664000000000000000000000313511004030775014331 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : Bxor.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.6 $ * Updated : $Date: 2005/07/29 14:03:09 $ */ package mpi; import mpjbuf.*; public class Bxor extends Op { Bxor() { worker = new BxorWorker(); } } mpj-v0_38/src/mpi/SimplePackerInt.java0000664000000000000000000000707311514104243016454 0ustar rootroot/* This file generated automatically from template SimplePackerType.java.in. */ /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : SimplePackerInt.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/07/29 14:03:10 $ */ package mpi; import mpjbuf.*; public class SimplePackerInt extends SimplePacker{ public SimplePackerInt(int numEls) { super(numEls); } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { mpjbuf.write((int []) buf, offset, numEls) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { mpjbuf.read((int []) buf, offset, numEls) ; } catch(Exception e) { throw new MPIException(e); } } public void unpackPartial(mpjbuf.Buffer mpjbuf, int length, Object buf, int offset) throws MPIException { try { mpjbuf.read((int []) buf, offset, length) ; } catch(Exception e) { throw new MPIException(e); } } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { try { mpjbuf.write((int []) buf, offset, count * numEls) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { try { mpjbuf.read((int []) buf, offset, count*numEls ) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, int length, Object buf, int offset, int count) throws MPIException { if(count * numEls < length) { throw new MPIException ("Error in SimplePacker : count <"+ (count*numEls)+"> is less than length <"+length+">"); } try { mpjbuf.read((int []) buf, offset, length) ; }catch(Exception e){ throw new MPIException(e); } } } mpj-v0_38/src/mpi/MPI.java0000775000000000000000000003272311354712317014063 0ustar rootroot/* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : MPI.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.41 $ * Updated : $Date: 2006/10/20 17:24:47 $ */ package mpi; import mpjdev.*; import mpjbuf.*; import java.util.Hashtable; import java.io.IOException ; import java.nio.ByteBuffer ; import java.util.ArrayList ; import java.util.Map ; import org.apache.log4j.Logger ; import org.apache.log4j.PropertyConfigurator ; import org.apache.log4j.PatternLayout ; import org.apache.log4j.FileAppender ; import org.apache.log4j.Level ; import org.apache.log4j.DailyRollingFileAppender ; import org.apache.log4j.spi.LoggerRepository ; public class MPI { public static final boolean DEBUG = false; //public static final boolean DEBUG = false; static Logger logger = null ; public static Intracomm COMM_WORLD; private static boolean initialized = false; static boolean debug = true; static ByteBuffer buffer = null; static ArrayList pendingRequests = new ArrayList () ; static final int OP_BSEND = 1; static final int OP_RSEND = 2; static final int OP_SEND = 3; static final int OP_RECV = 4; static final int OP_SSEND = 5; public static final int NUM_OF_PROCESSORS = Runtime.getRuntime().availableProcessors(); static Status UNDEFINED_STATUS = new Status( -1, -1, -1); //public static Datatype UNDEFINED = new BasicType( -1); public static int UNDEFINED = -1; public static Datatype NULL = new BasicType(0); public static Datatype BYTE = new BasicType(1); public static Datatype CHAR = new BasicType(2); public static Datatype SHORT = new BasicType(3); public static Datatype BOOLEAN = new BasicType(4); public static Datatype INT = new BasicType(5); public static Datatype LONG = new BasicType(6); public static Datatype FLOAT = new BasicType(7); public static Datatype DOUBLE = new BasicType(8); public static Datatype PACKED = new BasicType(9); public static Datatype LB = new BasicType(10); public static Datatype UB = new BasicType(11); public static Datatype OBJECT = new BasicType(12); public static int THREAD_SINGLE = 1; public static int THREAD_FUNNELED = 2; public static int THREAD_SERIALIZED = 3; public static int THREAD_MULTIPLE = 4; /** * Its actually not good to call the following basic datatypes because * they are not ... this will be changed to sometyhing else ...need * to think about it */ public static Datatype SHORT2 =Datatype.Contiguous( 2, MPI.SHORT) ; public static Datatype INT2 = Datatype.Contiguous( 2, MPI.INT) ; public static Datatype LONG2 = Datatype.Contiguous( 2, MPI.LONG) ; public static Datatype FLOAT2 = Datatype.Contiguous( 2, MPI.FLOAT) ; public static Datatype DOUBLE2 = Datatype.Contiguous( 2, MPI.DOUBLE) ; public static Op MAX = new Max(); public static Op MIN = new Min(); public static Op SUM = new Sum(); public static Op PROD = new Prod(); public static Op LAND = new Land(); public static Op BAND = new Band(); public static Op LOR = new Lor(); public static Op BOR = new Bor(); public static Op LXOR = new Lxor(); public static Op BXOR = new Bxor(); public static Op MAXLOC = new Op( new Maxloc(), true); public static Op MINLOC = new Op( new Minloc(), true); public static int ANY_SOURCE = -2, ANY_TAG = -2; public static Status EMPTY_STATUS = new Status(MPI.ANY_SOURCE, MPI.ANY_TAG, 0, 0); public static int PROC_NULL = -3; /** * Overhead incurred by buffered send. This variable should be accessed * after calling #Init(String[] args) method. */ public static int BSEND_OVERHEAD ; /** * These should be accessed after calling MPI.Init() */ public static int SEND_OVERHEAD, RECV_OVERHEAD ; //public static Datatype UNDEFINED; public static Group GROUP_EMPTY = new mpi.Group( new mpjdev.Group(new xdev.ProcessID[0], null,-1)); public static Comm COMM_SELF; public static final int IDENT = 0, CONGRUENT = 3, SIMILAR = 1, UNEQUAL = 2; public static int GRAPH = 1, CART = 2; public static Errhandler ERRORS_ARE_FATAL, ERRORS_RETURN; public static int TAG_UB, HOST, IO; public static Request REQUEST_NULL = new mpi.Request(true); public static Comm COMM_NULL; public static Group GROUP_NULL; /** * Provides to MPI a buffer in user's memory to be used for buffering * outgoing messages. * Java binding of the MPI operation MPI_BUFFER_ATTACH. */ public static void Buffer_attach(ByteBuffer userBuffer) throws MPIException{ buffer = userBuffer; } /** * Detach the buffer currently associated with MPI. * Java binding of the MPI operation MPI_BUFFER_DETACH. */ public static void Buffer_detach() throws MPIException { synchronized(pendingRequests) { for(Request pending : pendingRequests ) { //apparently may not make sense for bsend, but under the hoods //bsend is using isend for comms, and there is a request //object attached pending.Wait() ; } buffer = null; } Comm.PendingMessage.clearFront() ; } /** * Used to initialize MPI with certain level of threadedness ... */ public static String[] initThread(int required, int provided, String [] argv) { return null; } /** * Returns true if this thread initialized MPI */ public static boolean isMainThread() { return true; } /** * Returns the level of thread support provided by the MPI library and * the underlying device selected */ public static int queryThread() { return MPI.THREAD_MULTIPLE ; } /** * Initialize MPI. *

* * *
args arguments to main method.
*

* Java binding of the MPI operation MPI_INIT. */ public static String[] Init(String[] argv) throws MPIException { if (argv.length < 3) { throw new MPIException ("Usage: " + "java MPI " +"conf_file can be, ../conf/xdev.conf " +"OR http://holly.dsg.port.ac.uk:15000/xdev.conf "); } DailyRollingFileAppender fileAppender = null ; int rank = Integer.parseInt( argv[0] ); Map map = System.getenv() ; String mpjHomeDir = map.get("MPJ_HOME"); if(logger == null && DEBUG ) { try { fileAppender = new DailyRollingFileAppender( new PatternLayout( " %-5p %c %x - %m\n" ), mpjHomeDir+"/logs/mpj"+rank+".log", "yyyy-MM-dd-HH" ); Logger rootLogger = Logger.getRootLogger() ; rootLogger.addAppender( fileAppender); LoggerRepository rep = rootLogger.getLoggerRepository() ; rootLogger.setLevel ((Level) Level.ALL ); //rep.setThreshold((Level) Level.OFF ) ; logger = Logger.getLogger( "mpj" ); } catch(Exception e) { throw new MPIException(e) ; } } try { MPJDev.init(argv); BSEND_OVERHEAD = MPJDev.getSendOverhead() ; SEND_OVERHEAD = BSEND_OVERHEAD ; RECV_OVERHEAD = MPJDev.getRecvOverhead() ; COMM_WORLD = new Intracomm(MPJDev.WORLD, MPJDev.WORLD.group); COMM_WORLD.Attr_put(MPI.TAG_UB,Integer.MAX_VALUE); COMM_WORLD.Attr_put(MPI.HOST, PROC_NULL); COMM_WORLD.Attr_put(MPI.IO,COMM_WORLD.Rank()); } catch (Exception e) { throw new MPIException( e); } int [] self = { COMM_WORLD.Rank() } ; Group selfGroup = COMM_WORLD.group.Incl(self); COMM_SELF = COMM_WORLD.Create( selfGroup ); int [] empty = new int[0]; GROUP_EMPTY = COMM_WORLD.group.Incl(empty); GROUP_EMPTY.code = Group.EMPTY; //use these three in case of errors.. GROUP_NULL = new Group(Group.NULL) ; COMM_NULL = new Comm(Comm.NULL) ; //REQUEST_NULL = new Request(Request.NULL) ; ERRORS_ARE_FATAL = new Errhandler(Errhandler.FATAL) ; ERRORS_ARE_FATAL = new Errhandler(Errhandler.RETURN) ; /* * this is 3 coz i know MPI/MPJDev/xdev init methods only * use the first four arguments ..if in future, we write * a device which takes more argument, then this '3' may * have to be changed */ String[] nargs = new String[(argv.length - 3)] ; System.arraycopy(argv, 3, nargs, 0, nargs.length) ; initialized = true; if(DEBUG && logger.isDebugEnabled()) { logger.debug("pendingQue.size "+pendingRequests.size()) ; logger.debug(" queue_size (init) "+Comm.PendingMessage.queue_size); } return nargs ; } /** * Finalize MPI. *

* Java binding of the MPI operation MPI_FINALIZE. */ public static void Finalize() throws MPIException { if(DEBUG && logger.isDebugEnabled() ) { logger.debug("calling detach"); } MPI.Buffer_detach() ; if(DEBUG && logger.isDebugEnabled() ) { logger.debug("called detach"); logger.debug(" queue_size (exit) "+Comm.PendingMessage.queue_size); logger.debug("pendingQue.size "+pendingRequests.size()) ; logger.debug("calling last barrier"); } try { COMM_WORLD.Barrier(); } catch (Exception e) { e.printStackTrace() ; throw new MPIException(e); } if(DEBUG && logger.isDebugEnabled() ) { logger.debug("Called it") ; } if(DEBUG && logger.isDebugEnabled() ) { logger.debug("Calling MPJDev finalize ") ; } try { MPJDev.finish(); } catch (Exception e) { throw new MPIException(e); } if(DEBUG && logger.isDebugEnabled() ) { logger.debug("Called it ...") ; } initialized = false; } /** * Returns the name of the processor on which it is called. *

* * *
returns: A unique specifier for the actual * node.
*

* Java binding of the MPI operation MPI_GET_PROCESSOR_NAME. */ public static String Get_processor_name() throws MPIException { try { java.net.InetAddress addr = java.net.InetAddress.getLocalHost(); byte[] ipAddr = addr.getAddress(); String hostname = addr.getHostName(); return hostname; } catch (java.net.UnknownHostException e) { throw new MPIException( e ); } } /** * Set Error Handler * * Not Implemented in the current release * */ public static void Errorhandler_set(Errhandler errhandler) throws MPIException { } /** * Gets the error handler * * Not Implemented in the current release * */ public static Errhandler Errorhandler_get() throws MPIException { return null; } /** * Returns wallclock time. *

* * *
returns: elapsed wallclock time in seconds * since some time in the past
*

* Java binding of the MPI operation MPI_WTIME. */ public static double Wtime() throws MPIException { return (System.currentTimeMillis() / 1000) ; } /** * Returns resolution of timer. *

* * *
returns: resolution of wtime in * seconds.
*

* Java binding of the MPI operation MPI_WTICK. */ public static double Wtick() throws MPIException { double time = 0L; double newTime; double smaller = Double.MAX_VALUE; for (int i = 0; i < 100000; i++) { time = Wtime(); newTime = Wtime(); smaller = Math.min(smaller, (newTime - time)); } return smaller; } /** * Test if MPI has been initialized. *

* * *
returns: true if Init has * been called, false * otherwise.
*

* Java binding of the MPI operation MPI_INITIALIZED. */ public static boolean Initialized() throws MPIException { return initialized; } } mpj-v0_38/src/mpi/SimplePackerType.java.in0000664000000000000000000000711211004030775017244 0ustar rootroot /* The MIT License Copyright (c) 2005 - 2008 1. Distributed Systems Group, University of Portsmouth (2005) 2. Community Grids Laboratory, Indiana University (2005) 3. Aamir Shafi (2005 - 2008) 4. Bryan Carpenter (2005 - 2008) 5. Mark Baker (2005 - 2008) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * File : SimplePacker@Type@.java * Author : Aamir Shafi, Bryan Carpenter * Created : Fri Sep 10 12:22:15 BST 2004 * Revision : $Revision: 1.7 $ * Updated : $Date: 2005/07/29 14:03:10 $ */ package mpi; import mpjbuf.*; public class SimplePacker@Type@ extends SimplePacker{ public SimplePacker@Type@(int numEls) { super(numEls); } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { @WRITEBUF(mpjbuf)@.write((@type@ []) buf, offset, numEls) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset) throws MPIException { try { @READBUF(mpjbuf)@.read((@type@ []) buf, offset, numEls) ; } catch(Exception e) { throw new MPIException(e); } } public void unpackPartial(mpjbuf.Buffer mpjbuf, int length, Object buf, int offset) throws MPIException { try { @READBUF(mpjbuf)@.read((@type@ []) buf, offset, length) ; } catch(Exception e) { throw new MPIException(e); } } public void pack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { try { @WRITEBUF(mpjbuf)@.write((@type@ []) buf, offset, count * numEls) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, Object buf, int offset, int count) throws MPIException { try { @READBUF(mpjbuf)@.read((@type@ []) buf, offset, count*numEls ) ; } catch(Exception e) { throw new MPIException(e); } } public void unpack(mpjbuf.Buffer mpjbuf, int length, Object buf, int offset, int count) throws MPIException { if(count * numEls < length) { throw new MPIException ("Error in SimplePacker : count <"+ (count*numEls)+"> is less than length <"+length+">"); } try { @READBUF(mpjbuf)@.read((@type@ []) buf, offset, length) ; }catch(Exception e){ throw new MPIException(e); } } } mpj-v0_38/src/mpi/generate.pl0000664000000000000000000001164610516704527014723 0ustar rootroot#!/usr/bin/perl # File : generate.pl # Author : Bryan Carpenter # Created : Thu Jul 15 10:44:32 BST 2004 # Revision : $Revision: 1.4 $ # Updated : $Date: 2005/08/16 21:44:02 $ #logical types # Numeric types @ntypes = ('byte', 'short', 'int', 'long', 'char', 'float', 'double') ; @nTypes = ('Byte', 'Short', 'Int', 'Long', 'Char', 'Float', 'Double') ; @nTYPES = ('BYTE', 'SHORT', 'INT', 'LONG', 'CHAR', 'FLOAT', 'DOUBLE') ; # Logical types ..only boolean ..and even boolean is represented @ltypes = ('boolean'); @lTypes = ('Boolean'); @lTYPES = ('BOOLEAN'); # in Java bit-wise operations cannot be applied to double and float ... @btypes = ('byte', 'short', 'int', 'long', 'char'); @bTypes = ('Byte', 'Short', 'Int', 'Long', 'Char'); @bTYPES = ('BYTE', 'SHORT', 'INT', 'LONG', 'CHAR'); # another category for minloc and maxloc operations ... @mtypes = ('short', 'int', 'long', 'float', 'double'); @mTypes = ('Short', 'Int', 'Long', 'Float', 'Double'); @mTYPES = ('SHORT', 'INT', 'LONG', 'FLOAT', 'DOUBLE'); @smallest = ('Byte.MIN_VALUE', 'Short.MIN_VALUE', 'Integer.MIN_VALUE', 'Long.MIN_VALUE', 'Character.MIN_VALUE', 'Float.NEGATIVE_INFINITY', 'Double.NEGATIVE_INFINITY') ; @largest = ('Byte.MAX_VALUE', 'Short.MAX_VALUE', 'Integer.MAX_VALUE', 'Long.MAX_VALUE', 'Character.MAX_VALUE', 'Float.POSITIVE_INFINITY', 'Double.POSITIVE_INFINITY') ; # Primitive types @ptypes = (@ntypes, 'boolean') ; @pTypes = (@nTypes, 'Boolean') ; @pTYPES = (@nTYPES, 'BOOLEAN') ; # General types @types = (@ptypes, 'Object') ; @Types = (@pTypes, 'Object') ; @TYPES = (@pTYPES, 'OBJECT') ; # Root names for classes generated by simple templates over primitive types #@mroots = ('Minloc','Maxloc') ; @lroots = ('Land', 'Lor', 'Lxor') ; @nroots = ('Max','Min','Sum','Prod'); @broots = ('Bxor','Bor','Band'); # Root names for classes generated by simple templates over general types @groots = ('SimplePacker', 'MultistridedPacker', 'GatherPacker'); #foreach $root (@mroots) { # $template = "${root}Type.java.in" ; # for ($i = 0 ; $i < @mtypes ; $i++) { # $type = $mtypes [$i] ; # $Type = $mTypes [$i] ; # $TYPE = $mTYPES [$i] ; # makeSimple("${root}${Type}", $type, $Type, $TYPE, 'false', # $template) ; #} #} foreach $root (@lroots) { $template = "${root}Type.java.in" ; for ($i = 0 ; $i < @ltypes ; $i++) { $type = $ltypes [$i] ; $Type = $lTypes [$i] ; $TYPE = $lTYPES [$i] ; makeSimple("${root}${Type}", $type, $Type, $TYPE, 'false', $template) ; } } foreach $root (@broots) { $template = "${root}Type.java.in" ; for ($i = 0 ; $i < @btypes ; $i++) { $type = $btypes [$i] ; $Type = $bTypes [$i] ; $TYPE = $bTYPES [$i] ; makeSimple("${root}${Type}", $type, $Type, $TYPE, 'false', $template) ; } } foreach $root (@nroots) { $template = "${root}Type.java.in" ; for ($i = 0 ; $i < @ntypes ; $i++) { $type = $ntypes [$i] ; $Type = $nTypes [$i] ; $TYPE = $nTYPES [$i] ; makeSimple("${root}${Type}", $type, $Type, $TYPE, 'false', $template) ; } } foreach $root (@groots) { $template = "${root}Type.java.in" ; for ($i = 0 ; $i < @ptypes ; $i++) { $type = $ptypes [$i] ; $Type = $pTypes [$i] ; $TYPE = $pTYPES [$i] ; makeSimple("${root}${Type}", $type, $Type, $TYPE, 'false', $template) ; } makeSimple("${root}Object", 'Object', 'Object', 'OBJECT', 'true', $template) ; } sub makeSimple { local $name = $_[0] ; local $type = $_[1] ; local $Type = $_[2] ; local $TYPE = $_[3] ; local $isObject = $_[4] ; local $template = $_[5] ; local $target = "${name}.java" ; open(TEMPLATE, $template) or die "Can't open $template: $!\n" ; open(TARGET, ">$target") or die "Can't create $target: $!\n" ; print TARGET "/* This file generated automatically ", "from template $template. */\n" ; while($line =