int main(int argc, char *argv[]) { // Variable declarations int count = 1; int rows,cols,iters,numCoords,x,y,neighbors; FILE *inFile = openFile(argv[1]); struct timeval start, end; char *newBoard = NULL; char *refBoard = NULL; char *temp; // Threading variables // Process command line arguments verifyCmdArgs(argc, argv); // Open test parameter file and read in first 4 lines fscanf(inFile, "%d %d %d %d", &rows, &cols, &iters, &numCoords); // Create game board initialized to starting state newBoard = makeBoard(rows,cols,inFile,numCoords); refBoard = copyBoard(newBoard,rows,cols); print(refBoard,atoi(argv[2]),rows,cols,0); //printf("refBoard2: %s\n", refBoard); // Apply the life and death conditions to the board /*gettimeofday(&start, NULL); while (count < iters+1) { evolve(x,y,rows,cols,newBoard,refBoard,argv,numCoords,count); *temp = *refBoard; *refBoard = *newBoard; // reference board updated to be the newer board *newBoard = *temp;*/ // Very helpful visuals for showing which versions of the board // are being stored in our three char *'s /*printf("temBoard: %s\n", temp); printf("refBoard: %s\n", refBoard); printf("newBoard: %s\n", newBoard);* s/ temp = copyBoard(newBoard,rows,cols); refBoard = temp; // reference board updated to be the newer board //newBoard = temp; ++count; } gettimeofday(&end, NULL); */ // Time calculations long elapsed = (end.tv_sec-start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec); printf("\nElapsed time for %d steps of a %d x %d board is: %f seconds\n", iters, rows, cols, elapsed/1000000.); free(newBoard); free(refBoard); fclose(inFile); refBoard = NULL; newBoard = NULL; temp = NULL; return 0; }
int main (int argc, char **argv) { #ifdef CLEAR strcpy(table_path, dirname(argv[0])); strcat(table_path, "/"); strcat(table_path, argv[2]); shm_unlink(table_path); #else // verifies if the number of arguments is correct if (argc != 4) { printf("usage: %s <player's name> <table's name> <nr. players>\n", argv[0]); return -1; } if (verifyCmdArgs(argv) == -1) { return -1; } // installs an exit handler if (atexit(exitHandler) == -1) { perror("atexit()"); exit(-1); } blockSignals(); initFIFO(argv[1]); initSharedMem(argv); waitForPlayers(); pthread_t tid; if (is_dealer) { initDefaultDeck(); printCardsList(cards, NULL); shuffleDeck(); randomiseFirstPlayer(); if ((errno = pthread_create(&tid, NULL, dealCards, NULL)) != 0) { perror("pthread_create()"); exit(-1); } } receiveCards(); reorderCardsList(hand); if (is_dealer) { pthread_join(tid, NULL); } //call thread responsible for showing info about the game and manage the game pthread_t tidG; if ((errno = pthread_create(&tidG, NULL, playGame, NULL)) != 0) { perror("pthread_create()"); exit(-1); } pthread_join(tidG, NULL); #endif return 0; }