Example #1
0
int recvFilterData(FilterData *fData) {
	int bufId;
	int i, l, toFilter;
	char *cwd = (char *)malloc(MAX_CWD_LENGTH+1);
	int num = 0;
	int *tids = (int *)malloc(sizeof(int)*MAXINSTANCES);
	char *filterName         = (char *)malloc(MAX_FNAME_LENGTH);
	char *libName            = (char *)malloc(MAX_LNAME_LENGTH);
	char *hostname           = (char *)malloc(MAX_HNAME_LENGTH);
	char *labelStreamLibname = (char *)malloc(MAX_LNAME_LENGTH);

	int parentTid = pvm_parent();

#ifdef ATTACH
	// if im using attach i dont no if the
	// manager process is realy my father
	bufId = pvm_recv(-1, 0);
	int bytes, msgtag,tid;
	pvm_bufinfo(bufId, &bytes, &msgtag, &tid );
	printf("recvFilterData: bytes = %d msgtag = %d tid = %d\n", bytes, msgtag, tid);
#else
	//We receive one message with all data in it
	bufId = pvm_recv(parentTid, 0);
#endif
	//get the current working directory
	pvm_upkint(&l, 1, 1);
	pvm_upkbyte(cwd, l, 1);
	cwd[l] = '\0';
#ifdef DEBUG	
	printf("cwd = %s\n",cwd);
#endif	

	// filter id, useful for debugging
	pvm_upkint(&num, 1, 1);
	setFDIdFilter(fData, num);
	// get my rank
	pvm_upkint(&num, 1, 1);
	setFDRank(fData, num);
	// total number of instances of this filter
	pvm_upkint(&num, 1, 1);
	setFDNumInstances(fData, num);
	// get my brothers tids
	pvm_upkint(tids, num, 1);
	setFDTids(fData, tids);
#ifdef ATTACH
	// getting my parent Tid because if i'm a attached filter
	// i can be adopted for anyone.. so we do it for all filters..
	// just to make the code easy to understand..
	pvm_upkint(&parentTid, 1, 1);
	int attached;
	pvm_upkint(&attached, 1, 1);
	setFDAttached(fData, attached);
#endif
	// if you are not using Attach the parentTid still the same
	// or its equal to pvm_parent()
	setFDParentTid(fData, parentTid);

#ifdef BMI_FT
	int faultStatus, lastFilter;
	pvm_upkint(&faultStatus, 1, 1);
	setFDFaultStatus(fData, faultStatus);

	pvm_upkint(&lastFilter, 1, 1);
	setFDLastFilter(fData, lastFilter);
#endif

	// filtername
	pvm_upkint(&l, 1, 1);
	pvm_upkbyte(filterName, l, 1);
	filterName[l] = '\0';
	setFDName(fData, filterName);

	//machine declared memory: -1 autodetect, declared on XML
	pvm_upkint(&num, 1, 1);
	setFDMachineMem(fd, num);

	//number of brothers(+ me) I have on this machine, useful for memory management
	pvm_upkint(&num, 1, 1);
	setFDNumLocalInstances(fd, num);

#ifdef VOID_INST
	char instDir[MAX_IDIR_LENGTH];
	pvm_upkint(&l, 1, 1);
	pvm_upkbyte(instDir, l, 1);
	instDir[l] = '\0';
	setFDInstDir(fd, instDir);
#endif

	// receives shared lib name
	pvm_upkint(&l, 1, 1);
	pvm_upkbyte(libName, l, 1);
	libName[l] = '\0';
	setFDLibName(fData, libName);
	/*if (loadFDLibFunctions(fData) == -1){
	  char msg[1000];
	  sprintf(msg, "could not load shared library %s", libName);
	  pvm_initsend(PvmDataRaw);

	  pvm_pkbyte(msg, strlen(msg), 1);
	  pvm_send(pvm_parent(), MSGT_FERROR);
	  return -1;
	  }*/

	// set hostname
	gethostname(hostname, MAX_HNAME_LENGTH);
	setFDHostName(fData, hostname);

	// data received till now
	fprintf(stderr,"filter %s (rank: %d): pvm_tid:%d hostname:%s\n",
			fData->name, fData->myRank, pvm_mytid(), fData->hostName);

	//port data
	//Receive numOutputs
	pvm_upkint(&num, 1, 1);
	setFDNumOutputs(fData, num);
	//receive numInputs
	pvm_upkint(&num, 1, 1);
	setFDNumInputs(fData, num);

	// for each OutputPort
	for(i = 0; i < fData->numOutputPorts; i++) {
		int nOutHosts = 0, tag = 0;
		int numToSend;
		int *outTids  = NULL;
		int firstInstanceToWrite;
		char *portName = (char *)malloc(MAX_PTNAME_LENGTH + 1);
		char *writePolicyName = (char *)malloc(100);
		writePolicy_t wp;

		OutputPort *outputPort;

		pvm_upkint(&numToSend, 1, 1);
		//now we can create the port
		outputPort = createOutputPort(numToSend);

		//port data
		pvm_upkint(&l, 1, 1);
		pvm_upkbyte(portName, l, 1);  //portname
		portName[l] = '\0';
		setOPName(outputPort, portName);

		pvm_upkint(&tag, 1, 1); //get tag
		setOPTag(outputPort, tag);

		for( toFilter = 0; toFilter < numToSend; toFilter++ )
		{
			pvm_upkint(&nOutHosts, 1, 1); //number of tids it is connected

			setOPNumDestinations(outputPort, toFilter, nOutHosts);
			outTids = (int *) malloc(sizeof(int)*nOutHosts);
			pvm_upkint(outTids, nOutHosts, 1); //get tids
			setOPTidsDestinations(outputPort, toFilter, outTids);

			pvm_upkint(&l, 1, 1);
			pvm_upkbyte(writePolicyName, l, 1); // get write policy
			writePolicyName[l] = '\0';
			wp = getWritePolicyByName(writePolicyName);
			setOPWritePolicy(outputPort, toFilter, wp);

			// get LS sharedlib if policy is LS
			if (wp  == LABELED_STREAM ){
				pvm_upkint(&l, 1, 1);
				pvm_upkbyte(labelStreamLibname, l, 1);
				labelStreamLibname[l] = '\0';
				//set output port library name
				setOPLibName(outputPort, toFilter, labelStreamLibname);
				//load output port library for ls
				if (loadOPLSData(outputPort, toFilter) == -1 ){
					char msg[1000];
					sprintf(msg, "could not load LS shared library %s", labelStreamLibname);
					pvm_initsend(PvmDataRaw);

					pvm_pkbyte(msg, strlen(msg), 1);
					pvm_send(pvm_parent(), MSGT_FERROR);
					return -1;
				}
			}
			else if (wp == MULTICAST_LABELED_STREAM) {
				pvm_upkint(&l, 1, 1);
				pvm_upkbyte(labelStreamLibname, l, 1);
				labelStreamLibname[l] = '\0';
				//set output port library name
				setOPLibName(outputPort, toFilter, labelStreamLibname);
				//load output port library for ls
				if (loadOPMLSData(outputPort, toFilter) == -1){
					char msg[1000];
					sprintf(msg,"could not load MLS shared library %s", labelStreamLibname);
					pvm_initsend(PvmDataRaw);

					pvm_pkbyte(msg, strlen(msg), 1);
					pvm_send(pvm_parent(), MSGT_FERROR);
					return -1;
				}
			}
			else {
				//if not LS, we needa know who will be the first instance to receive msgs
				pvm_upkint(&firstInstanceToWrite, 1, 1); //the first instance to write
				setOPNextToSend(outputPort, toFilter,  firstInstanceToWrite);
			}

		}

		// and we finally add the port to our filterData structure
		addFDOutputPort(fData, outputPort);

		//free pointers
		free(outTids);
		free(portName);
		free(writePolicyName);
	}

	// foreach InputPort
	for(i = 0; i < fData->numInputPorts; i++) {
		int nInHosts = 0;
		int *inTids  = NULL;
		int inTag;
		char portName[MAX_PTNAME_LENGTH + 1];
		int l;

		InputPort *inputPort =  createInputPort();

		//get the portName
		pvm_upkint(&l, 1, 1);
		pvm_upkbyte(portName, l, 1);
		portName[l] = '\0';
		setIPName(inputPort, portName);

		// receive the number of tids of this port
		pvm_upkint(&nInHosts, 1, 1); // number of instances connected to this port
		setIPNumSources(inputPort, nInHosts);

		// get the tids
		inTids = (int *) malloc(sizeof(int)*nInHosts);
		pvm_upkint(inTids, nInHosts, 1); //get tids
		setIPTidsSources(inputPort, inTids);
		free(inTids);

		pvm_upkint(&inTag, 1, 1); //the port tag
		setIPTag(inputPort, inTag);
		int hasLabel;
		pvm_upkint(&hasLabel, 1, 1);

		toFilter = 0;
		// if it receives from a LS or MLS we have to have the library with
		// the function that extracts the label
		if (hasLabel){
			setIPLS(inputPort, 1);
			pvm_upkint(&l, 1, 1);
			pvm_upkbyte(labelStreamLibname, l, 1);
			labelStreamLibname[l] = '\0';
			//set output port library name
			setIPLibName(inputPort, toFilter, labelStreamLibname);
			//load output port library for ls
			if (loadIPLSData(inputPort, toFilter) == -1 ){
				char msg[1000];
				sprintf(msg, "could not load LS shared library %s", labelStreamLibname);
				pvm_initsend(PvmDataRaw);

				pvm_pkbyte(msg, strlen(msg), 1);
				pvm_send(pvm_parent(), MSGT_FERROR);
				return -1;
			}
		}

		//finally add the port to our filterData
		addFDInputPort(fData, inputPort);
	}


	free(tids);
	free(hostname);
	free(filterName);
	free(libName);
	free(labelStreamLibname);

	return 1;
}
Example #2
0
GendatChecker::GendatChecker(const std::string &shmname, const std::string &name, int moduleID)
    : Module("GendatChecker", shmname, name, moduleID) {

    createOutputPort("grid_in");
    createOutputPort("data_in");
}