static void Welcome(const char *welcomeTextURL) { url u; urlconnection urlconn; URLNewAbsolute(&u, welcomeTextURL); URLConnectionNew(&urlconn, &u); if (urlconn.responseCode / 100 == 3) { Welcome(urlconn.newUrl); } else { streamtokenizer st; char buffer[4096]; STNew(&st, urlconn.dataStream, kNewLineDelimiters, true); while (STNextToken(&st, buffer, sizeof(buffer))) { printf("%s\n", buffer); } printf("\n"); fflush(stdout); STDispose(&st); // remember that STDispose doesn't close the file, since STNew doesn't open one.. } URLConnectionDispose(&urlconn); URLDispose(&u); }
/* * Function: main * ----------------- * Serves as entry point of program. Takes in all user inputs to determine specific boggle configuration. * Then, it gives the user a chance to find words in the boggleBoard. Then, the computer takes over * to find any remaining words. Finally, gives user option to play another round. * *@return 0 if program completed successfully. */ int main() { Randomize(); //initializes random constructor SetWindowSize(8, 5); InitGraphics(); Welcome(); GiveInstructions(); Lexicon wordList("lexicon.dat"); //generates list of all possible words while (true) { Lexicon usedWords; //generates a list that stores all words found by the player and computer InitGraphics(); SoundFeature(); int boardDimension = BoggleBoardSize(); DrawBoard(boardDimension, boardDimension); Grid<char> boggleBoard(boardDimension, boardDimension); if (!UserBoardConfiguration()) { InitializeRandomBoard(boggleBoard); //if user chooses not to specify board configuration, a random one is generated } else { string diceConfig = GetDiceConfiguration(boardDimension); SetDiceConfiguration(boggleBoard, diceConfig); } DrawBoggleBoard(boggleBoard); Grid<bool> usedDice(boggleBoard.numRows(), boggleBoard.numCols()); CreateMarker(usedDice); InputGuesses(boggleBoard, wordList, usedWords, usedDice); //player's turn FindRemainingWords(boggleBoard, wordList, usedWords, usedDice); //computer's turn PlayNamedSound("thats pathetic.wav"); //assumes the player will always lose to the computer if (!GameContinue()) break; } return 0; }
int MyMain() { Welcome(); unsigned long checksum[2] = {-1,-1}; char KEY[8]; printf("REVO WOLF!\n"); printf("Give me your key and overflooooooooooow it,\nI'll Check it.\n"); printf("Looking for keys? find those on STACK OVERFLOW\nTell me your Key: "); scanf("%s", KEY); if (*(unsigned int*)(KEY+0) == 0x7265766f) { if (*(unsigned int*)(KEY+4) == 0x776f6c66) { _asm { xor ecx,ecx mov eax,[checksum+00] xor eax,0x3D504952 add ecx,eax mov eax,[checksum+04] xor eax,0x776f6f6f add ecx,eax test ecx,ecx jnz levelCurrSub } printf("WoW! Your key is correct!\n"); } else printf("Your key must be like an animal....like wolf?\n");
int main(int argc, char **argv) { Welcome(kWelcomeTextFile); hashset stopWords; BuildStopWordsHashset(&stopWords, kDefaultStopWordsFile); hashset wordHash; HashSetNew(&wordHash, sizeof(currWord), 10007, WordHashFn, WordCompare, WordFree); hashset articlesSeen; HashSetNew(&articlesSeen, sizeof(article), 10007, ArticleHashFn, ArticleCompare, ArticleFree); BuildIndices((argc == 1) ? kDefaultFeedsFile : argv[1], &stopWords, &wordHash, &articlesSeen); QueryIndices(&stopWords, &wordHash, &articlesSeen); HashSetDispose(&stopWords); HashSetDispose(&wordHash); HashSetDispose(&articlesSeen); return 0; }
int main(int argc, char **argv) { static const char *stopwordFilename = "/home/compilers/media/assn-4-rss-news-search-data/stop-words.txt"; static const int kStopwordBuckets = 1009; static const int kIndexNumBuckets = 10007; rssData allData; HashSetNew(&allData.stopwords, sizeof(char*), kStopwordBuckets, StringHash, StringCmp, StringFree); HashSetNew(&allData.indices, sizeof(indexEntry), kIndexNumBuckets, IndexHash, IndexCmp, IndexFree); // this vector VectorNew(&allData.explored, sizeof(article), ArticleFree, 10); Welcome(kWelcomeTextFile); ReadStopwords(&allData.stopwords, stopwordFilename); BuildIndices((argc == 1) ? kDefaultFeedsFile : argv[1], &allData ); int hcount = HashSetCount(&allData.indices); printf("hcount: %d\n", hcount); printf("Finished BuildIndices\n"); QueryIndices(&allData); return 0; }
extern "C" void KernelMain() { char charValue = 0; if (VerificaRetorno() == 0) { Welcome(); } ShowPrompt(); for(;;) { char charValue = GetChr(); if (charValue == 13) { DefinirPrograma(); //Printf(); ExecutarPrograma(); ShowPrompt(); } } return; }
static void LoadStopWords(const char *StopWordsTextURL, hashset* stopWords) { url u; urlconnection urlconn; URLNewAbsolute(&u, StopWordsTextURL); URLConnectionNew(&urlconn, &u); if (urlconn.responseCode / 100 == 3) { Welcome(urlconn.newUrl); } else { streamtokenizer st; char buffer[4096]; STNew(&st, urlconn.dataStream, kNewLineDelimiters, true); while (STNextToken(&st, buffer, sizeof(buffer))) { char * copy = strdup(buffer); HashSetEnter(stopWords,©); } STDispose(&st); } URLConnectionDispose(&urlconn); URLDispose(&u); }
int main() { SetWindowSize(9, 5); InitGraphics(); Welcome(); GiveInstructions(); return 0; }
int main() { setlocale(LC_ALL, "Ukrainian"); Welcome(); Enter(); system("pause"); return 0; }
int main (int argc, char **argv) { initscr (); noecho (); Welcome (); Selection (argc, argv); endwin (); return 0; }
void Display::Show() { int nSelect; Begin: Welcome(); while(1) { cin>>nSelect; if(cin.fail()) { ClearScreen(); cout<<"Input Error! Please Select Again!"<<endl; cin.clear(); cin.sync(); goto Begin; } ClearScreen(); switch(nSelect) { case 1: ShowDataStructItems(); break; case 2: ShowAllSortsItems(); case 3: ShowAlgorithmAndPracticalIssuesItems(); break; case 99: exit(0); break; default: ClearScreen(); cout<<"Select Error! Please Select Again!"<<endl; cin.clear(); cin.sync(); Welcome(); break; } } }
int main() { Welcome(); unsigned n=0; POINT* points=NULL; if (!Initialize(&points, &n)) { DoJob(points, &n); free(points); } system("pause"); return 0; }
int main() { int parent_x, parent_y; START: head = (psnakeHead)malloc(sizeof(snakeHead)); head -> length = 0; head -> row = 14; head -> col = 14; head -> pbody = NULL; head -> headdirection = RIGHT; InitSnake(head); initscr(); raw(); /* close row buffer */ cbreak(); /* put termial to CBREAK mode */ noecho(); curs_set(FALSE); /* set cursor invisible */ keypad(stdscr,TRUE); /* recognise user's function key,F1,F2,... display some message about title and wall */ signal(SIGALRM, StartAlarm); getmaxyx(stdscr, parent_y, parent_x); WINDOW *welwin = newwin(29, parent_x, 0, 0); WINDOW *lelwin = newwin(7, parent_x, 30, 0); if (!welwin || !lelwin) { Die("Unable to allocate window memory\n"); } Welcome(welwin, 29, parent_x); int speed = Choice(lelwin); Set_ticker(speed); DrawWalls(); StartAlarm(); foodpos = DisplayFood(head); while(!isfailed && chinput !='q') { chinput = getch(); ControlSnake(chinput, head); } if(isfailed) { ClearScr(LEFT_EDGE+1, RIGHT_EDGE-1, TOP_ROW+1, BUT_ROW-1); //mark free(head -> pbody); free(head); head = NULL; } if(isrestart) { isfailed = 0; isrestart = 0; // clear the flag goto START; // go to the START statement } endwin(); return 0; }
int main(void) { InitConsole(); Welcome(); while (1) { GameMainLoop(); ClearConsoleBuffer(); setConsoleColor(FRED); DrawString((WIDTH - strlen("You are dead")) / 2, HEIGHT / 2, "You are dead"); resetConsoleColor(); RedrawConsole(); while (!IsKeyPressed(VK_RETURN)); } return 0; }
int main(int argc, char **argv) { const char *feedsFileName = (argc == 1) ? kDefaultFeedsFile : argv[1]; rssDatabase db; initThreadsData(&db); //InitThreadPackage(false); Welcome(kWelcomeTextFile); LoadStopWords(&db.stopWords, kDefaultStopWordsFile); BuildIndices(&db, feedsFileName); cleanThreadData(&db); QueryIndices(&db); pthread_exit(NULL); return 0; }
void TScreen::Begin() { // Initialize the touch screen myTouch.InitTouch(); myTouch.setPrecision(PREC_MEDIUM); if (!welcome) Welcome(); // do not modify after //Activate and display screen userBegin(); // starts the interrupts DueTimer::getAvailable().attachInterrupt(myTouchInt).start(TIMER1); // for touch / untouch DueTimer::getAvailable().attachInterrupt(StatInt).start(TIMER2); // for status bar computing DueTimer::getAvailable().attachInterrupt(TimeInt).start(TIMER3);; // for user task and time task Show(); Draw(); }
int main(int argc,char *argv[]){ int choice; Welcome(); scanf("%d",&choice); switch(choice) { case 0:Compress(); break; case 1:Uncompress(); break; case 2: exit(0); break; default :printf(" йДхКспнС"); } }
int main(int argc, char **argv) { hashset stopWords; loadStopWords(&stopWords); hashset prevSeenArticles; initPrevSeenArticles(&prevSeenArticles); hashset wordCounts; initWordCount(&wordCounts); Welcome(kWelcomeTextFile); BuildIndices((argc == 1) ? kDefaultFeedsFile : argv[1], &stopWords, &prevSeenArticles, &wordCounts); wordCountSort(&wordCounts); QueryIndices(&stopWords, &wordCounts); HashSetDispose(&stopWords); HashSetDispose(&prevSeenArticles); HashSetDispose(&wordCounts); return 0; }
char print_menu(char menu[4]) { int y; y = menu_search(menu); printf("\n\n"); Welcome(); printf("\n\n"); if(y == 0) { printf("\t%c[ START GAME ]\n\n",16); } else { printf("\tStart Game\n\n"); } if( y == 1) { printf("\t%c[ OPTION ]\n\n",16); } else { printf("\tOption\n\n"); } if( y == 2) { printf("\t%c[ ABOUT ]\n\n",16); } else { printf("\tAbout\n\n"); } if( y == 3) { printf("\t%c[ EXIT ]\n\n",16); } else { printf("\tExit\n\n"); } printf("\n\t\t\t\t\t\tPress W and S to navigate.\n\n\t\t\t\t\t\tPress Enter to Select.\n"); }
int main() { loop = 1; credits = 10; boolean = 0; setbuf(stdin, NULL); // This disables IO buffering within Eclipse which is needed since it is incapable of doing it correctly setbuf(stdout, NULL); printf("********Welcome to my Slot Machine********\n"); Welcome(); // Runs the Welcome function while( loop == 1) { //======= 5 ======= InputTester(); ColumnResults(); BettingSystem(); AskToPlayAgain(); ContinuePlaying(); } return 0; }
int main(int argc, char **argv) { const char *feedsFileURL = (argc == 1) ? kDefaultFeedsFileURL : argv[1]; Welcome(kWelcomeTextURL); rssFeedData rssFData; CreateDataStructure(&rssFData); LoadStopWords(kDefaultStopWordsURL, &rssFData); //void *found = HashSetLookup(&(rssFData.stopWords), &smstr); BuildIndices(feedsFileURL, &rssFData); //HashSetMap(&(rssFData.articles), ArticleMap, NULL); QueryIndices(&rssFData); DisposeDataStructure(&rssFData); return 0; }
int main() { int choice = -1; int player = 0; bool play = true; while(play) { choice = Welcome(); //main menu switch(choice) { case 0: //exit game entirely play = false; break; case 1: //make game choice = Make(); break; case 2: //join game choice = Join(); break; case 3: //watch game break; case 4: //load game choice = Load(); break; default: break; } if(choice == 0) { play = false; } } return 0; }
RECEIVE(ENTER, id, msg, reliable) { if (!tokenring->authorized()) return; unsigned char team = (unsigned char) (long) msg[1]; string name = msg[2]; Player::Id pid = game.topId++; ObjectHandle player = Player(pid, team, name); game.root->children.insert(player); game.players[pid] = player; nodes[id] = pid; Welcome(pid); // Send game state TeamInfo(id); PlayerInfo(id); StructInfo(id); ItemInfo(id); Join(findNode(pid), pid, team, name); }
int RoundRoom::ProcessInput() { Welcome(); findKey(); String uInput; uInput.ReadFromConsole(); uInput.ToLower(); if (uInput.Equalto("back")) { std::cout << "Valid " << std::endl; return 0; } else { std::cout << "Dead end, try again" << std::endl; system("pause"); return roomID; } return roomID; }
/** * Function: main * -------------- * Serves as the entry point of the full RSS News Feed Aggregator. * * @param argc the number of tokens making up the shell command invoking the * application. It should be either 1 or 2--2 when the used wants to * specify what flat text file should be used to source all of the * RSS feeds. * @param argv the array of one of more tokens making up the command line invoking * the application. The 0th token is ignored, and the 1st one, if present, * is taken to be the path identifying where the list of RSS feeds is. * @return always 0 if it main returns normally (although there might be exit(n) calls * within the code base that end the program abnormally) */ int main(int argc, char **argv) { const char *feedsFileURL = (argc == 1) ? kDefaultFeedsFileURL : argv[1]; Welcome(kWelcomeTextURL); rssFeedData data; CreateDataStructure(&data); LoadStopWords(kDefaultStopWordsURL,&data.stopWords); BuildIndices(feedsFileURL, &data); // tests // HashSetMap(&data.stopWords, StringMap, NULL); // HashSetMap(&data.articles, ArticleMap, NULL); // HashSetMap(&data.indices, IndexMap, NULL); QueryIndices(&data); DisposeData(&data); return 0; }
int SquareRoom::ProcessInput() { Welcome(); std::cout << "You have found a" << " " << Object.Cstr() << std::endl; std::cout << "Type in a keyword to open the " << " " << Object.Cstr() << std::endl; String uInput; uInput.ReadFromConsole(); uInput.ToLower(); while (true) { if (uInput.Equalto("open")) { std::cout << "You win" << std::endl; system("pause"); break; } else { std::cout << "Wrong keyword, try again" << std::endl; system("pause"); uInput.ReadFromConsole(); uInput.ToLower(); } } return 0; }
int main() { while (true) { //initialize Randomize(); Set<string> wordsSeen; Lexicon lex("lexicon.dat"); Grid<string> board(4,4); //changes for 5x5 SetWindowSize(9, 5); InitGraphics(); DrawBoard(4,4); //changes for 5x5 Welcome(); GiveInstructions(); //either set up the board automatically or let the user set it up cout << "Would you like to configure the board? "; string response = GetLine(); response = ConvertToUpperCase(response); if (response == "YES") { UserConfigureBoard(board); } else { InitializeBoard(board); } //have the player play, then the computer PlayerTurn(board, lex, wordsSeen); ComputerTurn(board, lex, wordsSeen); //check if the user wants to play again cout << "Would you like to play again? "; response = GetLine(); response = ConvertToUpperCase(response); if (response != "YES") break; } return 0; }
//--------------------------------------------------// //----------------Funcion Principal-----------------// //--------------------------------------------------// int main(int argc, char **argv) { Welcome(); FILE *P8_12Console= popen("echo high > /sys/class/gpio/gpio44/direction","w"); fclose(P8_12Console); }
int main() { /* VARIABLES */ char *req; //Requête de l'utilisateur char *srvAddress; //Adresse du serveur char *username; //Nom de connexion de l'utilisateur char *password; //Mot de passe de l'utilisateur char *sessionid; //Identifiant de session char *reqRec; //requete reçue en réception int retour; //Variable de retour int again; //variable de boucle char requete[100] = {0}; //requete transmise au serveur /* INITIALISATION DES VARIABLES */ srvAddress = malloc(sizeof(char)*1024); srvAddress = "localhost"; reqRec = malloc(sizeof(char)*1024); sessionid = malloc(sizeof(char)*8); username = NULL; password = NULL; again = EVAL_FALSE; /* DEBUT */ do{ Welcome(); //Affichage de l'interface graphique //Initialisation de la connexion avec le serveur printf("Test de la connexion avec le serveur.\n"); if(Initialisation(srvAddress) != 1) { printf("Le serveur est hors ligne ...\n"); return EXIT_FAILURE; } else { printf("Le serveur est en ligne."); } //puts("Phase de test, on supprime le test de connexion au serveur."); printf("\n**************************************************************\n\n"); /* Saise des identifiants */ retour = DemandeID(&username, &password); if(retour != 0){ return EXIT_FAILURE; } //connectUser(&username, &password); /* Création de la requete de connexion */ strcat(requete,"CONNECT "); strcat(requete,username); strcat(requete," "); strcat(requete,password); strcat(requete,"\n"); printf("%s\n", requete); //Affichage de la requete envoyée /* Envoi des identifiants et récupération du session ID*/ if(Emission(requete)!=1) { printf("Erreur d'émission\n"); return 1; } /* Connexion au service, echec si le sessionID retourné est 1*/ reqRec = Reception(); get_word(reqRec, sessionid,2); printf("%s\n",reqRec ); if(cmp_word(sessionid,"1",1)){ printf("Erreur lors de la réception du session ID : val = %s\n", sessionid); return 1; } /* Traitement du choix de l'utilisateur */ do{ /* Proposition des différents cas et appel des fonctions correspondantes */ again = ChoiceScreen(username, sessionid); }while(again != EVAL_FALSE); }while(1); /* -------------------------------------------------- */ /* if(Emission("Test de req client1.\n")!=1) { printf("Erreur d'�mission\n"); return 1; } req = Reception(); if(req != NULL) { printf("J'ai recu: %s\n", req); free(req); } else { printf("Erreur de r�ception\n"); return 1; } req = Reception(); if(req != NULL) { printf("J'ai recu: %s\n", req); free(req); } else { printf("Erreur de r�ception\n"); return 1; } req = Reception(); if(req != NULL) { printf("J'ai recu: %s\n", req); free(req); } else { printf("Erreur de r�ception\n"); return 1; } Terminaison();*/ /* FIN */ return 0; }
int main (int argc, char *argv[]) { /*data--------- */ int *Geno; /*NUMINDSxLINES: genotypes */ float *R; /*NUMINDS */ float *Mapdistance; /*NUMLOCI */ float *Phase; /*NUMLOCI*NUMINDS */ int *Phasemodel=NULL; /*NUMINDS */ char *Markername; /*GENELEN*NUMLOCI */ struct IND *Individual; /*NUMINDS: records for each individual */ int *Translation; /*NUMLOCIxMAXALLELES: value of each coded allele */ int *NumAlleles; /*NUMLOCI: number of alleles at each locus */ /* only used for recessive or inbreeding models: */ int *PreGeno= NULL; /*NUMINDSxLINESxNUMLOCI; diploid genotype if recessive alleles */ int *Recessive= NULL; /*NUMLOCI recessive allele at each locus, or -1 if there is none */ /*Basic parameters */ int *Z; /*NUMINDSx2xNUMLOCI: Z=pop of origin for each allele */ int *Z1; float *Q; /*NUMINDSxMAXPOPS: Q=ancestry of individuals */ float *P; /*NUMLOCIxMAXPOPSxMAXALLELES: P=population allele freqs */ float *Epsilon; /*NUMLOCIxMAXALLELES: Dirichlet parameter for allele frequencies. This is either LAMBDA (if uncorrelated), or ancestral allele freqs if they are correlated */ float *Fst; /*MAXPOPS: Factor multiplied by epsilon under the Fst model */ float *Alpha; /*MAXPOPS: Dirichlet parameter for degree of admixture. Start this at ALPHA, and possibly change (if INFERALPHA==1) */ float *lambda; /*Dirichlet prior parameter for allele frequencies; start this at LAMBDA, and update if INFERLAMBDA*/ float *sumlambda; /*Summaries */ int *NumLociPop; /*NUMINDSxMAXPOPS: Number of alleles from each pop (by ind) */ float *PSum; /*NUMLOCIxMAXPOPSxMAXALLELES: sum of AlFreqs */ float *QSum; /*NUMINDSxMAXPOPS: sum of Ancestries */ float *FstSum; /*MAXPOPS: Sum of Fst */ float *SumEpsilon= NULL; /*NUMLOCIxMAXALLELES: sum of ancestral allele freqs*/ float *sumAlpha; /*MAXPOPS*/ float *sumR; /*NUMINDS */ float *varR; /*NUMINDS */ float recomblikelihood=0.0; float *like; /*current likelihood value */ float *sumlikes; /*sum of likelihood values */ float *sumsqlikes; /*sum of squared likelihoods */ int *popflags; /*The populationflags of individuals*/ unsigned int *randGens; /*Melissa added 7/12/07 for calculating DIC*/ float *sumIndLikes, *indLikesNorm; int *AncestDist= NULL; /*NUMINDS*MAXPOPS*NUMBOXES histogram of Q values */ float *UsePopProbs= NULL; /*NUMINDS*MAXPOPS*(GENSBACK+1) This is used when the population info is used. It stores the probability that an individual has each of a specified set of ancestry amounts */ /*loop variables-------------- */ int rep; /*MCMC iterations so far */ int savefreq; /*frequency of saving to file */ int ind; /*Melissa's new variables added 7/12/07 to use priors based on sampling location*/ float *LocPrior=NULL, *sumLocPrior=NULL, LocPriorLen=0; /* ======================= GPU Structure ======================== */ /*Dict to that keeps track of CL info */ /*CLDict *clDict = NULL;*/ float * randomArr; /* array of random numbers */ int POPFLAGINDS = 0; float invsqrtnuminds; /* enum BUFFER buffers[5]; */ /* char *names[5]; */ /* size_t sizes[5]; */ /* void *dests[5]; */ float *reduceresult; int *Numafrompopscl; int *Numlocipopscl; if (signal(SIGINT, catch_function) == SIG_ERR) { fputs("An error occurred while setting a signal handler.\n", stderr); return EXIT_FAILURE; } clDict = malloc(sizeof (*clDict)); sumlikes = calloc(1,sizeof(float)); sumsqlikes = calloc(1,sizeof(float)); like = calloc(1,sizeof(float)); /*=====Code for getting started=============================*/ Welcome (stdout); /*welcome */ GetParams (0,argc,argv); /*read in parameter values */ CheckParamCombinations(); /*check that some parameter combinations are valid*/ Mapdistance = calloc (NUMLOCI, sizeof (float)); Phase = calloc (NUMLOCI * NUMINDS, sizeof (float)); if (LINES ==2 && PHASED ==0) { Phasemodel=calloc(NUMINDS,sizeof(int)); for (ind=0; ind<NUMINDS; ind++) { if (MARKOVPHASE) { Phasemodel[ind]=0; } else { Phasemodel[ind]=1; } } } lambda=calloc(MAXPOPS, sizeof (float)); sumlambda=calloc(MAXPOPS, sizeof (float)); Markername = calloc (GENELEN*NUMLOCI, sizeof (char)); Geno = calloc (LINES * NUMLOCI * NUMINDS, sizeof (int)); if (RECESSIVEALLELES) { PreGeno = calloc (LINES * NUMLOCI * NUMINDS, sizeof (int)); Recessive = calloc (NUMLOCI, sizeof (int)); if (PreGeno == NULL || Recessive == NULL) { printf ("Error (3) in assigning memory\n"); Kill (); } } Individual = calloc (NUMINDS, sizeof (struct IND)); if (Geno == NULL || Individual == NULL || Mapdistance == NULL || Markername == NULL) { printf ("Error in assigning memory (not enough space?)\n"); Kill (); } Randomize(RANDOMIZE, &SEED); /*read in data file */ if (RECESSIVEALLELES) { ReadInputFile(PreGeno, Mapdistance, Markername, Individual, Phase, Recessive); } else { ReadInputFile (Geno, Mapdistance, Markername, Individual, Phase, Recessive); } if (RECESSIVEALLELES) { MAXALLELES = FindMaxAlleles (PreGeno, Recessive); } else { MAXALLELES = FindMaxAlleles (Geno, Recessive); } /*=============set aside memory space=====================*/ Translation = calloc (NUMLOCI * MAXALLELES, sizeof (int)); NumAlleles = calloc (NUMLOCI, sizeof (int)); Z = calloc (NUMINDS * LINES * NUMLOCI, sizeof (int)); Z1 = calloc (NUMINDS * LINES * NUMLOCI, sizeof (int)); Q = calloc (NUMINDS * MAXPOPS, sizeof (float)); P = calloc (NUMLOCI * MAXPOPS * MAXALLELES, sizeof (float)); R = calloc (NUMINDS, sizeof (float)); sumR = calloc (NUMINDS, sizeof (float)); varR = calloc (NUMINDS, sizeof (float)); Epsilon = calloc (NUMLOCI * MAXALLELES, sizeof (float)); if (FREQSCORR) { SumEpsilon = calloc (NUMLOCI * MAXALLELES, sizeof (float)); } Fst = calloc (MAXPOPS, sizeof (float)); FstSum = calloc (MAXPOPS, sizeof (float)); NumLociPop = calloc (NUMINDS * MAXPOPS, sizeof (int)); PSum = calloc (NUMLOCI * MAXPOPS * MAXALLELES, sizeof (float)); QSum = calloc (NUMINDS * MAXPOPS, sizeof (float)); if (ANCESTDIST) { AncestDist = calloc (NUMINDS * MAXPOPS * NUMBOXES, sizeof (int)); } if (USEPOPINFO) { UsePopProbs = calloc (NUMINDS * MAXPOPS * (GENSBACK + 1), sizeof (float)); } /*Melissa added 7/12/07*/ if (LOCDATA>0 || LOCISPOP) { GetNumLocations(Individual); } /*Allocate the LocPrior vector. For no-admixture, it contains r, and the vectors nu and gamma. For admixture, it contains gamma. The alphas_locals are stored with alpha global*/ if (LOCPRIOR) { if (NOADMIX) { LocPriorLen = 1+MAXPOPS*(NUMLOCATIONS+1); } else { LocPriorLen=1; } LocPrior = malloc(LocPriorLen*sizeof(float)); sumLocPrior = malloc(LocPriorLen*sizeof(float)); } if (LOCPRIOR && NOADMIX==0) { Alpha = malloc(MAXPOPS*(NUMLOCATIONS+1)*sizeof(float)); sumAlpha = malloc(MAXPOPS*(NUMLOCATIONS+1)*sizeof(float)); } else { Alpha = calloc(MAXPOPS, sizeof (float)); sumAlpha = calloc(MAXPOPS, sizeof (float)); } /* this is for DIC */ sumIndLikes = malloc(NUMINDS*sizeof(float)); indLikesNorm = malloc(NUMINDS*sizeof(float)); if ((Translation == NULL) || (NumAlleles == NULL) || (Z == NULL) || (Z1 == NULL) || (Q == NULL) || (P == NULL) || (R == NULL) || (sumR == NULL) || (varR == NULL) || (Epsilon == NULL) || (Fst == NULL) || (NumLociPop == NULL) || (PSum == NULL) || (QSum == NULL) || (FstSum == NULL) || ((ANCESTDIST) && (AncestDist == NULL)) || ((USEPOPINFO) && (UsePopProbs == NULL))||(Alpha == NULL)||(sumAlpha==NULL)|| ((FREQSCORR) && (SumEpsilon == NULL)) || (LocPriorLen>0 && (LocPrior==NULL || sumLocPrior==NULL)) || sumIndLikes==NULL || indLikesNorm==NULL) { printf ("Error in assigning memory (not enough space?)\n"); FreeAll(Mapdistance, Phase, Phasemodel, lambda, sumlambda, Markername, Geno, PreGeno, Recessive, Individual, Translation, NumAlleles, Z, Z1, Q, P, R, sumR, varR, Epsilon, SumEpsilon, Fst, FstSum, NumLociPop, PSum, QSum, AncestDist, UsePopProbs, LocPrior, sumLocPrior, Alpha, sumAlpha, sumIndLikes, indLikesNorm, clDict); Kill (); } /*=========done setting aside memory space=====================*/ /*initialize variables and arrays */ Initialization (Geno, PreGeno, Individual, Translation, NumAlleles, Z, Z1, Epsilon, SumEpsilon, Fst, PSum, Q, QSum, FstSum, AncestDist, UsePopProbs, Alpha, sumAlpha, sumR, varR, sumlikes, sumsqlikes, &savefreq, R, lambda, sumlambda,Phase,Recessive, LocPrior, sumLocPrior, LocPriorLen, sumIndLikes, indLikesNorm, clDict); /* ==================== GPU Structure ==================== */ /*Allocate an array of random numbers. Primarily used so that we can compare CL implementation to the original */ randomArr = calloc(RANDSIZE,sizeof(float)); randGens = calloc(NUMRANDGENS,sizeof(unsigned int)); Numafrompopscl = calloc(NUMLOCI*MAXPOPS*MAXALLELES,sizeof(int)); Numlocipopscl = calloc(NUMINDS*MAXPOPS,sizeof(int)); /* ====== OpenCL initialized ====== */ printf ("\n\n--------------------------------------\n\n"); printf ("Finished initialization; starting MCMC \n"); printf ("%d iterations + %d burnin\n\n", NUMREPS, BURNIN); /*=====Main MCMC loop=======================================*/ writeBuffer(clDict,Numafrompopscl,sizeof(int) * NUMLOCI*MAXPOPS*MAXALLELES,NUMAFROMPOPSCL,"NumAFromPops"); writeBuffer(clDict,Numlocipopscl,sizeof(int)*NUMINDS*MAXPOPS,NUMLOCIPOPSCL,"NUMLOCIPOPS"); /* init buffers on GPU */ writeBuffer(clDict,P,sizeof(float) * PSIZE,PCL,"P"); writeBuffer(clDict,Z,sizeof(int)*ZSIZE,ZCL,"Z"); writeBuffer(clDict,Q, sizeof(float) * QSIZE,QCL, "Q"); writeBuffer(clDict,NumAlleles,sizeof(int) * NUMLOCI,NUMALLELESCL,"NumAlleles"); writeBuffer(clDict,lambda,sizeof(float) * MAXPOPS,LAMBDACL,"LAMBDA"); if(!RECESSIVEALLELES){ writeBuffer(clDict,Geno,sizeof(int)*GENOSIZE,GENOCL,"Geno"); } popflags = calloc(NUMINDS,sizeof(int)); for(ind = 0; ind < NUMINDS;ind++){ popflags[ind] = Individual[ind].PopFlag; if (!((USEPOPINFO) && (Individual[ind].PopFlag))) { POPFLAGINDS++; } } printf("Setting updatealpha arg\n"); setKernelArgExplicit(clDict,UpdateAlphaKernel,sizeof(int),&POPFLAGINDS,7); printf("Setting invsqrtnuminds arg\n"); invsqrtnuminds = 1.0/sqrt(NUMINDS); setKernelArgExplicit(clDict,NonIndUpdateEpsilonKernel,sizeof(float),&invsqrtnuminds,6); writeBuffer(clDict,popflags,sizeof(int)*NUMINDS,POPFLAGCL,"popflags"); writeBuffer(clDict,Alpha,sizeof(float) *MAXPOPS,ALPHACL,"Alpha"); reduceresult = calloc(NUMINDS*NUMLOCI*MAXGROUPS,sizeof(float)); if(reduceresult == NULL){ printf("Failed to allocate reduce result\n"); } printf("Writing reduce results\n"); writeBuffer(clDict,reduceresult,sizeof(float)*MAXGROUPS*NUMINDS*NUMLOCI,REDUCERESULTSCL,"result"); printf("Done writing reduce results\n"); writeBuffer(clDict,sumAlpha, sizeof(float) * MAXPOPS,ALPHASUMCL, "alphasum"); writeBuffer(clDict,sumlambda, sizeof(float) * MAXPOPS,LAMBDASUMCL, "lambdasum"); writeBuffer(clDict,like, sizeof(float),LIKECL, "like"); writeBuffer(clDict,sumsqlikes, sizeof(float),SUMSQLIKESCL, "sumsqlikes"); writeBuffer(clDict,sumlikes, sizeof(float),SUMLIKESCL, "sumlikes"); writeBuffer(clDict,QSum, sizeof(float) * QSIZE,QSUMCL, "qsum"); writeBuffer(clDict,PSum, sizeof(float) * PSIZE,PSUMCL, "psum"); writeBuffer(clDict,SumEpsilon, sizeof(float) * NUMLOCI*MAXALLELES,EPSILONSUMCL, "epssum"); if(ANCESTDIST){ writeBuffer(clDict,AncestDist, sizeof(int)*NUMINDS*MAXPOPS*NUMBOXES,ANCESTDISTCL, "ancest dist"); } if (FREQSCORR) { writeBuffer(clDict,Fst,sizeof(float) * MAXPOPS,FSTCL,"FST"); writeBuffer(clDict,FstSum, sizeof(float) * MAXPOPS,FSTSUMCL, "fstsum"); writeBuffer(clDict,Epsilon,sizeof(float) * NUMLOCI*MAXALLELES,EPSILONCL, "EPSILON"); } /*printf("%d, %d\n",INFERALPHA,INFERLAMBDA);*/ /*printf("%d\n",USEPOPINFO);*/ /*printf("%d\n",RECESSIVEALLELES);*/ /*printf("%d\n",LINKAGE);*/ /*printf("%d\n",COMPUTEPROB);*/ /*printf("%d\n",POPALPHAS);*/ /*printf("%d\n",NOADMIX);*/ /*printf("%d\n",LOCPRIOR);*/ /*handleCLErr(1,clDict,"heyhey");*/ /*Initialize Q */ initQ(Q); initRandGens(clDict,randGens); finishWaitList(clDict); printf("Waitlist finished!\n"); for (rep = 0; rep < (NUMREPS + BURNIN); rep++) { breakP(clDict); /*FillArrayWithRandomCL(clDict,randomArr,NUMLOCI*MAXALLELES*MAXPOPS*MAXRANDOM);*/ /*FillArrayWithRandom(randomArr,NUMLOCI*MAXALLELES*MAXPOPS*MAXRANDOM);*/ /*FillArrayWithRandom(randomArr,RANDSIZE);*/ /* if(DEBUGCOMPARE) { */ /* readBuffer(clDict,randomArr, */ /* sizeof(float) * NUMLOCI*MAXALLELES*MAXPOPS*MAXRANDOM,RANDCL, */ /* "randomArr"); */ /* comparePCLandP(clDict,P,Epsilon, Fst, NumAlleles, Geno, Z, */ /* lambda, Individual, randomArr); */ /* } */ /* if (USEWORKINGCL) { */ /* clear buffer */ writeBuffer(clDict,Numafrompopscl,sizeof(int) * NUMLOCI*MAXPOPS*MAXALLELES,NUMAFROMPOPSCL,"NumAFromPops"); UpdatePCL (clDict,P, Epsilon, Fst, NumAlleles, Geno, Z, lambda, Individual, randomArr); /* } else { */ /* readBuffer(clDict,randomArr, */ /* sizeof(float) * NUMLOCI*MAXALLELES*MAXPOPS*MAXRANDOM,RANDCL, */ /* "randomArr"); */ /* UpdateP (P, Epsilon, Fst, NumAlleles, Geno, Z, lambda, Individual, */ /* randomArr); */ /* } */ /* Update Q */ /*FillArrayWithRandomCL(clDict,randomArr,NUMINDS+NUMINDS*MAXRANDOM);*/ if (LINKAGE && rep >= ADMBURNIN) { UpdateQMetroRecombine (Geno, Q, Z, P, Alpha, rep, Individual, Mapdistance, R, Phase,Phasemodel,randomArr); } else { writeBuffer(clDict,Numlocipopscl,sizeof(int)*NUMINDS*MAXPOPS,NUMLOCIPOPSCL,"NUMLOCIPOPS"); UpdateQCL (clDict,Geno, PreGeno, Q, P, Z, Alpha, rep, Individual, UsePopProbs, Recessive, LocPrior,randomArr); } if (LOCPRIOR && UPDATELOCPRIOR) { UpdateLocPrior(Q, LocPrior, Alpha, Individual); } if (RECESSIVEALLELES) { UpdateGeno (PreGeno, Geno, P, Z, Recessive, NumAlleles, Q); writeBuffer(clDict,Geno,sizeof(int) * GENOSIZE,GENOCL,"Geno"); /*The Zs are not correct after UpdateGeno, until UpdateZ is run */ } if (LINKAGE && rep > ADMBURNIN) { if (!INDIVIDUALR) { recomblikelihood = UpdateZandSingleR(Z, Q, P, Geno, R, Mapdistance, rep, Phase, Z1,Phasemodel, rep+1 > BURNIN? sumIndLikes : NULL, indLikesNorm); } else { recomblikelihood = UpdateZandR(Z, Q, P, Geno, R, Mapdistance, rep, Phase, Z1,Phasemodel, rep+1 > BURNIN ? sumIndLikes:NULL, indLikesNorm); } } else { /*FillArrayWithRandomCL(clDict,randomArr,NUMINDS*NUMLOCI*LINES);*/ /* if (DEBUGCOMPARE) { */ /* readBuffer(clDict,randomArr, */ /* sizeof(float) * NUMINDS*NUMLOCI*LINES,RANDCL, */ /* "randomArr"); */ /* compareZCLandZ(clDict,Z,Q,P,Geno,randomArr); */ /* } */ /* if (USEWORKINGCL) { */ UpdateZCL (clDict,Z, Q, P, Geno,randomArr); /* Not needed */ /*readBuffer(clDict,Z,sizeof(int)*ZSIZE,ZCL,"Z");*/ /* } else { */ /* readBuffer(clDict,randomArr, */ /* sizeof(float) * NUMINDS*NUMLOCI*LINES,RANDCL, */ /* "randomArr"); */ /* UpdateZ (Z, Q, P, Geno,randomArr); */ /* } */ /* printf("done updatez alpha[2]=%e\n", Alpha[2]); */ } if (LOCPRIOR && NOADMIX==0) { UpdateAlphaLocPrior(Q, Alpha, LocPrior, Individual); } else if (INFERALPHA) { UpdateAlphaCL (clDict,Q, Alpha, Individual, rep,POPFLAGINDS); /* readBuffer(clDict,Q, sizeof(float) * QSIZE,QCL, "Q"); */ /* readBuffer(clDict,Alpha, sizeof(float) * MAXPOPS,ALPHACL, "alpha"); */ /* UpdateAlpha(Q, Alpha, Individual, rep); */ /* writeBuffer(clDict,Alpha, sizeof(float) * MAXPOPS,ALPHACL, "alpha"); */ } if (INFERLAMBDA) { readBuffer(clDict,P,sizeof(float) * PSIZE,PCL,"P"); if (POPSPECIFICLAMBDA) { UpdatePopLambda(P,lambda,NumAlleles); } else { UpdateLambda (P,Epsilon,lambda, NumAlleles); } writeBuffer(clDict,lambda,sizeof(float) * MAXPOPS,LAMBDACL,"LAMBDA"); } if (FREQSCORR) { UpdateEpsilonCL(clDict,P,Epsilon,Fst,NumAlleles,lambda[0]); UpdateFstCL (clDict,Epsilon, Fst, P, NumAlleles); /* readBuffer(clDict,P, sizeof(float) * PSIZE,PCL, "P"); */ /* readBuffer(clDict,Fst,sizeof(float) * MAXPOPS,FSTCL,"FST"); */ /* readBuffer(clDict,Epsilon,sizeof(float) * NUMLOCI*MAXALLELES,EPSILONCL,"eps"); */ /* UpdateEpsilon(P,Epsilon,Fst,NumAlleles,lambda[0]); */ /* UpdateFst (Epsilon, Fst, P, NumAlleles); */ /* writeBuffer(clDict,Epsilon,sizeof(float) * NUMLOCI*MAXALLELES,EPSILONCL,"eps"); */ /* writeBuffer(clDict,Fst,sizeof(float) * MAXPOPS,FSTCL,"FST"); */ } /*====book-keeping stuff======================*/ if (rep + 1 > BURNIN) { /*buffers[0] = PCL; names[0] = "P"; dests[0] = P; sizes[0] = sizeof(float) * PSIZE; buffers[1] = QCL; names[1] = "Q"; dests[1] = Q; sizes[1] = sizeof(float) * QSIZE; readBuffers(clDict,dests,sizes,buffers,names,2);*/ /*readBuffer(clDict,Alpha, sizeof(float) * MAXPOPS,ALPHACL, "alpha"); if(rep % 100 == 0){ printf("%f",Alpha[0]); }*/ DataCollectionCL (clDict,Geno, PreGeno, Q, QSum, Z, Z1, P, PSum, Fst, FstSum, NumAlleles, AncestDist, Alpha, sumAlpha, sumR, varR, like, sumlikes, sumsqlikes, R, Epsilon,SumEpsilon,recomblikelihood, lambda, sumlambda, Recessive, LocPrior, sumLocPrior, LocPriorLen, sumIndLikes, indLikesNorm, rep); } if ((savefreq) && ((rep + 1) > BURNIN) && (((rep + 1 - BURNIN) % savefreq) == 0) && ((rep + 1) != NUMREPS + BURNIN)) { /* readBuffer(clDict,Alpha, sizeof(float) * MAXPOPS,ALPHACL, "alpha"); */ readBuffer(clDict,Fst, sizeof(float) * MAXPOPS,FSTCL, "fst"); readBuffer(clDict,sumAlpha, sizeof(float) * MAXPOPS,ALPHASUMCL, "alphasum"); readBuffer(clDict,sumlambda, sizeof(float) * MAXPOPS,LAMBDASUMCL, "lambdasum"); readBuffer(clDict,FstSum, sizeof(float) * MAXPOPS,FSTSUMCL, "fstsum"); readBuffer(clDict,QSum, sizeof(float) * QSIZE,QSUMCL, "Qsum"); readBuffer(clDict,PSum, sizeof(float) * PSIZE,PSUMCL, "Psum"); readBuffer(clDict,SumEpsilon, sizeof(float) * NUMLOCI*MAXALLELES,EPSILONSUMCL, "epssum"); readBuffer(clDict,like, sizeof(float),LIKECL, "like"); readBuffer(clDict,sumlikes, sizeof(float),SUMLIKESCL, "sumlike"); readBuffer(clDict,sumsqlikes, sizeof(float),SUMSQLIKESCL, "sumsqlikes"); OutPutResults (Geno, rep + 1, savefreq, Individual, PSum, QSum, FstSum, AncestDist, UsePopProbs, *sumlikes, *sumsqlikes, sumAlpha, sumR, varR, NumAlleles, Translation, 0, Markername, R, SumEpsilon, lambda,sumlambda,sumLocPrior, LocPriorLen, sumIndLikes, indLikesNorm, argc,argv); } if (PRINTLIKES) { readBuffer(clDict,like, sizeof(float),LIKECL, "like"); PrintLike (*like, rep, Geno, PreGeno, Q, P,recomblikelihood); } if (((rep + 1) % UPDATEFREQ) == 0) { readBuffer(clDict,Alpha, sizeof(float) * MAXPOPS,ALPHACL, "alpha"); readBuffer(clDict,Fst, sizeof(float) * MAXPOPS,FSTCL, "fst"); readBuffer(clDict,like, sizeof(float),LIKECL, "like"); readBuffer(clDict,sumlikes, sizeof(float),SUMLIKESCL, "sumlike"); readBuffer(clDict,sumsqlikes, sizeof(float),SUMSQLIKESCL, "sumsqlikes"); /*readBuffer(clDict,sumAlpha, sizeof(float) * MAXPOPS,ALPHASUMCL, "alphasum"); readBuffer(clDict,sumlambda, sizeof(float) * MAXPOPS,LAMBDASUMCL, "lambdasum"); readBuffer(clDict,FstSum, sizeof(float) * MAXPOPS,FSTSUMCL, "fstsum"); readBuffer(clDict,QSum, sizeof(float) * QSIZE,QSUMCL, "Qsum"); readBuffer(clDict,PSum, sizeof(float) * PSIZE,PSUMCL, "Psum"); readBuffer(clDict,SumEpsilon, sizeof(float) * NUMLOCI*MAXALLELES,EPSILONSUMCL, "epssum");*/ PrintUpdate (rep + 1, Geno, PreGeno, Alpha, Fst, P, Q, *like, *sumlikes, *sumsqlikes, NumAlleles, R, lambda,Individual, recomblikelihood, Recessive, LocPrior, LocPriorLen); } finishWaitList(clDict); } /*====final book-keeping====================================*/ if ((rep % UPDATEFREQ) != 0) { readBuffer(clDict,Alpha, sizeof(float) * MAXPOPS,ALPHACL, "alpha"); readBuffer(clDict,Fst, sizeof(float) * MAXPOPS,FSTCL, "fst"); readBuffer(clDict,like, sizeof(float),LIKECL, "like"); readBuffer(clDict,sumsqlikes, sizeof(float),SUMSQLIKESCL, "sumsqlikes"); readBuffer(clDict,sumlikes, sizeof(float),SUMLIKESCL, "sumlikes"); /*readBuffer(clDict,sumAlpha, sizeof(float) * MAXPOPS,ALPHASUMCL, "alphasum"); readBuffer(clDict,sumlambda, sizeof(float) * MAXPOPS,LAMBDASUMCL, "lambdasum"); readBuffer(clDict,FstSum, sizeof(float) * MAXPOPS,FSTSUMCL, "fstsum"); readBuffer(clDict,QSum, sizeof(float) * QSIZE,QSUMCL, "Qsum"); readBuffer(clDict,PSum, sizeof(float) * PSIZE,PSUMCL, "Psum"); readBuffer(clDict,SumEpsilon, sizeof(float) * NUMLOCI*MAXALLELES,EPSILONSUMCL, "epssum");*/ PrintUpdate (rep, Geno, PreGeno, Alpha, Fst, P, Q, *like, *sumlikes, *sumsqlikes, NumAlleles,R, lambda, Individual,recomblikelihood, Recessive, LocPrior, LocPriorLen); } readBuffer(clDict,Alpha, sizeof(float) * MAXPOPS,ALPHACL, "alpha"); readBuffer(clDict,Fst, sizeof(float) * MAXPOPS,FSTCL, "fst"); readBuffer(clDict,sumAlpha, sizeof(float) * MAXPOPS,ALPHASUMCL, "alphasum"); readBuffer(clDict,sumlambda, sizeof(float) * MAXPOPS,LAMBDASUMCL, "lambdasum"); readBuffer(clDict,FstSum, sizeof(float) * MAXPOPS,FSTSUMCL, "fstsum"); readBuffer(clDict,QSum, sizeof(float) * QSIZE,QSUMCL, "Qsum"); readBuffer(clDict,PSum, sizeof(float) * PSIZE,PSUMCL, "Psum"); readBuffer(clDict,SumEpsilon, sizeof(float) * NUMLOCI*MAXALLELES,EPSILONSUMCL, "epssum"); readBuffer(clDict,like, sizeof(float),LIKECL, "like"); readBuffer(clDict,sumsqlikes, sizeof(float),SUMSQLIKESCL, "sumsqlikes"); readBuffer(clDict,sumlikes, sizeof(float),SUMLIKESCL, "sumlikes"); OutPutResults (Geno, rep, savefreq, Individual, PSum, QSum, FstSum, AncestDist, UsePopProbs, *sumlikes, *sumsqlikes, sumAlpha, sumR, varR, NumAlleles, Translation, 1, Markername, R, SumEpsilon, lambda,sumlambda,sumLocPrior, LocPriorLen, sumIndLikes, indLikesNorm, argc,argv); /*=====Closing everything down==============================*/ FreeAll(Mapdistance, Phase, Phasemodel, lambda, sumlambda, Markername, Geno, PreGeno, Recessive, Individual, Translation, NumAlleles, Z, Z1, Q, P, R, sumR, varR, Epsilon, SumEpsilon, Fst, FstSum, NumLociPop, PSum, QSum, AncestDist, UsePopProbs, LocPrior, sumLocPrior, Alpha, sumAlpha, sumIndLikes, indLikesNorm, clDict); free(randomArr); free(randGens); free(like); free(sumsqlikes); free(sumlikes); free(reduceresult); printf("Structure seed: %d\n", SEED); return (0); }