import java.io.*; import java.util.*; import java.lang.*; /**This class creates the PE world according to a configuration file provided by the *simulation application programmer. It parses the configuration file, decides how many *LPs each PE should create and send the detailed LP information to those PEs. Application *programmer can overwrite it. * *@version 1.1 (02/2006) *@author Yin Xiong */ public class Creator{ /**vector that holds the LP config information*/ Vector simClasses =new Vector(); /**vector that holds the global routing into*/ Vector gns=new Vector(); /**number of LPs the first PE will create; =lpForEach+remainder*/ int lpForFirst; /**number of LPs all the other PEs will create*/ int lpForEach; /**the number of PEs in this mpi world*/ int numPEs; /**Create the simulation world using a configuration file. *@param configFile String indicating the name of the configuration file. *@param size int the size of the mpi world, e.g. number of PEs. */ public void procConfigFile(String configFile, int size) { //read configuration file to decide how many instance for each class need to be created try{ String newline=null; BufferedReader bf=new BufferedReader(new FileReader(configFile)); StringTokenizer st; String id, name, className, dat; numPEs=size; //each line is of the format: id obj data while((newline=bf.readLine())!=null){ //System.out.println(" " + newline); st=new StringTokenizer(newline, "\t"); if(st.countTokens()>0){ id= st.nextToken(); //trim id id=id.trim(); if(!id.equals("*")){ name=st.nextToken(); className=st.nextToken(); dat=st.nextToken(); LPConfigInfo lpcInfo=new LPConfigInfo(id,name, className,dat); simClasses.add(lpcInfo); RoutingInfo rinfo=new RoutingInfo(0,0,id); gns.add(rinfo); }//end if count of tokens >0 } }//end while bf.close(); }//end try catch(Exception e){ e.printStackTrace(); } //computes number of LPs for the first PE and for each of the rest int numLPs=simClasses.size(); int rmder=numLPs%(numPEs-1); lpForEach=numLPs/(numPEs-1); lpForFirst=lpForEach+rmder; System.out.println("in creator,numLPs,numPEs: " + numLPs+ " " + numPEs); System.out.println("in creator: " + rmder + " " +lpForEach + " " + lpForFirst); }//end procConfigFile public Vector getLPConfigInfo() { return simClasses; } public int getLPNumForFirst() { return lpForFirst; }//end getLPNumForFirst public int getLPNumForEach() { return lpForEach; }//end getLPForNumEach public void sendLPInfo() { }//end sendLPInfo }//end Creator