TypException CheckPermission_define_regCPTT(TypSysRegRW /*RW*/, TypExceptionLevel level, TypContext& context) { if ((EL2 == level) && 1 == QueryRegField(CPTR, EL3, nsFIELD::TCPAC) && IsSecureAccess() && 1 == QueryRegField(CPTR, EL2, nsFIELD::TCPAC)) { return Trap(EL2, context, 3); } if ((EL1 == level) && 1 == QueryRegField(CPTR, EL3, nsFIELD::TCPAC) && !IsSecureAccess()) { return Trap(EL3, context, 3); } return NO_TRAP; }
int main (void) { double a = 0.0, b = 0.0, local_int = 0.0, total_int = 0.0, h = 0.0, local_a = 0.0, local_b = 0.0; int my_rank = 0, comm_sz = 0, err = 0, n = 0, local_n = 0; err = MPI_Init (NULL, NULL); err |= MPI_Comm_size (MPI_COMM_WORLD, &comm_sz); err |= MPI_Comm_rank (MPI_COMM_WORLD, &my_rank); if (err != 0) return -1; get_input (&a, &b, &n, my_rank, comm_sz); h = (b - a) / n; local_n = n / comm_sz; local_a = a + h * local_n * my_rank; local_b = local_a + h * local_n; local_int = Trap (local_a, local_b, h, my_rank, comm_sz); MPI_Reduce (&local_int, &total_int, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); if (my_rank == 0) { printf ("El valor de la integral entre %.2f y %.2f ", a, b); printf ("con tamaño de partición %d es %.10f\n", n, total_int); } MPI_Finalize (); return 0; }
int main(void) { double area, area2; /* Store result in area */ double a, b; /* Left and right endpoints */ int n; /* Number of trapezoids */ double h; /* Trapezoid base width */ printf("Enter a, b, and n\n"); scanf("%lf", &a); scanf("%lf", &b); scanf("%d", &n); h = (b-a)/n; area = Trap(a, b, n, h); if(n%2 == 0){ area2 = Simp(a, b, n, h); printf("With n = %d parabolas, our estimate\n", n); printf("of the area from %f to %f = %.15f\n", a, b, area2); double abs = area - area2; int num = fabs(abs); printf("The absolute vale of the difference between %f and %f is %d.", area, area2, num); } printf("With n = %d trapezoids, our estimate\n", n); printf("of the area from %f to %f = %.15f\n", a, b, area); main(); return 0; } /* main */
*/ static void Read_File_Port(REBVAL *out, REBSER *port, REBREQ *file, REBVAL *path, REBCNT args, REBCNT len) /* ** Read from a file port. ** ***********************************************************************/ { REBSER *ser; // Allocate read result buffer: ser = Make_Binary(len); Set_Series(REB_BINARY, out, ser); //??? what if already set? // Do the read, check for errors: file->common.data = BIN_HEAD(ser); file->length = len; if (OS_DO_DEVICE(file, RDC_READ) < 0) Trap_Port(RE_READ_ERROR, port, file->error); SERIES_TAIL(ser) = file->actual; STR_TERM(ser); // Convert to string or block of strings. // NOTE: This code is incorrect for files read in chunks!!! if (args & (AM_READ_STRING | AM_READ_LINES)) { REBSER *nser = Decode_UTF_String(BIN_HEAD(ser), file->actual, -1); if (nser == NULL) { Trap(RE_BAD_DECODE); } Set_String(out, nser); if (args & AM_READ_LINES) Set_Block(out, Split_Lines(out)); } }
void Livininabox(){ double time; time = getTimeInterval(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(time > 0.0 && time < 16.17) KnockKnock(time); if(time > 16.04 && time < 27.07) drawExplosion(time - 16.04); if(time > 16.17 && time < 27.07) JumpOut(time - 16.17); if(time > 27.07 && time < 52.23) RunForLife(time - 27.07); if(time > 52.23 && time < 66.50) Credits(time); if(time > 66.50 && time < 118.06) Greetings(time - 66.50); if(time > 118.06 && time < 134.00) ProceduralScenes(time - 118.06); if(time > 134.00 && time < 162.94) FractalMe(time - 134.00); if(time > 162.94 && time < 196.94) CubeTunnel(time - 162.94); if(time > 196.94 && time < 221.26) Trap(time - 196.94); if(time > 221.26 && time < 226.86) HangingFruite(time - 221.26); if(time > 226.86 && time < 248.49) WatchOutForTheLetters(time - 226.86); if(time > 248.49 && time < 271.87) OpenTheDoor(time - 248.49); if(time > 271.87 && time < 276.85) Headbreak(time); if(time > 276.85 && time < 283.33) Matatas(time); if(time > 283.33 && time < 300.00) Cube(time - 283.33); if(time > 300.00 && time < 307.00) End(); if(time > 307.00) cg_isrunning = 0; }
main(int argc, char** argv) { int my_rank; /* rank do processo atual */ int p; /* numero de processos */ float a; /* intervalo esquerdo */ float b; /* intervalo direito */ int n; /* numero de trapezios */ float h; /* largura da base do trapezio */ float local_a; /*intervalo esquerdo local*/ float local_b; /* intervalo direito local*/ int local_n; /* numero de trapezios local*/ float integral; /* resultado da integral do processo */ float total; /* resultado final da integral */ int source; /* processo que esta enviando o resultado*/ int dest = 0; /* o destino das msgs sera o processo 0*/ int tag = 0; MPI_Status status; float Trap(float local_a, float local_b, int local_n, float h); /* Calcula a integral local */ MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); MPI_Comm_size(MPI_COMM_WORLD, &p); Get_data1(&a, &b, &n, my_rank, p); h = (b-a)/n; local_n = n/p; local_a = a + my_rank*local_n*h; local_b = local_a + local_n*h; integral = Trap(local_a, local_b, local_n, h); if (my_rank == 0) { total = integral; for (source = 1; source < p; source++) { MPI_Recv(&integral, 1, MPI_FLOAT, source, tag, MPI_COMM_WORLD, &status); total = total + integral; } } else { MPI_Send(&integral, 1, MPI_FLOAT, dest, tag, MPI_COMM_WORLD); } if (my_rank == 0) { printf("With n = %d trapezoids, our estimate\n", n); printf("of the integral from %f to %f = %f\n", a, b, total); } MPI_Finalize(); } /* main */
int main(int argc, char **argv){ int my_rank; int comm_sz; double parametros[3]; //Parametros: int local_n; double a, b, h; //change this values in other implementation double local_a; double local_b; double local_int; //estimate of trapezoid in cpu my _rank double total_int; int source; int dest; int rc; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); MPI_Comm_size(MPI_COMM_WORLD, &comm_sz); if(my_rank == 0){ scanf("n=%d", ¶metros[0]); scanf("a=%lf", ¶metros[1]); scanf("b=%lf", ¶metros[2]); if(n%comm_sz != 0) { printf("El numero de trapecios debe ser múltiplo del número de procesos\n"); MPI_Abort(MPI_COMM_WORLD, rc); exit(1); } MPI_Bcast(¶metros,3,MPI_DOUBLE,0,MPI_COMM_WORLD); } h=(b-a)/n; /*h is the same for all processes*/ local_n= n/comm_sz; /* number of trapezoids, same for all processes*/ local_a = a+my_rank*local_n*h; local_b = local_a+local_n*h; local_int=Trap(local_a, local_b, local_n, h); MPI_Reduce(&local_int,&total_int,1,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD); if(my_rank==0){ printf("Integral from %f to %f = %.15e\n", a, b, total_int); } MPI_Finalize(); return 0; } /*main*/
int main(int argc, char *argv[]) { int my_rank; int p; float a = 0.0; float b = 1.0f; int n = 1024; float h; float local_a; float local_b; int local_n; float integral; float total; int source; int dest = 0; int tag = 0; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); MPI_Comm_size(MPI_COMM_WORLD, &p); Get_data2(&a, &b, &n, my_rank); h = (b - a) / n; local_n = n / p; local_a = a + my_rank* local_n * h; local_b = local_a + local_n * h; integral = Trap(local_a, local_b, local_n, h); if (my_rank == 0) { total = integral; for (source = 1; source < p; source++) { MPI_Recv(&integral, 1, MPI_FLOAT, source, tag, MPI_COMM_WORLD, &status); total = total + integral; } } else { MPI_Send(&integral, 1, MPI_FLOAT, dest, tag, MPI_COMM_WORLD); } if (my_rank == 0) { printf("With n = %d trapezoids, our estimate\n", n); printf("of the integral from %f to %f = %f\n", a, b, total); } MPI_Finalize(); }
// 9.5.5 Xfer Traps // CheckForXferTraps: PROC[dst: ConrolLink, type: XferType] static inline void CheckForXferTraps(ControlLink dst, int type) { if (Odd(XTS)) { GlobalWord word = {*Fetch(GO_OFFSET(GF, word))}; if (word.trapxfers) { XTS = XTS >> 1; if (DEBUG_SHOW_XFER_TRAP) logger.debug("XferTrap %08X %d", dst, type); Trap(SD + OFFSET_SD(sXferTrap)); *StoreLF(0) = LowHalf(dst); *StoreLF(1) = HighHalf(dst); *StoreLF(2) = type; ERROR_Abort(); } } else {
int main(void) { int my_rank, comm_sz, n = 1024, local_n; double a = 0.0, b = 3.0, h, local_a, local_b; double local_int, total_int; int source; /* Let the system do what it needs to start up MPI */ MPI_Init(NULL, NULL); /* Get my process rank */ MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); /* Find out how many processes are being used */ MPI_Comm_size(MPI_COMM_WORLD, &comm_sz); h = (b-a)/n; /* h is the same for all processes */ local_n = n/comm_sz; /* So is the number of trapezoids */ /* Length of each process' interval of * integration = local_n*h. So my interval * starts at: */ local_a = a + my_rank*local_n*h; local_b = local_a + local_n*h; local_int = Trap(local_a, local_b, local_n, h); /* Add up the integrals calculated by each process */ if (my_rank != 0) { MPI_Send(&local_int, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD); } else { total_int = local_int; for (source = 1; source < comm_sz; source++) { MPI_Recv(&local_int, 1, MPI_DOUBLE, source, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); total_int += local_int; } } /* Print the result */ if (my_rank == 0) { printf("With n = %d trapezoids, our estimate\n", n); printf("of the integral from %f to %f = %.15e\n", a, b, total_int); } /* Shut down MPI */ MPI_Finalize(); return 0; } /* main */
int main(int argc, char* argv[ ]) { double global_result = 0.0; double a, b; int n, thread_count; thread_count = strtol(argv[1], NULL, 10); printf("Enter a, b, and n:\n"); scanf("%lf %lf %d", &a, &b, &n); # pragma omp parallel num_threads(thread_count) Trap(a, b, n, &global_result); printf("With n = %d trapezoids, our estimate of the integral\n", n); printf("of function f from %f to %f = %f\n", a, b, global_result); return 0; }
int main(int argc, char* argv[]) { double global_result = 0.0; /* Store result in global_result */ double a, b; /* Left and right endpoints */ int n; /* Total number of trapezoids */ int thread_count; if (argc != 2) Usage(argv[0]); thread_count = strtol(argv[1], NULL, 10); printf("Enter a, b, and n\n"); scanf("%lf %lf %d", &a, &b, &n); global_result = Trap(a, b, n, thread_count); printf("With n = %d trapezoids, our estimate\n", n); printf("of the integral from %f to %f = %.14e\n", a, b, global_result); return 0; } /* main */
int main(void) { double area; /* Store result in area */ double a, b; /* Left and right endpoints */ int n; /* Number of trapezoids */ double h; /* Trapezoid base width */ printf("Enter a, b, and n\n"); scanf("%lf", &a); scanf("%lf", &b); scanf("%d", &n); h = (b-a)/n; area = Trap(a, b, n, h); printf("With n = %d trapezoids, our estimate\n", n); printf("of the area from %f to %f = %.15f\n", a, b, area); return 0; } /* main */
int main(int argc, char** argv) { double n, h, total_int; double start, finish, elapsed; Get_input(argc, argv, &n); /*Read user input */ h = (b-a)/n; /* length of each trapezoid */ start = clock(); /* Calculate integral using endpoints*/ total_int = Trap(a, b, n, h); finish = clock(); elapsed = (double)(finish-start)/CLOCKS_PER_SEC; printf("With n = %.0f trapezoids, our estimate\n", n); printf("of the integral from %.0f to %.0f = %.0f\n", a, b, total_int); printf("Elapsed time = %f milliseconds \n", elapsed * 1000); return 0; } /* main */
*/ static void Loop_Integer(REBVAL *out, REBVAL *var, REBSER* body, REBI64 start, REBI64 end, REBI64 incr) /* ***********************************************************************/ { VAL_SET(var, REB_INTEGER); SET_NONE(out); // Default result to NONE if the loop does not run while ((incr > 0) ? start <= end : start >= end) { VAL_INT64(var) = start; if (!DO_BLOCK(out, body, 0) && Check_Error(out) >= 0) break; if (!IS_INTEGER(var)) Trap_Type(var); start = VAL_INT64(var); if (REB_I64_ADD_OF(start, incr, &start)) { Trap(RE_OVERFLOW); } } }
int main(void) { int comm_sz; double integral; struct timeval start, end; /* Lê os dados de entrada e envia aos processos */ gettimeofday(&start, NULL); double lb, ub; int trap_count; scanf("%lf %lf %d", &lb, &ub, &trap_count); integral = Trap(0, lb, ub, (ub-lb)/trap_count, trap_count); printf("%.5lf\n", integral); gettimeofday(&end, NULL); int duration = ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)); printf("%d\n", duration); return 0; }
virtual ResultExpr EvaluateSyscall(int sysno) const override { switch (sysno) { // Simulate opening the plugin file. #ifdef __NR_open case __NR_open: #endif case __NR_openat: return Trap(OpenTrap, mPlugin); // ipc::Shmem case __NR_mprotect: return Allow(); case __NR_madvise: { Arg<int> advice(2); return If(advice == MADV_DONTNEED, Allow()) .Else(InvalidSyscall()); } default: return SandboxPolicyCommon::EvaluateSyscall(sysno); } }
*/ void Subtract_Date(REBVAL *d1, REBVAL *d2, REBVAL *result) /* ** Called by DIFFERENCE function. ** ***********************************************************************/ { REBINT diff; REBI64 t1; REBI64 t2; diff = Diff_Date(VAL_DATE(d1), VAL_DATE(d2)); if (cast(REBCNT, abs(diff)) > (((1U << 31) - 1) / SECS_IN_DAY)) Trap(RE_OVERFLOW); t1 = VAL_TIME(d1); if (t1 == NO_TIME) t1 = 0L; t2 = VAL_TIME(d2); if (t2 == NO_TIME) t2 = 0L; VAL_SET(result, REB_TIME); VAL_TIME(result) = (t1 - t2) + ((REBI64)diff * TIME_IN_DAY); }
Room::Room(int room) { number = room; Boss endBoss = Boss(10); RandomGenerator rg; size = RoomSize[rg.getRandom(0, 2)]; content = RoomContent[rg.getRandom(0, 3)]; description = RoomDescription[rg.getRandom(0, 3)]; appearance = RoomAppearance[rg.getRandom(0, 3)]; lighting = RoomLighting[rg.getRandom(0, 3)]; color = RoomColor[rg.getRandom(0, 3)]; connected[RoomDirection::NORTH] = nullptr; connected[RoomDirection::EAST] = nullptr; connected[RoomDirection::SOUTH] = nullptr; connected[RoomDirection::WEST] = nullptr; visited = false; visiting = false; exit = false; equipment.push_back(Equipment()); if (rg.getRandom(0, 100) < 20) traps.push_back(Trap()); }
*/ void Pop_Stack_Values(REBVAL *out, REBINT dsp_start, REBOOL into) /* ** Pop_Stack_Values computed values from the stack into the series ** specified by "into", or if into is NULL then store it as a ** block on top of the stack. (Also checks to see if into ** is protected, and will trigger a trap if that is the case.) ** ** Protocol for /INTO is to set the position to the tail. ** ***********************************************************************/ { REBSER *series; REBCNT len = DSP - dsp_start; REBVAL *values = BLK_SKIP(DS_Series, dsp_start + 1); if (into) { assert(ANY_BLOCK(out)); series = VAL_SERIES(out); if (IS_PROTECT_SERIES(series)) Trap(RE_PROTECTED); VAL_INDEX(out) = Insert_Series( series, VAL_INDEX(out), cast(REBYTE*, values), len ); } else {
virtual ResultExpr InvalidSyscall() const override { return Trap(BlockedSyscallTrap, nullptr); }
main(int argc, char** argv) { int my_rank; /* My process rank */ int p; /* The number of processes */ float a; /* Left endpoint */ float b; /* Right endpoint */ int n; /* Number of trapezoids */ float h; /* Trapezoid base length */ float local_a; /* Left endpoint my process */ float local_b; /* Right endpoint my process */ int local_n; /* Number of trapezoids for */ /* my calculation */ float integral; /* Integral over my interval */ float total; /* Total integral */ int source; /* Process sending integral */ int dest = 0; /* All messages go to 0 */ int tag = 0; MPI_Status status; void Get_data(float* a_ptr, float* b_ptr, int* n_ptr, int my_rank, int p); float Trap(float local_a, float local_b, int local_n, float h); /* Calculate local integral */ /* Let the system do what it needs to start up MPI */ MPI_Init(&argc, &argv); /* Get my process rank */ MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); /* Find out how many processes are being used */ MPI_Comm_size(MPI_COMM_WORLD, &p); Get_data(&a, &b, &n, my_rank, p); h = (b-a)/n; /* h is the same for all processes */ local_n = n/p; /* So is the number of trapezoids */ /* Length of each process' interval of * integration = local_n*h. So my interval * starts at: */ local_a = a + my_rank*local_n*h; local_b = local_a + local_n*h; integral = Trap(local_a, local_b, local_n, h); /* Add up the integrals calculated by each process */ if (my_rank == 0) { total = integral; for (source = 1; source < p; source++) { MPI_Recv(&integral, 1, MPI_FLOAT, source, tag, MPI_COMM_WORLD, &status); total = total + integral; } } else { MPI_Send(&integral, 1, MPI_FLOAT, dest, tag, MPI_COMM_WORLD); } /* Print the result */ if (my_rank == 0) { printf("With n = %d trapezoids, our estimate\n", n); printf("of the integral from %f to %f = %f\n", a, b, total); } /* Shut down MPI */ MPI_Finalize(); } /* main */
virtual ResultExpr EvaluateSyscall(int sysno) const override { switch (sysno) { // Timekeeping case __NR_clock_gettime: { Arg<clockid_t> clk_id(0); return If(clk_id == CLOCK_MONOTONIC, Allow()) .ElseIf(clk_id == CLOCK_REALTIME, Allow()) .Else(InvalidSyscall()); } case __NR_gettimeofday: #ifdef __NR_time case __NR_time: #endif case __NR_nanosleep: return Allow(); // Thread synchronization case __NR_futex: // FIXME: This could be more restrictive.... return Allow(); // Asynchronous I/O case __NR_epoll_wait: case __NR_epoll_pwait: case __NR_epoll_ctl: case __NR_ppoll: case __NR_poll: return Allow(); // Used when requesting a crash dump. case __NR_pipe: return Allow(); // Metadata of opened files CASES_FOR_fstat: return Allow(); // Simple I/O case __NR_write: case __NR_read: case __NR_writev: // see SandboxLogging.cpp return Allow(); // Memory mapping CASES_FOR_mmap: case __NR_munmap: return Allow(); // Signal handling #if defined(ANDROID) || defined(MOZ_ASAN) case __NR_sigaltstack: #endif CASES_FOR_sigreturn: CASES_FOR_sigprocmask: CASES_FOR_sigaction: return Allow(); // Send signals within the process (raise(), profiling, etc.) case __NR_tgkill: { Arg<pid_t> tgid(0); return If(tgid == getpid(), Allow()) .Else(InvalidSyscall()); } #if defined(ANDROID) && ANDROID_VERSION < 16 // Polyfill with tgkill; see above. case __NR_tkill: return Trap(TKillCompatTrap, nullptr); #endif // Yield case __NR_sched_yield: return Allow(); // Thread creation. case __NR_clone: return ClonePolicy(); // More thread creation. #ifdef __NR_set_robust_list case __NR_set_robust_list: return Allow(); #endif #ifdef ANDROID case __NR_set_tid_address: return Allow(); #endif // prctl case __NR_prctl: return PrctlPolicy(); // NSPR can call this when creating a thread, but it will accept a // polite "no". case __NR_getpriority: // But if thread creation races with sandbox startup, that call // could succeed, and then we get one of these: case __NR_setpriority: return Error(EACCES); // Stack bounds are obtained via pthread_getattr_np, which calls // this but doesn't actually need it: case __NR_sched_getaffinity: return Error(ENOSYS); // Read own pid/tid. case __NR_getpid: case __NR_gettid: return Allow(); // Discard capabilities case __NR_close: return Allow(); // Machine-dependent stuff #ifdef __arm__ case __ARM_NR_breakpoint: case __ARM_NR_cacheflush: case __ARM_NR_usr26: // FIXME: do we actually need this? case __ARM_NR_usr32: case __ARM_NR_set_tls: return Allow(); #endif // Needed when being debugged: case __NR_restart_syscall: return Allow(); // Terminate threads or the process case __NR_exit: case __NR_exit_group: return Allow(); #ifdef MOZ_ASAN // ASAN's error reporter wants to know if stderr is a tty. case __NR_ioctl: { Arg<int> fd(0); return If(fd == STDERR_FILENO, Allow()) .Else(InvalidSyscall()); } // ...and before compiler-rt r209773, it will call readlink on // /proc/self/exe and use the cached value only if that fails: case __NR_readlink: case __NR_readlinkat: return Error(ENOENT); // ...and if it found an external symbolizer, it will try to run it: // (See also bug 1081242 comment #7.) CASES_FOR_stat: return Error(ENOENT); #endif default: return SandboxPolicyBase::EvaluateSyscall(sysno); } }
// TrapTwo: PROC[ptr POINTER TO ControlLink, parameter: LONG UNSPEC] static inline void TrapTwo(POINTER ptr, UNSPEC parameter) { Trap(ptr); *StoreLF(0) = LowHalf(parameter); *StoreLF(1) = HighHalf(parameter); ERROR_Abort(); }
int main() { int a[] = {0,1,0,5,1,0,1,3,2,1,2,1}; assert(Trap(a, 12) == 9); return 0; }
// TrapOne: PROC[ptr POINTER TO ControlLink, parameter: UNSPEC] static inline void TrapOne(POINTER ptr, UNSPEC parameter) { Trap(ptr); *StoreLF(0) = parameter; ERROR_Abort(); }
// TrapZero: PROC[ptr: POINTER TO ControlLink] static inline void TrapZero(POINTER ptr) { Trap(ptr); ERROR_Abort(); }
int main(int argc, char** argv) { float a, b, step, process_n; int n; // Initialize the MPI environment MPI_Init(NULL, NULL); // Get the number of processes int world_size; MPI_Comm_size(MPI_COMM_WORLD, &world_size); // Get the rank of the process int world_rank; MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); // Get the name of the processor char processor_name[MPI_MAX_PROCESSOR_NAME]; int name_len; MPI_Get_processor_name(processor_name, &name_len); if (world_rank == 0) { a = 0; b = 1; n = 1000; //number of traps per process, round up in case //of indivisible amount process_n = ceil( ((float)n) / ((float)world_size) ); //Update n so when I print it at the end it's correct n = process_n * world_size; } // printf("n = %d, process %d \n", n, world_rank); //Broadcast relevant information to all processes MPI_Bcast(&a, 1, MPI_FLOAT, 0, MPI_COMM_WORLD); MPI_Bcast(&b, 1, MPI_FLOAT, 0, MPI_COMM_WORLD); MPI_Bcast(&process_n, 1, MPI_FLOAT, 0, MPI_COMM_WORLD); // printf("n = %f, process %d \n", process_n, world_rank); float local_a, local_b, local_result; //Process specific start point local_a = ((b - a) / world_size) * world_rank + a; //Process specific end point local_b = ((b - a) / world_size) * (world_rank + 1) + a; // printf("a = %f, b = %f, process %d \n", local_a, local_b, world_rank); local_result = Trap(local_a, local_b, process_n); // printf("result = %f, process %d \n", local_result, world_rank); //Send results, adding along the way //Account for 1 process case if (world_size > 1) { //Start sending with last process if (world_rank == (world_size-1)) { MPI_Send(&local_result, 1, MPI_FLOAT, world_rank-1, 0, MPI_COMM_WORLD); } else { //temp variable so the receive doesn't overwrite float temp = local_result; //Receive intermediate result MPI_Recv(&local_result, 1, MPI_FLOAT, world_rank+1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); local_result += temp; //Add intermediate result to current total //Send new intermediate result along if (world_rank != 0) { MPI_Send(&local_result, 1, MPI_FLOAT, world_rank-1, 0, MPI_COMM_WORLD); } //Display final result else { printf("Final result with %d trapezoids = %f \n", n, local_result); } } } else { printf("Final result with %d trapezoids = %f \n", n, local_result); } MPI_Finalize(); }
*/ static void Check_Overflow(REBDEC dval) /* ***********************************************************************/ { if (!FINITE(dval)) Trap(RE_OVERFLOW); }
bool BaseAI::startTurn() { static bool initialized = false; int count = 0; count = getPlayerCount(c); players.clear(); players.resize(count); for(int i = 0; i < count; i++) { players[i] = Player(getPlayer(c, i)); } count = getMappableCount(c); mappables.clear(); mappables.resize(count); for(int i = 0; i < count; i++) { mappables[i] = Mappable(getMappable(c, i)); } count = getTileCount(c); tiles.clear(); tiles.resize(count); for(int i = 0; i < count; i++) { tiles[i] = Tile(getTile(c, i)); } count = getTrapCount(c); traps.clear(); traps.resize(count); for(int i = 0; i < count; i++) { traps[i] = Trap(getTrap(c, i)); } count = getThiefCount(c); thiefs.clear(); thiefs.resize(count); for(int i = 0; i < count; i++) { thiefs[i] = Thief(getThief(c, i)); } count = getThiefTypeCount(c); thiefTypes.clear(); thiefTypes.resize(count); for(int i = 0; i < count; i++) { thiefTypes[i] = ThiefType(getThiefType(c, i)); } count = getTrapTypeCount(c); trapTypes.clear(); trapTypes.resize(count); for(int i = 0; i < count; i++) { trapTypes[i] = TrapType(getTrapType(c, i)); } if(!initialized) { initialized = true; init(); } return run(); }