void rel_output (rel_t *r) { if (r->outputEOF) { return; } int buff = conn_bufspace(r->c); int dataOut = 0; while (outputCheck (r, dataOut, buff)) { int currentOut = ntohs(r->receiverBuff->packet->len) - 16 - r->recvBuffOffset; if (currentOut == 0 || currentOut < 0) { break; } if (buff > dataOut + currentOut) { char* start_of_data = r->receiverBuff->packet->data + r->recvBuffOffset; conn_output(r->c, start_of_data, currentOut); dequeue(&r->receiverBuff); dataOut += currentOut; } else{ currentOut = buff - dataOut; char* start_of_data = r->receiverBuff->packet->data + r->recvBuffOffset; conn_output(r->c, start_of_data, currentOut); r->recvBuffOffset += currentOut; dataOut += currentOut; } } }
/**************************************************************** * * Function: main * Input: int argc number of command line arguements * char **arg pointer to those arguements * * Output: int 0 for success and 1 for error * * Description: Runs the prefix and suffix algorithm multiple * times averaging the results and printing them to terminal. * *****************************************************************/ int main(int argc, char **argv) { struct timeval startt, endt, result; double cpu_time_used; char name[16] = "seq"; int status; int n; int* A; int* P; int* S; int RUNS; //Check if app was given enough input if(argc < 6){ printf("Missing Arguement Parameters\n"); printf("Format ./seq file_path array_size P_ans_path S_ans_Path RUNS\n"); return 1; } //Save args to memory and allocate memory for arrays n = atoi(argv[2]); RUNS = atoi(argv[5]); A = malloc(n*sizeof(int)); P = malloc(n*sizeof(int)); S = malloc(n*sizeof(int)); if(A==NULL){ printf("Failed to Allocate Memory for Input Array"); } //Read the input array from file and save to memory status = read_input(A, n, argv[1]); if(status){ printf("Failed to Read Input \n"); return 1; } //Start of testing of the algorithm int j; double average; for(j=0; j<RUNS; j++){ /*Start Timer*/ result.tv_sec=0; result.tv_usec=0; gettimeofday (&startt, NULL); psMin(A, P, S, n); /*Stop Timer*/ gettimeofday (&endt, NULL); result.tv_usec = (endt.tv_sec*1000000+endt.tv_usec) - (startt.tv_sec*1000000+startt.tv_usec); average += result.tv_usec; } average = average/RUNS; //Average the execution times //print results to terminal printf("%d %f us \n",n,average); //Check to see if answer is correct if told to do so in the input args if((atoi(argv[3])!=1) && (atoi(argv[4])!=1)) { status = outputCheck(P, S, argv[3], argv[4], n); if(status){ printf("Incorrect Answer\n"); } else{ printf("Correct Answer\n"); } } /*Output Results for small N*/ if(n<=50){ status = write_output(P, S, n, name); if(status){ printf("Failed to Write Output \n"); return 1; } } /*Free allocated memory*/ free(P); free(S); free(A); /*Used to generate random data sets and save to disk as text files*/ //generateArrays(); return 0; }
void GenericOCIO::changedParam(const OFX::InstanceChangedArgs &args, const std::string ¶mName) { assert(_created); #ifdef OFX_IO_USING_OCIO if (paramName == kOCIOParamConfigFile) { // compute canonical inputSpace and outputSpace before changing the config, // if different from inputSpace and outputSpace they must be set to the canonical value after changing ocio config std::string inputSpace; getInputColorspaceAtTime(args.time, inputSpace); std::string inputSpaceCanonical = canonicalizeColorSpace(_config, inputSpace); if (inputSpaceCanonical != inputSpace) { _inputSpace->setValue(inputSpaceCanonical); } std::string outputSpace; getOutputColorspaceAtTime(args.time, outputSpace); std::string outputSpaceCanonical = canonicalizeColorSpace(_config, outputSpace); if (outputSpaceCanonical != outputSpace) { _outputSpace->setValue(outputSpaceCanonical); } loadConfig(); // re-load the new OCIO config //if inputspace or outputspace are not valid in the new config, reset them to "default" if (_config) { std::string inputSpaceName; getInputColorspaceAtTime(args.time, inputSpaceName); int inputSpaceIndex = _config->getIndexForColorSpace(inputSpaceName.c_str()); if (inputSpaceIndex < 0) { _inputSpace->setValue(OCIO_NAMESPACE::ROLE_DEFAULT); } } inputCheck(args.time); if (_config) { std::string outputSpaceName; getOutputColorspaceAtTime(args.time, outputSpaceName); int outputSpaceIndex = _config->getIndexForColorSpace(outputSpaceName.c_str()); if (outputSpaceIndex < 0) { _outputSpace->setValue(OCIO_NAMESPACE::ROLE_DEFAULT); } } outputCheck(args.time); if (!_config && args.reason == OFX::eChangeUserEdit) { std::string filename; _ocioConfigFile->getValue(filename); _parent->sendMessage(OFX::Message::eMessageError, "", std::string("Cannot load OCIO config file \"") + filename + '"'); } } else if (paramName == kOCIOHelpButton || paramName == kOCIOHelpLooksButton || paramName == kOCIOHelpDisplaysButton) { std::string msg = "OpenColorIO Help\n" "The OCIO configuration file can be set using the \"OCIO\" environment variable, which should contain the full path to the .ocio file.\n" "OpenColorIO version (compiled with / running with): " OCIO_VERSION "/"; msg += OCIO_NAMESPACE::GetVersion(); msg += '\n'; if (_config) { std::string configdesc = _config->getDescription(); configdesc = whitespacify(trim(configdesc)); if ( configdesc.size() > 0 ) { msg += "\nThis OCIO configuration is "; msg += configdesc; msg += '\n'; } msg += '\n'; if (paramName == kOCIOHelpLooksButton) { msg += (_config->getNumLooks() <= 0 ? "No look available in this OCIO configuration.\n" : "Available looks in this OCIO Configuration (applied in the given colorspace):\n"); for (int i = 0; i < _config->getNumLooks(); ++i) { const char* lkname = _config->getLookNameByIndex(i); OCIO_NAMESPACE::ConstLookRcPtr lk = _config->getLook(lkname); msg += "- "; msg += lkname; std::string lkspace = lk->getProcessSpace(); msg += " (" + lkspace + ")\n"; } msg += '\n'; } if (paramName == kOCIOHelpDisplaysButton) { if (_config->getNumDisplays() <= 0) { msg += "No display available in this OCIO configuration.\n"; } else { msg += "Available displays and views in this OCIO Configuration:\n"; std::string defaultdisplay = _config->getDefaultDisplay(); for (int i = 0; i < _config->getNumDisplays(); ++i) { const char* display = _config->getDisplay(i); msg += "- "; msg += display; if (display == defaultdisplay) { msg += " (default)"; } int numViews = _config->getNumViews(display); if (numViews <= 0) { msg += ", no view available.\n"; } else { msg += ", views: "; std::string defaultview = _config->getDefaultView(display); for (int j = 0; j < numViews; ++j) { const char* view = _config->getView(display, j); msg += view; if (view == defaultview) { msg += " (default)"; } if (j < numViews-1) { msg += ", "; } } msg += '\n'; } } } msg += '\n'; } msg += "Available colorspaces in this OCIO Configuration:\n"; int defaultcs = _config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_DEFAULT); int referencecs = _config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_REFERENCE); int datacs = _config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_DATA); int colorpickingcs = _config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_COLOR_PICKING); int scenelinearcs = _config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_SCENE_LINEAR); int compositinglogcs = _config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_COMPOSITING_LOG); int colortimingcs = _config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_COLOR_TIMING); int texturepaintcs = _config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_TEXTURE_PAINT); int mattepaintcs = _config->getIndexForColorSpace(OCIO_NAMESPACE::ROLE_MATTE_PAINT); for (int i = 0; i < _config->getNumColorSpaces(); ++i) { const char* csname = _config->getColorSpaceNameByIndex(i);; OCIO_NAMESPACE::ConstColorSpaceRcPtr cs = _config->getColorSpace(csname); msg += "- "; msg += csname; bool first = true; //int roles = 0; if (i == defaultcs) { msg += first ? " (" : ", "; msg += OCIO_NAMESPACE::ROLE_DEFAULT; first = false; //++roles; } if (i == referencecs) { msg += first ? " (" : ", "; msg += OCIO_NAMESPACE::ROLE_REFERENCE; first = false; //++roles; } if (i == datacs) { msg += first ? " (" : ", "; msg += OCIO_NAMESPACE::ROLE_DATA; first = false; //++roles; } if (i == colorpickingcs) { msg += first ? " (" : ", "; msg += OCIO_NAMESPACE::ROLE_COLOR_PICKING; first = false; //++roles; } if (i == scenelinearcs) { msg += first ? " (" : ", "; msg += OCIO_NAMESPACE::ROLE_SCENE_LINEAR; first = false; //++roles; } if (i == compositinglogcs) { msg += first ? " (" : ", "; msg += OCIO_NAMESPACE::ROLE_COMPOSITING_LOG; first = false; //++roles; } if (i == colortimingcs) { msg += first ? " (" : ", "; msg += OCIO_NAMESPACE::ROLE_COLOR_TIMING; first = false; //++roles; } if (i == texturepaintcs) { msg += first ? " (" : ", "; msg += OCIO_NAMESPACE::ROLE_TEXTURE_PAINT; first = false; //++roles; } if (i == mattepaintcs) { msg += first ? " (" : ", "; msg += OCIO_NAMESPACE::ROLE_MATTE_PAINT; first = false; //++roles; } if (!first /*&& roles > 0*/) { msg += ')'; } std::string csdesc = cs ? cs->getDescription() : "(no colorspace)"; csdesc = whitespacify(trim(csdesc)); if ( !csdesc.empty() ) { msg += ": "; msg += csdesc; msg += '\n'; } else { msg += '\n'; } } } _parent->sendMessage(OFX::Message::eMessageMessage, "", msg); } else if (!_config) { // the other parameters assume there is a valid config return; } else if (paramName == kOCIOParamInputSpace) { assert(_inputSpace); if (args.reason == OFX::eChangeUserEdit) { // if the inputspace doesn't correspond to a valid one, reset to default. // first, canonicalize. std::string inputSpace; getInputColorspaceAtTime(args.time, inputSpace); std::string inputSpaceCanonical = canonicalizeColorSpace(_config, inputSpace); if (inputSpaceCanonical != inputSpace) { _inputSpace->setValue(inputSpaceCanonical); inputSpace = inputSpaceCanonical; } int inputSpaceIndex = _config->getIndexForColorSpace(inputSpace.c_str()); if (inputSpaceIndex < 0) { if (args.reason == OFX::eChangeUserEdit) { _parent->sendMessage(OFX::Message::eMessageWarning, "", std::string("Unknown OCIO colorspace \"")+inputSpace+"\""); } OCIO::ConstColorSpaceRcPtr colorspace = _config->getColorSpace(OCIO_NAMESPACE::ROLE_DEFAULT); if (colorspace) { inputSpace = colorspace->getName(); _inputSpace->setValue(inputSpace); } } } inputCheck(args.time); } #ifdef OFX_OCIO_CHOICE else if ( paramName == kOCIOParamInputSpaceChoice && args.reason == OFX::eChangeUserEdit) { assert(_inputSpace); int inputSpaceIndex; _inputSpaceChoice->getValueAtTime(args.time, inputSpaceIndex); std::string inputSpaceOld; getInputColorspaceAtTime(args.time, inputSpaceOld); std::string inputSpace = canonicalizeColorSpace(_config, _config->getColorSpaceNameByIndex(inputSpaceIndex)); // avoid an infinite loop on bad hosts (for examples those which don't set args.reason correctly) if (inputSpace != inputSpaceOld) { _inputSpace->setValue(inputSpace); } } #endif else if (paramName == kOCIOParamOutputSpace) { assert(_outputSpace); if (args.reason == OFX::eChangeUserEdit) { // if the outputspace doesn't correspond to a valid one, reset to default. // first, canonicalize. std::string outputSpace; getOutputColorspaceAtTime(args.time, outputSpace); std::string outputSpaceCanonical = canonicalizeColorSpace(_config, outputSpace); if (outputSpaceCanonical != outputSpace) { _outputSpace->setValue(outputSpaceCanonical); outputSpace = outputSpaceCanonical; } int outputSpaceIndex = _config->getIndexForColorSpace(outputSpace.c_str()); if (outputSpaceIndex < 0) { if (args.reason == OFX::eChangeUserEdit) { _parent->sendMessage(OFX::Message::eMessageWarning, "", std::string("Unknown OCIO colorspace \"")+outputSpace+"\""); } outputSpace = _config->getColorSpace(OCIO_NAMESPACE::ROLE_DEFAULT)->getName(); _outputSpace->setValue(outputSpace); outputSpaceIndex = _config->getIndexForColorSpace(outputSpace.c_str()); assert(outputSpaceIndex >= 0); } } outputCheck(args.time); } #ifdef OFX_OCIO_CHOICE else if ( paramName == kOCIOParamOutputSpaceChoice && args.reason == OFX::eChangeUserEdit) { assert(_outputSpace); int outputSpaceIndex; _outputSpaceChoice->getValueAtTime(args.time, outputSpaceIndex); std::string outputSpaceOld; getOutputColorspaceAtTime(args.time, outputSpaceOld); std::string outputSpace = canonicalizeColorSpace(_config, _config->getColorSpaceNameByIndex(outputSpaceIndex)); // avoid an infinite loop on bad hosts (for examples those which don't set args.reason correctly) if (outputSpace != outputSpaceOld) { _outputSpace->setValue(outputSpace); } } #endif // OFX_OCIO_CHOICE #endif }
GenericOCIO::GenericOCIO(OFX::ImageEffect* parent) : _parent(parent) , _created(false) #ifdef OFX_IO_USING_OCIO , _ocioConfigFileName() , _ocioConfigFile(0) , _inputSpace(0) , _outputSpace(0) #ifdef OFX_OCIO_CHOICE , _choiceIsOk(true) , _choiceFileName() , _inputSpaceChoice(0) , _outputSpaceChoice(0) #endif , _contextKey1(0) , _contextValue1(0) , _contextKey2(0) , _contextValue2(0) , _contextKey3(0) , _contextValue3(0) , _contextKey4(0) , _contextValue4(0) , _config() #endif { #ifdef OFX_IO_USING_OCIO _ocioConfigFile = _parent->fetchStringParam(kOCIOParamConfigFile); if (_parent->paramExists(kOCIOParamInputSpace)) { _inputSpace = _parent->fetchStringParam(kOCIOParamInputSpace); } if (_parent->paramExists(kOCIOParamOutputSpace)) { _outputSpace = _parent->fetchStringParam(kOCIOParamOutputSpace); } #ifdef OFX_OCIO_CHOICE _ocioConfigFile->getDefault(_choiceFileName); if (_inputSpace) { _inputSpaceChoice = _parent->fetchChoiceParam(kOCIOParamInputSpaceChoice); } if (_outputSpace) { _outputSpaceChoice = _parent->fetchChoiceParam(kOCIOParamOutputSpaceChoice); } #endif loadConfig(); #ifdef OFX_OCIO_CHOICE if (!_config) { # ifndef OFX_OCIO_NOSECRET if (_inputSpace) { _inputSpaceChoice->setIsSecret(true); } if (_outputSpace) { _outputSpaceChoice->setIsSecret(true); } # endif } #endif if (_parent->paramExists(kOCIOParamContextKey1)) { _contextKey1 = _parent->fetchStringParam(kOCIOParamContextKey1); _contextValue1 = _parent->fetchStringParam(kOCIOParamContextValue1); _contextKey2 = _parent->fetchStringParam(kOCIOParamContextKey2); _contextValue2 = _parent->fetchStringParam(kOCIOParamContextValue2); _contextKey3 = _parent->fetchStringParam(kOCIOParamContextKey3); _contextValue3 = _parent->fetchStringParam(kOCIOParamContextValue3); _contextKey4 = _parent->fetchStringParam(kOCIOParamContextKey4); _contextValue4 = _parent->fetchStringParam(kOCIOParamContextValue4); assert(_contextKey1 && _contextKey2 && _contextKey3 && _contextKey4); assert(_contextValue1 && _contextValue2 && _contextValue3 && _contextValue4); } #endif // setup the GUI // setValue() may be called from createInstance, according to // http://openfx.sourceforge.net/Documentation/1.3/ofxProgrammingReference.html#SettingParams inputCheck(0.); outputCheck(0.); _created = true; }
/**************************************************************** * * Function: main * Input: int argc number of command line arguements * char **arg pointer to those arguements * * Output: int 0 for success and 1 for error * * Description: Runs the simple merge algorithm multiple * times averaging the results and printing them to terminal. * *****************************************************************/ int main(int argc, char **argv) { struct timeval startt, endt, result; char name[8] = "posix/"; int status = 0; int n; int* S; int* R; int* P; //Check if app was given enough input if(argc < 6){ printf("Missing Arguement Parameters\n"); printf("Format ./seq path_input input_size ans_Path RUNS MAX_THREADS\n"); return 1; } //Save args to memory and allocate memory for arrays n = atoi(argv[2])+1; RUNS = atoi(argv[4]); MAX_THREADS = atoi(argv[5]); S = malloc(n*sizeof(int)); R = malloc(n*sizeof(int)); P = malloc(n*sizeof(int)); if(S==NULL){ printf("Failed to Allocate Memory for Input Array S"); } if(R==NULL){ printf("Failed to Allocate Memory for Input Array R"); } //Read the input array from file and save to memory status = read_input(S, n, argv[1]); if(status){ printf("Failed to Read Input S\n"); return 1; } /*Declaring Temporary Arrays*/ int *P_temp = malloc(n*sizeof(int)); int *R_temp = malloc(n*sizeof(int)); //Start of testing of the algorithm int j, i; double average; for(j=0; j<RUNS; j++){ memset(R, 0, n*sizeof(int)); memset(P, 0, n*sizeof(int)); /*Start Timer*/ result.tv_sec=0; result.tv_usec=0; gettimeofday (&startt, NULL); int rc; pthread_t thread_id[MAX_THREADS]; pthread_attr_t attr[MAX_THREADS]; int k; for(k=0; k<MAX_THREADS; k++){ pthread_attr_init(&attr[k]); pthread_attr_setdetachstate(&attr[k], PTHREAD_CREATE_DETACHED); } //Initiate the barrier variable for threads pthread_barrier_init (&barrier, NULL, MAX_THREADS); pthread_barrier_init (&init, NULL, MAX_THREADS); /*Setup variables to be passed to threads*/ args input[MAX_THREADS]; for(k=0; k<MAX_THREADS; k++){ input[k].S = S; input[k].R = R; input[k].P = P; input[k].n = n; input[k].id = k; input[k].R_temp = R_temp; input[k].P_temp = P_temp; } /*Initialize the Array in Parrallel*/ jobs.queue1[0] = 0; jobs.queue1[1] = n; jobs.m = ceil(log2(n)); /*Set the number of steps*/ for(k=1; k<MAX_THREADS; k++){ pthread_create(&thread_id[k], &attr[k], &arrayInit, &input[k]); } arrayInit(&input[0]); /*Compute the Distance of each Node*/ jobs.queue1[0] = 0; jobs.queue1[1] = n; for(k=1; k<MAX_THREADS; k++){ pthread_create(&thread_id[k], &attr[k], &nodeLength, &input[k]); } nodeLength(&input[0]); /*Stop Timer*/ gettimeofday (&endt, NULL); result.tv_usec = (endt.tv_sec*1000000+endt.tv_usec) - (startt.tv_sec*1000000+startt.tv_usec); average += result.tv_usec; //Release barrier resources pthread_barrier_destroy(&barrier); pthread_barrier_destroy(&init); } average = average/RUNS; //Average the execution times //print results to terminal printf("%d %f us \n",n-1,average); if(atoi(argv[3])!=1) { status = outputCheck(R, argv[3], n); if(status){ printf("Incorrect Answer\n"); } else{ printf("Correct Answer\n"); } } /*Save the Results if the output is less than 50 elements*/ if(n<=50){ status = write_output(S, R, n, name); } if(status){ printf("Failed to Write Output \n"); return 1; } free(S); free(R); free(P); free(R_temp); free(P_temp); return 0; }
/**************************************************************** * * Function: main * Input: int argc number of command line arguements * char **arg pointer to those arguements * * Output: int 0 for success and 1 for error * * Description: Runs the prefix and suffix algorithm multiple * times averaging the results and printing them to terminal. * * *****************************************************************/ int main(int argc, char **argv) { struct timeval startt, endt, result; char name[16] = "posix"; int status; int n; int* A; int* P; int* S; //Check if app was given enough input if(argc < 7){ printf("Missing Arguement Parameters\n"); printf("Format ./seq file_path array_size P_ans_path S_ans_Path RUNS THREADS\n"); return 1; } //Save args to memory and allocate memory for arrays n = atoi(argv[2]); RUNS = atoi(argv[5]); MAX_THREADS = atoi(argv[6]); A = malloc(n*sizeof(int)); P = malloc(n*sizeof(int)); S = malloc(n*sizeof(int)); if(A==NULL){ printf("Failed to Allocate Memory for Input Array"); } //Read the input array from file and save to memory status = read_input(A, n, argv[1]); if(status){ printf("Failed to Read Input \n"); return 1; } //Start algorithm testing int j; double average; for(j=0; j<RUNS; j++){ /*Start Timer*/ result.tv_sec=0; result.tv_usec=0; gettimeofday (&startt, NULL); //setup the threads and args for threads pthread_t thread_id[MAX_THREADS]; int k; data thread_args[MAX_THREADS]; //figure out the amount of work for each thread int m = n/MAX_THREADS; int rem = n%MAX_THREADS; int allocated=0; //Set the threads to Detached state so they release resources immediately //when terminated pthread_attr_t attribute; pthread_attr_init(&attribute); pthread_attr_setdetachstate(&attribute, PTHREAD_CREATE_DETACHED); //Make sure the number of barriers is correct in case of work is less than //amount of threads available. int numbarriers = MAX_THREADS; if(m==0){ numbarriers = rem; } //Initiate the barrier variable for threads pthread_barrier_init (&barrier, NULL, numbarriers); //Setup all the thread arguements with their respective workloads for(k=0; k<MAX_THREADS; k++){ thread_args[k].A = A; thread_args[k].P = P; thread_args[k].S = S; thread_args[k].n = n; if(rem){ thread_args[k].start = k*m+allocated; thread_args[k].end = (k+1)*m+1+allocated; rem--; allocated++; } else{ thread_args[k].start = k*m+allocated; thread_args[k].end = (k+1)*m+allocated; } thread_args[k].id = k; } //Create all the threads for(k=1; k<MAX_THREADS; k++){ //Check to see if they have work if(thread_args[k].start != thread_args[k].end ) pthread_create(&thread_id[k], &attribute, &psMin, &thread_args[k]); } //Run main thread with arguements psMin(&thread_args[0]); //Release barrier resources pthread_barrier_destroy(&barrier); /*Stop Timer*/ gettimeofday (&endt, NULL); result.tv_usec = (endt.tv_sec*1000000+endt.tv_usec) - (startt.tv_sec*1000000+startt.tv_usec); average += result.tv_usec; } average = average/RUNS; //Find average execution time //Print the results printf("%d %f us \n",n,average); //Check to see if answer is correct if told to do so in the input args if((atoi(argv[3])!=1) && (atoi(argv[4])!=1)) { status = outputCheck(P, S, argv[3], argv[4], n); if(status){ printf("Incorrect Answer\n"); } else{ printf("Correct Answer\n"); } } /*Output Results if N is small*/ if(n<=50){ status = write_output(P, S, n, name); if(status){ printf("Failed to Write Output \n"); return 1; } } //free the memory free(P); free(S); free(A); return 0; }
void semantics(ASTnode* ASTroot){ firstMatrix=1; if(ASTroot==NULL){ return; } int z,noTraverse=0; ASTnode *rows,*l; token bufToken; SymbolTable *tmp; SymbolTableEntryNode *t; int p=0; if(sflag==0){ //first time, main function so create a symbol table for main function sflag=1; S[0]=createSymbolTable(size, NULL, "MAIN");//parentTable of Main is NULL symbolStack=createSymbolStack(); pushSymbolStack(S[0],symbolStack); p=1; counter++; } switch(ASTroot->label){ //Symbol Table creates only in 1, 61, 64 //Symbol table populates in 1:functionDef,31:declarationStmt case 1://make a new symbol table, this would be the scope unless an END is encountered, functionDef InsertSymbolTable(topSymbolStack(symbolStack), ASTroot); S[counter]=createSymbolTable(size, topSymbolStack(symbolStack),ASTroot->array[1]->t.lexeme); pushSymbolStack(S[counter],symbolStack); InsertSymbolTableFun(topSymbolStack(symbolStack), ASTroot);//for input and output arguments of function p=1; counter++; break; case 2://ifstmt S[counter]=createSymbolTable(size, topSymbolStack(symbolStack),"IF"); pushSymbolStack(S[counter],symbolStack); p=1; counter++; break; case 3: noTraverse=1; if(strcmp(topSymbolStack(symbolStack)->symbolTableName,ASTroot->array[0]->t.lexeme)==0){//checking for Recursion semanticError(3,ASTroot->array[0]->t); return; } //check for input parameter list and function signature- input and output tmp=topSymbolStack(symbolStack); while(tmp!=NULL){ z=SearchHashTable(tmp, ASTroot->array[0]->t.lexeme); if(z!=-1) break; else tmp=tmp->parentTable; } if(tmp==NULL){ semanticError(1,ASTroot->t); break; }//declaration of FunId is checked here itself t=findSymbolTableNode(tmp->table[z].next,ASTroot->array[0]->t.lexeme); if(t->type.fid.outputSize!=typeCounter){ semanticError(5,ASTroot->array[0]->t); break; } else{ for(z=0; z<=t->type.fid.outputSize; z++){ if(t->type.fid.output[z]!=type[z]){ semanticError(5,ASTroot->array[0]->t); noTraverse=1; break;//from for } } typeCounter=-1;//successfully implemented. } l=ASTroot->array[1]; for(z=0; z<=t->type.fid.inputSize; z++){ if(l==NULL){ semanticError(5,ASTroot->array[0]->t);//number of output parameters noTraverse=1; break; } if(t->type.fid.input[z]!=findTypeVar(l->array[0])){ semanticError(14,ASTroot->array[0]->t);//type Mismatch noTraverse=1; break; } l=l->array[1]; } break; case 11://else stmt S[counter]=createSymbolTable(size, topSymbolStack(symbolStack),"ELSE"); pushSymbolStack(S[counter],symbolStack); p=1; counter++; break; case 26:if(ASTroot->array[0]->label==67){ t=getSymbolTableNode(ASTroot->array[1]); t->type.id.initialized=1; } case 27: break; case 28: break; //it should not come case 29: break; case 30: break; case 31://declaration stmt InsertSymbolTable(topSymbolStack(symbolStack), ASTroot); return; break; case 51://Assignment noTraverse=1; typeCounter=-1; if(ASTroot->array[1]->label==3){//function call statement if(ASTroot->array[0]->label==54){//single list if(outputCheck1(ASTroot->array[0])==0)//send leaf directly return; //1- it should already have been declared, 2-if so, then it's type should be recorded } else{ //send l if(outputCheck(ASTroot->array[0])==0) return; } semantics(ASTroot->array[1]); } if(ASTroot->array[1]->label==60){//size stmt //1- check if ID is declared, 2- What is the type of ID, 3- Compare with the return type if(!isDeclared(ASTroot->array[1]->array[0])){ semanticError(1,ASTroot->array[1]->array[0]->t); return; } z=findType(ASTroot->array[1]->array[0],0); if(z==57){ if(outputCheck(ASTroot->array[0])==0){//it will populate type of LHS if declared, else returns 0 return; } else{//declared if(!(typeCounter==0&&type[0]==57)) semanticError(6,ASTroot->array[0]->t); return; } } else if(z==58){ if(outputCheck(ASTroot->array[0])==0){//it will populate type of LHS if declared, else returns 0 return; } else{//declared if(!(typeCounter==1&&type[0]==55&&type[1]==55)) semanticError(6,ASTroot->array[0]->t); return; } } else { semanticError(8,ASTroot->array[1]->array[0]->t);//Size contains other that String and Matrix } } if(ASTroot->array[1]->label==37){//Arithmetic Expression l=ASTroot->array[0]; z=findType(l,1); if(l->label==54){ if(z==57){ if(ASTroot->array[1]->array[1]==NULL){ if(ASTroot->array[1]->array[0]->array[1]==NULL){ if(findTypeVar(ASTroot->array[1]->array[0]->array[0])==57){//initialization StringInit(ASTroot->array[0],ASTroot->array[1]->array[0]->array[0]->t.lexeme); return; } } } } else if(z==58){//lhs is matrix firstMatrix=1; if(ASTroot->array[1]->array[1]==NULL){ if(ASTroot->array[1]->array[0]->array[1]==NULL){ if((ASTroot->array[1]->array[0]->array[0]->label)==44){//initialization MatrixInit(ASTroot->array[0],ASTroot->array[1]->array[0]->array[0]); return; } } } } } if(z==-1) break; typeCounter++; type[typeCounter]=z; if((z=findTypeAE(ASTroot->array[1]))!=type[typeCounter]){ bufToken.lineNumber=l->t.lineNumber; semanticError(10,bufToken); break; } //valid Arithmetic expression //debug(); t= getSymbolTableNode(ASTroot->array[0]); t->type.id.initialized=1; typeCounter=-1; } break; case 52://go to case 54 case 54: if(!isDeclared(ASTroot)) semanticError(1,ASTroot->t); break; case 75:// AND case 76:// OR case 77:// LT case 78:// LE case 79:// EQ case 80:// GT case 81:// GE case 82:// NE case 83:// NOTbooleanExpressionSemantics(ASTnode* BE) noTraverse=1; if(booleanExpressionSemantics(ASTroot)==0){ semanticError(10,bufToken); } default: break; }//end of switch int i; if(noTraverse==0){ for( i=0; i<ASTroot->arraySize; i++){ if(ASTroot->array[i]!=NULL){ semantics(ASTroot->array[i]); } } } if(p){ //if popping SymbolTable is a function, then check if it's output parameter are accurately initialised or not tmp=popSymbolStack(symbolStack); if(strcmp(tmp->symbolTableName,"MAIN")!=0&&strcmp(tmp->symbolTableName,"IF")!=0&&strcmp(tmp->symbolTableName,"ELSE")!=0){//it is a function int i; for(i=0; i<tmp->outputParameter; i++){ t=outputParameterInitCheck(tmp,tmp->outputParameterLexeme[i]); if(t->type.id.initialized!=1) { semanticError(13,ASTroot->array[1]->t); break; } } } } }//end of function
void prettyOne(struct psl *psl, struct hash *qHash, struct hash *tHash, struct dlList *fileCache, FILE *f, boolean axt, FILE *checkFile) /* Make pretty output for one psl. Find target and query * sequence in hash. Load them. Output bases. */ { static char *tName = NULL, *qName = NULL; static struct dnaSeq *tSeq = NULL, *qSeq = NULL; struct dyString *q = newDyString(16*1024); struct dyString *t = newDyString(16*1024); int blockIx; int qs, ts; int lastQ = 0, lastT = 0, size; int qOffset = 0; int tOffset = 0; boolean qIsPartial = FALSE; boolean tIsPartial = FALSE; if (qName == NULL || !sameString(qName, psl->qName)) { freeDnaSeq(&qSeq); freez(&qName); qName = cloneString(psl->qName); readCachedSeqPart(qName, psl->qStart, psl->qEnd-psl->qStart, qHash, fileCache, &qSeq, &qOffset, &qIsPartial); if (qIsPartial && psl->strand[0] == '-') qOffset = psl->qSize - psl->qEnd; } if (tName == NULL || !sameString(tName, psl->tName) || tIsPartial) { freeDnaSeq(&tSeq); freez(&tName); tName = cloneString(psl->tName); readCachedSeqPart(tName, psl->tStart, psl->tEnd-psl->tStart, tHash, fileCache, &tSeq, &tOffset, &tIsPartial); } if (tIsPartial && psl->strand[1] == '-') tOffset = psl->tSize - psl->tEnd; if (psl->strand[0] == '-') reverseComplement(qSeq->dna, qSeq->size); if (psl->strand[1] == '-') reverseComplement(tSeq->dna, tSeq->size); for (blockIx=0; blockIx < psl->blockCount; ++blockIx) { qs = psl->qStarts[blockIx] - qOffset; ts = psl->tStarts[blockIx] - tOffset; /* Output gaps except in first case. */ if (blockIx != 0) { int qGap, tGap, minGap; qGap = qs - lastQ; tGap = ts - lastT; minGap = min(qGap, tGap); if (minGap > 0) { writeGap(q, qGap, qSeq->dna + lastQ, t, tGap, tSeq->dna + lastT); } else if (qGap > 0) { writeInsert(q, t, qSeq->dna + lastQ, qGap); } else if (tGap > 0) { writeInsert(t, q, tSeq->dna + lastT, tGap); } } /* Output sequence. */ size = psl->blockSizes[blockIx]; dyStringAppendN(q, qSeq->dna + qs, size); lastQ = qs + size; dyStringAppendN(t, tSeq->dna + ts, size); lastT = ts + size; if(q->stringSize != t->stringSize) { // printf("%d BLK %s q size %d t size %d diff %d qs size %d ts size %d\n",blockIx, psl->qName, q->stringSize, t->stringSize, q->stringSize - t->stringSize, qSeq->size, tSeq->size ); } } if (checkFile != NULL) { outputCheck(psl, qSeq, qOffset, tSeq, tOffset, checkFile); } if (psl->strand[0] == '-' && !qIsPartial) reverseComplement(qSeq->dna, qSeq->size); if (psl->strand[1] == '-' && !tIsPartial) reverseComplement(tSeq->dna, tSeq->size); if(q->stringSize != t->stringSize) { // printf("AF %s q size %d t size %d qs size %d ts size %d\n",psl->qName, q->stringSize, t->stringSize, qSeq->size, tSeq->size ); } //assert(q->stringSize == t->stringSize); if (axt) axtOutString(q->string, t->string, min(q->stringSize,t->stringSize), 60, psl, f); else prettyOutString(q->string, t->string, min(q->stringSize,t->stringSize), 60, psl, f); dyStringFree(&q); dyStringFree(&t); if (qIsPartial) freez(&qName); if (tIsPartial) freez(&tName); }
/**************************************************************** * * Function: main * Input: int argc number of command line arguements * char **arg pointer to those arguements * * Output: int 0 for success and 1 for error * * Description: Runs the simple merge algorithm multiple * times averaging the results and printing them to terminal. * *****************************************************************/ int main(int argc, char **argv) { struct timeval startt, endt, result; char name[8] = "omp/"; int status=0; int n; int* S; int* R; int RUNS; //Check if app was given enough input if(argc < 6){ printf("Missing Arguement Parameters\n"); printf("Format ./seq path_input input_size ans_Path RUNS MAX_THREADS\n"); return 1; } //Save args to memory and allocate memory for arrays n = atoi(argv[2])+1; RUNS = atoi(argv[4]); MAX_THREADS = atoi(argv[5]); S = malloc(n*sizeof(int)); R = malloc(n*sizeof(int)); if(n<50){ chunk = 4; /*For Small N*/ } omp_set_dynamic(0); //Makes sure the number of threads available is fixed omp_set_num_threads(MAX_THREADS); //Set thread number if(S==NULL){ printf("Failed to Allocate Memory for Input Array S"); } if(R==NULL){ printf("Failed to Allocate Memory for Input Array R"); } //Read the input array from file and save to memory status = read_input(S, n, argv[1]); if(status){ #ifdef DEBUG printf("Failed to Read Input S\n"); #endif return 1; } int *P_temp = malloc(n*sizeof(int)); int *R_temp = malloc(n*sizeof(int)); int *P = malloc(n*sizeof(int)); //Start of testing of the algorithm int j; double average; for(j=0; j<RUNS; j++){ memset(R, 0, n*sizeof(int)); /*Start Timer*/ result.tv_sec=0; result.tv_usec=0; gettimeofday (&startt, NULL); /*Start Algorithm*/ nodeLength(S, R, n, P_temp, R_temp, P); /*Stop Timer*/ gettimeofday (&endt, NULL); result.tv_usec = (endt.tv_sec*1000000+endt.tv_usec) - (startt.tv_sec*1000000+startt.tv_usec); average += result.tv_usec; } average = average/RUNS; //Average the execution times //print results to terminal printf("%d %f us \n",n-1,average); if(atoi(argv[3])!=1) { status = outputCheck(R, argv[3], n); if(status){ printf("Incorrect Answer\n"); } else{ printf("Correct Answer\n"); } } /*Save the Results if the output is less than 50 elements*/ if(n<=50){ status = write_output(S, R, n, name); } if(status){ printf("Failed to Write Output \n"); return 1; } free(S); free(R); free(P_temp); free(R_temp); free(P); return 0; }
/**************************************************************** * * Function: main * Input: int argc number of command line arguements * char **arg pointer to those arguements * * Output: int 0 for success and 1 for error * * Description: Runs the simple merge algorithm multiple * times averaging the results and printing them to terminal. * *****************************************************************/ int main(int argc, char **argv) { struct timeval startt, endt, result; char name[8] = "seq/"; int status; int n; int* S; int* R; int RUNS; //Check if app was given enough input if(argc < 5){ printf("Missing Arguement Parameters\n"); printf("Format ./seq path_input input_size ans_Path RUNS\n"); return 1; } //Save args to memory and allocate memory for arrays n = atoi(argv[2])+1; RUNS = atoi(argv[4]); S = malloc(n*sizeof(int)); R = malloc(n*sizeof(int)); if(S==NULL){ printf("Failed to Allocate Memory for Input Array S"); } if(R==NULL){ printf("Failed to Allocate Memory for Input Array R"); } //Read the input array from file and save to memory status = read_input(S, n, argv[1]); if(status){ #ifdef DEBUG printf("Failed to Read Input S\n"); #endif return 1; } //Start of testing of the algorithm int j; double average; for(j=0; j<RUNS; j++){ memset(R, 0, n*sizeof(int)); /*Start Timer*/ result.tv_sec=0; result.tv_usec=0; gettimeofday (&startt, NULL); nodeLength(S, R, n); /*Stop Timer*/ gettimeofday (&endt, NULL); result.tv_usec = (endt.tv_sec*1000000+endt.tv_usec) - (startt.tv_sec*1000000+startt.tv_usec); average += result.tv_usec; } average = average/RUNS; //Average the execution times //print results to terminal printf("%d %f us \n",n-1,average); if(atoi(argv[3])!=1) { status = outputCheck(R, argv[3], n); if(status){ printf("Incorrect Answer\n"); } else{ printf("Correct Answer\n"); } } /*Save the Results if the output is less than 50 elements*/ if(n<=50){ status = write_output(S, R, n, name); } if(status){ printf("Failed to Write Output \n"); return 1; } /*Used to generate the input files for the batch run*/ // generateArrays(); free(S); free(R); return 0; }