Top Up Prev Next Bottom Contents Index Search

18.7 Class CGCMultiTarget


Class CGCMultiTarget, derived from CGSharedBus class, models multiple Unix machines connected together via Ethernet. We use socket mechanism for interprocessor communication. Since the communication overhead is huge, we do not gain any speed up for small examples. Nonetheless, we can test and verify the procedure of multiprocessor code generation.

This class has five private states as follows.

IntState doCompile; 
IntState doRun;
If these states are set YES, we compile and run the generated code.

StringState machineNames; 
StringState nameSuffix;
We list the machine names separated by commas. If all machines names listed have the same suffix, we separate that suffix in the second state. For example, if machineName is "ohm" and nameSuffix is ".berkeley.edu", we mean machine named "ohm.berkeley.edu".

IntState portNumber; 
To make socket connections, we assign port numbers that are available. For now, we set the starting port number with this state. We will increase this number by one every time we add a new connection. Therefore, it should be confirmed that these assigned port numbers should be available. If the Ptolemy program is assigned a port number in the future, then we will be able to let the system choose the available port number for each connection.

With the given list of machine names, we prepare a data structure called MachineInfo that pairs the machine name and internet address.

class MachineInfo {
friend class CGCMultiTarget;
const char* inetAdddrr; // internet address
const char* nm; // machine name
public:
MachineInfo: inetAddr(0), nm(0) { }
}
This class has a constructor with three argument like its base classes. The destructor deallocates MachineInfo arrays if allocated. It has makeNew method and isA method redefined.

18.7.1 CGCMultiTarget protected members

void setup(); 
If the child targets are inherited, we also inherit the machine information. Otherwise, we set up the machine information. The number of processors and the number of machines names should be equal. Then, we call CGMultiTarget::setup for normal setup operation . At last, we set the hostName state of child targets with the machine names.

int wormLoadCode(); 
This method do nothing if doCompile state is NO. Otherwise, it compiles the code for all child targets (compileCode). Then, it checks whether doRun state is YES or NO. If it is YES, we execute the code.

int sendWormData(PortHole& p); 
int receiveWormData(PortHole& p);
int sendWormData();
int receiveWormData();
These method should be redefined in the future to support wormhole interface. Currently, they do same tasks with the base Target classes.

18.7.2 CGCMultiTarget public members

MachineInfo* getMachineInfo(); 
int* getPortNumber();
These methods return the current machine information and the next port number to be assigned.

DataFlowStar* createSend(int from, int to, int num); 
DataFlowStar* createReceive(int from, int to, int num);
The above methods create CGCUnixSend and CGCUnixReceive stars for communication stars with TCP protocol.

void pairSendReceive(DataFlowStar* snd, DataFlowStar* rcv); 
This method pairs a UnixSend star and a UnixReceive star to make a connection. We assign a port number to the connection. More important task is to generate function calls in the initialization code (commInit stream) of two child targets which these communication stars belong to. These functions will make a TCP connection between two child targets with the assigned port number. The UnixSend star will call connect function while the UnixReceive star will call listen function.

void setMachineAddr(CGStar* snd, CGStar* rcv); 
This method informs the snd star about the internet address of the machine that the rcv star is scheduled on. The address is needed in connect function.

void signalCopy(int flag); 
By giving a non-zero value as the argument, we indicate that the code will be duplicated in different set of processors so that we need to adjust the machine information of communication stars.

void prepCode(Profile* pf, int nP, int numChunk); 
This method is also used to allow code replication into different set of targets.

DataFlowStar* createCollect(); 
DataFlowStar* createSpread();
These methods create CGCCollect and CGCSpread stars.



Top Up Prev Next Bottom Contents Index Search

Copyright © 1990-1997, University of California. All rights reserved.