void main() { initvars(); initgraphics(); showlogo(); do { while(!mainoptions()); playgame(); }while(1); //Infinite loop }
void go_sleep() { cbi(ADCSRA,ADEN); // switch Analog to Digitalconverter OFF set_sleep_mode(SLEEP_MODE_PWR_DOWN); cli(); sleep_enable(); sleep_bod_disable(); sei(); sleep_cpu(); //sleep_mode(); /* wake up here */ sleep_disable(); sbi(ADCSRA,ADEN); // switch Analog to Digitalconverter ON initvars(); setup(); }
void clearsheet(void) /* Clears the current spreadsheet */ { int col, row; for (row = 0; row <= lastrow; row++) { for (col = 0; col <= lastcol; col++) deletecell(col, row, NOUPDATE); } initvars(); setrightcol(); setbottomrow(); displayscreen(NOUPDATE); printfreemem(); changed = FALSE; } /* clearsheet */
main(int argc, char *const *argv) { initvars(); #ifdef USE_KQUEUE ir_kqueue_init(); #endif /* USE_KQUEUE */ command_options(argc, argv); #if defined(_OS_CYGWIN) gdata.noscreen = 1; #endif startupiroffer(); while ( 1 ) { mainloop(); } }
int main(int argc, char *argv[]) { char *ptr; char option; struct stat st; char *conffile = NULL; const char *const myname = "rnews"; ln_log_open(myname); if (!initvars(argv[0], 0)) init_failed(myname); while ((option = getopt(argc, argv, GLOBALOPTS "")) != -1) { if (parseopt(myname, option, optarg, &conffile)) continue; switch(option) { default: usage(); exit(EXIT_FAILURE); } } if (readconfig(conffile) != 0) { ln_log(LNLOG_SERR, LNLOG_CTOP, "Reading configuration failed: %m.\n"); exit(2); } if (conffile) free(conffile); if (filterfile && !readfilter(filterfile)) { ln_log(LNLOG_SERR, LNLOG_CTOP, "%s: Cannot read filterfile %s, aborting.", argv[0], filterfile); log_unlink(lockfile, 0); exit(EXIT_FAILURE); } if (!init_post()) init_failed(myname); umask((mode_t) 077); if (attempt_lock(LOCKWAIT)) { exit(EXIT_FAILURE); } rereadactive(); readlocalgroups(); if (!argv[optind]) fprocessfile(stdin); /* process stdin */ while ((ptr = argv[optind++])) { if (stat(ptr, &st) == 0) { if (S_ISDIR(st.st_mode)) processdir(ptr); else if (S_ISREG(st.st_mode)) processfile(ptr); else ln_log(LNLOG_SERR, LNLOG_CTOP, "%s: cannot open %s\n", argv[0], ptr); } else ln_log(LNLOG_SERR, LNLOG_CTOP, "%s: cannot stat %s\n", argv[0], ptr); } writeactive(); /* write groupinfo file */ freeallfilter(filter); log_unlink(lockfile, 0); exit(0); }
/********************************************************* * M A I N *********************************************************/ int main() { FILE *fp; char msg[80], num[10], *fmt1, *fmt2; int i; printf(TITLE); initvars(); /* initialize config variables */ if (loadvars()) /* load config variables */ { printf("\nLast MCX11 configuration:\n\n"); showconfig(); do { printf("Do you wish to change the configuration? "); gets(msg); *msg = tolower(*msg); } while (*msg!='y' && *msg!='n'); if (*msg=='n') return 0; } do { enterconfig(); printf("\nNew MCX11 configuration:\n\n"); showconfig(); do { printf("Are the configuration parameters correct? "); gets(msg); *msg = tolower(*msg); } while (*msg!='y' && *msg!='n'); } while (*msg=='n'); do { printf("Save configuration? "); gets(msg); *msg = tolower(*msg); } while (*msg!='y' && *msg!='n'); if (*msg=='n') { printf("Not saved.\n"); return 0; } savevars(); configdoc(); /*************************** * Write the MCXDEF.S file * ***************************/ fp = fopen("mcxdef.s", "w"); fprintf(fp,"; mcxdef.s\n\n"); fmt1 = " .DEFINE %-10s = %3d ; %s\n"; fprintf(fp,fmt1, "NTASKS", gNTASKS, "Number of tasks (counting timer)"); fprintf(fp,fmt1, "NQUEUES", gNQUEUES, "Number of queues"); fprintf(fp,fmt1, "NNAMSEM", gNNAMSEM, "Number of named semaphores"); fprintf(fp,fmt1, "NTIMERS", gNTIMERS, "Number of timers"); fclose(fp); /*************************** * Write the MCXDEF.H file * ***************************/ fp = fopen("mcxdef.h", "w"); fprintf(fp,"/************\n * mcxdef.h *\n ************/\n\n"); fprintf(fp,"#define NTASKS %d\n", gNTASKS); fprintf(fp,"#define NQUEUES %d\n", gNQUEUES); fprintf(fp,"#define NNAMSEM %d\n", gNNAMSEM); fprintf(fp,"#define NTIMERS %d\n", gNTIMERS); fprintf(fp,"\n"); for (i=0; i<gNTASKS; i++) fprintf(fp,"#define TASK_%-12s %d\n", task[i].name, i+1); fprintf(fp,"\n"); for (i=0; i<gNTASKS; i++) fprintf(fp,"#define STACKSIZE_%-12s %d\n", task[i].name, task[i].stacksize); fprintf(fp,"\n"); for (i=0; i<gNQUEUES; i++) fprintf(fp,"#define QUEUE_%-12s %d\n", queue[i].name, i+1); fprintf(fp,"\n"); for (i=0; i<gNNAMSEM; i++) fprintf(fp,"#define SEMA_%-12s %d\n", sema_name[i], i+1); fprintf(fp,"\n"); for (i=1; i<gNTASKS; i++) fprintf(fp,"extern void task_%s (void);\n", task[i].name); fclose(fp); /**************************** * Write the MCXDBUG.H file * ****************************/ fp = fopen("mcxdbug.h", "w"); fprintf(fp,"/*************\n * mcxdbug.h *\n *************/\n\n"); fprintf(fp,"\n"); fprintf(fp,"typedef struct {\n"); fprintf(fp," char *name;\n"); fprintf(fp," int stacksize;\n"); fprintf(fp,"} MCXTASK;\n"); fprintf(fp,"#ifdef _DBUG_\n"); fprintf(fp,"const MCXTASK mcxtask[%d]={\n", gNTASKS); for (i=0; i<gNTASKS; i++) fprintf(fp," \"%s\", %d%s\n", task[i].name, task[i].stacksize, (i==gNTASKS-1)? "};": ","); fprintf(fp,"#else\n"); fprintf(fp,"extern MCXTASK mcxtask[];\n"); fprintf(fp,"#endif\n"); fclose(fp); /**************************** * Write the MCXDATA.S file * ****************************/ fp = fopen("mcxdata.s", "w"); fprintf(fp,"; mcxdata.s\n\n"); fprintf(fp," .INCLUDE \"DEFINE.S\"\n"); fprintf(fp," .INCLUDE \"MCXDEF.S\"\n\n"); fprintf(fp," .PUBLIC FLGTBL, QHDRTBL, STATLS, TIMERS\n"); fprintf(fp," .PUBLIC tickcnt, FREE, ACTIVE, curtsk, curtcb, hipri\n"); fprintf(fp," .PUBLIC pritcb, intlvl, temp, _width, _depth, notmt\n"); fprintf(fp," .PUBLIC SYSTACK, TCBDATA, QUEDATA, STKBASE\n"); fprintf(fp," .PUBLIC _TCBDATA\n\n"); for (i=0; i<gNTASKS; i++) fprintf(fp," .EXTERNAL %s%s\n", i?"_task_":"", task[i].name); fprintf(fp,"\n\n"); fprintf(fp,";************************\n"); fprintf(fp,"; Stack Areas\n"); fprintf(fp,";************************\n"); fprintf(fp," .PSECT _%s\n", task[0].memtype ? "bss" : "data"); fprintf(fp," .BYTE [64]\n"); fprintf(fp,"SYSTACK: .BYTE [19]\n"); for (i=0; i<gNTASKS; i++) { fprintf(fp," .PSECT _%s\n", task[i].memtype ? "bss" : "data"); sprintf(msg,"STAK%d:", i+1); fprintf(fp," .BYTE [%d]\n", task[i].stacksize); fprintf(fp,"%-7s\n", msg); } fprintf(fp,"STKBASE:\n"); fprintf(fp,"\n .PSECT _%s\n", task[0].memtype ? "bss" : "data"); fprintf(fp,"\n"); fprintf(fp,";************************\n"); fprintf(fp,"; Queue Headers\n"); fprintf(fp,";************************\n"); fprintf(fp,"QHDRTBL:\n"); for (i=0; i<gNQUEUES; i++) { sprintf(msg,"Q%dHDR:",i+1); fprintf(fp,"%-7s .BYTE [QHDRLEN]\n", msg); } fprintf(fp,"\n"); fprintf(fp,";************************\n"); fprintf(fp,"; Timers\n"); fprintf(fp,";************************\n"); fprintf(fp,"TIMERS: .BYTE [NTIMERS*TIMRLEN]\n\n"); fprintf(fp,"\n"); fprintf(fp,";************************\n"); fprintf(fp,"; System Variables\n"); fprintf(fp,";************************\n"); fmt1 = "%-7s .BYTE [1] ; %s\n"; fmt2 = "%-7s .WORD [1] ; %s\n"; fprintf(fp,"MCXVAR:\n"); fprintf(fp,"tickcnt: .BYTE [1] ; Tick counter\n"); fprintf(fp,fmt2,"FREE:","Address of first free timer block"); fprintf(fp,fmt2,"ACTIVE:","Address of first active timer in list"); fprintf(fp,fmt1,"curtsk:","Current task (i.e. the active task)"); fprintf(fp,fmt2,"curtcb:","Address of current task's TCB"); fprintf(fp,fmt1,"hipri:","Highest priority task ready to run"); fprintf(fp,fmt2,"pritcb:","Address of TCB of highest priority task"); fprintf(fp,fmt1,"intlvl:","Depth of nested interrupts"); fprintf(fp,fmt2,"temp:","Temporary area"); fprintf(fp,fmt1,"_width:","Work area for queue width"); fprintf(fp,fmt1,"_depth:","Work area for queue depth"); fprintf(fp,fmt1,"notmt:","Work area for queue not empty semaphore"); fprintf(fp,"\n"); fprintf(fp,";************************\n"); fprintf(fp,"; Semaphore table\n"); fprintf(fp,";************************\n"); fprintf(fp,"FLGTBL: .BYTE [NQUEUES*2 + NTASKS + NNAMSEM]\n\n"); fprintf(fp,";************************\n"); fprintf(fp,"; Task Control Block\n"); fprintf(fp,";************************\n"); fprintf(fp,"STATLS:\n"); for (i=0; i<gNTASKS; i++) { sprintf(msg,"TASK%d:",i+1); fprintf(fp,"%-7s .BYTE [TCBLEN]\n", msg); } fprintf(fp,"\n"); fprintf(fp,";************************\n"); fprintf(fp,"; Queue Bodies\n"); fprintf(fp,";************************\n"); for (i=0; i<gNQUEUES; i++) { sprintf(msg,"Q%dBODY:",i+1); fprintf(fp,"%-7s .BYTE [%d*%d]\n", msg, queue[i].width, queue[i].depth); } fprintf(fp,"\n"); fprintf(fp,"\n"); fprintf(fp," .PSECT _text\n"); fprintf(fp,"\n"); fprintf(fp,";************************\n"); fprintf(fp,"; Queue data in ROM\n"); fprintf(fp,";************************\n"); fprintf(fp,"QUEDATA:\n"); for (i=0; i<gNQUEUES; i++) { fprintf(fp," .BYTE %d,%d\n", queue[i].width, queue[i].depth); fprintf(fp," .WORD Q%dHDR,Q%dBODY\n", i+1, i+1); } fprintf(fp,"\n"); fprintf(fp,"\n"); fprintf(fp,";************************\n"); fprintf(fp,"; TCB data in ROM\n"); fprintf(fp,";************************\n"); fprintf(fp,"TCBDATA:\n"); fprintf(fp,"_TCBDATA:\n"); i = 0; for (i=0; i<gNTASKS; i++) { fprintf(fp," .BYTE %s\n", task[i].initial ? "_IDLE":"_RUN"); fprintf(fp," .WORD %s%s, STAK%d-1, TASK%d\n\n", i?"_task_":"", task[i].name, i+1, i+1); } fprintf(fp,"\n"); fprintf(fp," .END\n"); fclose(fp); printf("Saved.\n"); return 0; }
int main (int argc, char *argv[]) { double t1, t2, t3, t4, t5, t6, t7; /*timers */ MPI_Init (&argc, &argv); MPI_Comm_rank (MPI_COMM_WORLD, &ThisTask); MPI_Comm_size (MPI_COMM_WORLD, &NTask); t1 = MPI_Wtime (); initvars (); check_params (argc, argv); splitdomain (); /*select mesh size for domain decomposition based on NTask, produce spx,spy,spz */ read_header (); /*read file header and set file format */ MPI_Barrier (MPI_COMM_WORLD); read_part (); /*read particles, allocate each task >> locind, locbuffer, NumThis */ selectposition (); /*set cell position this task > ithis,jthis,kthis */ setbordersize (); /*set border lenght bsize */ MPI_Barrier (MPI_COMM_WORLD); t2 = MPI_Wtime (); /*Transfer temporary boundary particles in the 6 directions */ selectborder (0);/*-x*/ selectborder (1); /*+x */ selectborder (2);/*-y*/ selectborder (3); /*+y */ selectborder (4);/*-z*/ selectborder (5); /*+z */ MPI_Barrier (MPI_COMM_WORLD); t3 = MPI_Wtime (); printf ("Task=%d NumThis=%d NumThis_boundary=%d\n", ThisTask, NumThis, NumThisb); if (NumThisb > NumThis) printf ("%s",warning2); /*run vt */ #ifndef LOWMEMORY runvt (); #else if ((ThisTask % 2) == 0) runvt (); /*run half jobs first to save some memory, slower */ MPI_Barrier (MPI_COMM_WORLD); if ((ThisTask % 2) == 1) runvt (); #endif t4 = MPI_Wtime (); computeneig (); /* Neighbors computation */ #ifdef VERBOSE if (ThisTask == 0) printf ("Neighbors complete.\n"); #endif computedens (); /* Density computation */ #ifdef VERBOSE if (ThisTask == 0) printf ("Density and Volume complete.\n"); #endif #ifdef COMPUTEGRAD computegrad (); /*VT gradient computation*/ if (ThisTask == 0) printf ("Gradient complete.\n"); #endif t5 = MPI_Wtime (); MPI_Barrier (MPI_COMM_WORLD); t6 = MPI_Wtime (); #ifdef WRITEDENSITY writedensopen (); if (ThisTask == 0) printf ("write density..."); savedata (0); /*gather and save density */ if (ThisTask == 0) printf ("volumes..."); savedata (1); /*gather and save volumes */ #endif #ifdef COMPUTEGRAD if (ThisTask == 0) printf ("gradient..."); savedata (3); /*gather and save gradient x */ savedata (4); savedata (5); #endif #ifdef WRITEDENSITY writedensclose (); #endif #ifdef WRITENEIGHBORS if (ThisTask == 0) printf ("neighbors...\n"); writeneigopen (); savedata (2); /*gather and save neighbors */ writeneigclose (); #else printf ("\n"); #endif #ifdef COMPUTEGRID if (checkgrid ()) { writegridopen (); computegrid (); writegridclose (); } #endif t7 = MPI_Wtime (); MPI_Barrier (MPI_COMM_WORLD); if (ThisTask == 0) printf ("Time Stats: Read=%.2f Bdry=%.2f Comp=%.2f Write=%.2f Tot-I/O=%.2F Tot=%.2f\n", t2 - t1, t3 - t2, t6 - t3, t7 - t6, t6 - t2, t7 - t1); #ifdef VERBOSE MPI_Barrier (MPI_COMM_WORLD); printf ("Task=%d Time VT_only=%.2f\n", ThisTask, t4 - t3); MPI_Barrier (MPI_COMM_WORLD); #endif finalize (); /*free memory and finalize code */ return 0; } /* End Main */