particle *MakeParticle(particle *P, REAL ENE, REAL ANG, REAL AZI, unsigned int *seed) { REAL angle, azimuth; P->type = PROTON; P->energy = ENE; angle = ANG * M_PI / AS_REAL(180.0); azimuth = AZI * M_PI / AS_REAL(180.0); position_particle(azimuth, angle, P); #if DO_ELASTIC GenerateElasticDistances(P, seed); #endif #if MIN_TRACE P->eloss = AS_REAL(0.0); P->where = WhereAmI(P->pos[CX], P->pos[CY], P->pos[CZ]); #endif #if GOM_DEBUG if (VERBOSE) { print_particle("Made particle:", P); } #endif return(P); }
void *blas_memory_alloc(int procpos){ int position; #if defined(WHEREAMI) && !defined(USE_OPENMP) int mypos; #endif void *map_address; void *(*memoryalloc[])(void *address) = { #ifdef ALLOC_DEVICEDRIVER alloc_devicedirver, #endif #if defined OS_LINUX || defined OS_AIX || defined __sun__ || defined OS_WINDOWS alloc_hugetlb, #endif #ifdef ALLOC_SHM alloc_shm, #endif #ifdef ALLOC_MMAP alloc_mmap, #endif #ifdef ALLOC_QALLOC alloc_qalloc, #endif #ifdef ALLOC_WINDOWS alloc_windows, #endif #ifdef ALLOC_MALLOC alloc_malloc, #endif NULL, }; void *(**func)(void *address); if (!memory_initialized) { LOCK_COMMAND(&alloc_lock); if (!memory_initialized) { #if defined(WHEREAMI) && !defined(USE_OPENMP) for (position = 0; position < NUM_BUFFERS; position ++){ memory[position].addr = (void *)0; memory[position].pos = -1; memory[position].used = 0; memory[position].lock = 0; } #endif #ifdef DYNAMIC_ARCH gotoblas_dynamic_init(); #endif #if defined(SMP) && defined(OS_LINUX) && !defined(NO_AFFINITY) gotoblas_affinity_init(); #endif #ifdef SMP if (!blas_num_threads) blas_cpu_number = blas_get_cpu_number(); #endif #if defined(ARCH_X86) || defined(ARCH_X86_64) || defined(ARCH_IA64) || defined(ARCH_MIPS64) #ifndef DYNAMIC_ARCH blas_set_parameter(); #endif #endif memory_initialized = 1; } UNLOCK_COMMAND(&alloc_lock); } #ifdef DEBUG printf("Alloc Start ...\n"); #endif #if defined(WHEREAMI) && !defined(USE_OPENMP) mypos = WhereAmI(); position = mypos; while (position > NUM_BUFFERS) position >>= 1; do { if (!memory[position].used && (memory[position].pos == mypos)) { blas_lock(&memory[position].lock); if (!memory[position].used) goto allocation; blas_unlock(&memory[position].lock); } position ++; } while (position < NUM_BUFFERS); #endif position = 0; do { if (!memory[position].used) { blas_lock(&memory[position].lock); if (!memory[position].used) goto allocation; blas_unlock(&memory[position].lock); } position ++; } while (position < NUM_BUFFERS); goto error; allocation : #ifdef DEBUG printf(" Position -> %d\n", position); #endif memory[position].used = 1; blas_unlock(&memory[position].lock); if (!memory[position].addr) { do { #ifdef DEBUG printf("Allocation Start : %lx\n", base_address); #endif map_address = (void *)-1; func = &memoryalloc[0]; while ((func != NULL) && (map_address == (void *) -1)) { map_address = (*func)((void *)base_address); #ifdef ALLOC_DEVICEDRIVER if ((*func == alloc_devicedirver) && (map_address == (void *)-1)) { fprintf(stderr, "OpenBLAS Warning ... Physically contigous allocation was failed.\n"); } #endif #ifdef ALLOC_HUGETLBFILE if ((*func == alloc_hugetlbfile) && (map_address == (void *)-1)) { #ifndef OS_WINDOWS fprintf(stderr, "OpenBLAS Warning ... HugeTLB(File) allocation was failed.\n"); #endif } #endif #if defined OS_LINUX || defined OS_AIX || defined __sun__ || defined OS_WINDOWS if ((*func == alloc_hugetlb) && (map_address != (void *)-1)) hugetlb_allocated = 1; #endif func ++; } #ifdef DEBUG printf(" Success -> %08lx\n", map_address); #endif if (((BLASLONG) map_address) == -1) base_address = 0UL; if (base_address) base_address += BUFFER_SIZE + FIXED_PAGESIZE; } while ((BLASLONG)map_address == -1); memory[position].addr = map_address; #ifdef DEBUG printf(" Mapping Succeeded. %p(%d)\n", (void *)memory[position].addr, position); #endif } #if defined(WHEREAMI) && !defined(USE_OPENMP) if (memory[position].pos == -1) memory[position].pos = mypos; #endif #ifdef DYNAMIC_ARCH if (memory_initialized == 1) { LOCK_COMMAND(&alloc_lock); if (memory_initialized == 1) { if (!gotoblas) gotoblas_dynamic_init(); memory_initialized = 2; } UNLOCK_COMMAND(&alloc_lock); } #endif #ifdef DEBUG printf("Mapped : %p %3d\n\n", (void *)memory[position].addr, position); #endif return (void *)memory[position].addr; error: printf("BLAS : Program is Terminated. Because you tried to allocate too many memory regions.\n"); return NULL; }
void Disperse2() { double xmin, xmax, ymin, ymax, zmin, zmax, x, y, z, u, v, w; long uni0, cell0, root, cell, id, n; unsigned long seed; char uname[MAX_STR], cname[MAX_STR]; /***************************************************************************/ /***** Prompt input data ***************************************************/ return; /* Get universe */ fprintf(out, "Enter universe:\n"); if (scanf("%s", uname) == EOF) Die(FUNCTION_NAME, "fscanf error"); /* Get cell */ fprintf(out, "Enter cell:\n"); if (scanf("%s", cname) == EOF) Die(FUNCTION_NAME, "fscanf error"); /***************************************************************************/ /***** Find cell and universe pointers *************************************/ /* Loop over universes */ uni0 = (long)RDB[DATA_PTR_U0]; while (uni0 > VALID_PTR) { /* Compare name */ if (!strcmp(GetText(uni0 + UNIVERSE_PTR_NAME), uname)) break; /* Next */ uni0 = NextItem(uni0); } /* Check pointer */ if (uni0 < VALID_PTR) Error(0, "Universe %s not found in geometry", uname); /* Loop over cells */ cell0 = (long)RDB[DATA_PTR_C0]; while (cell0 > VALID_PTR) { /* Compare name */ if (!strcmp(GetText(cell0 + CELL_PTR_NAME), cname)) break; /* Next */ cell0 = NextItem(cell0); } /* Check pointer */ if (cell0 < VALID_PTR) Error(0, "Cell %s not found in geometry", cname); /* Set thread id */ id = 0; /* Init random number sequence */ seed = ReInitRNG(1); SEED[0] = seed; /* Set plotter mode to avoid termination in geometry error, and quick */ /* plotter mode to disable overlap check */ WDB[DATA_PLOTTER_MODE] = (double)YES; WDB[DATA_QUICK_PLOT_MODE] = (double)YES; /* Override root universe pointer */ root = (long)RDB[DATA_PTR_ROOT_UNIVERSE]; WDB[DATA_PTR_ROOT_UNIVERSE] = (double)uni0; /***************************************************************************/ /***** Sample code *********************************************************/ /* Check pointers */ CheckPointer(FUNCTION_NAME, "(uni0)", DATA_ARRAY, uni0); CheckPointer(FUNCTION_NAME, "(cell0)", DATA_ARRAY, cell0); /* Get universe boundaries */ xmin = RDB[uni0 + UNIVERSE_MINX]; xmax = RDB[uni0 + UNIVERSE_MAXX]; ymin = RDB[uni0 + UNIVERSE_MINY]; ymax = RDB[uni0 + UNIVERSE_MAXY]; zmin = RDB[uni0 + UNIVERSE_MINZ]; zmax = RDB[uni0 + UNIVERSE_MAXZ]; fprintf(out, "\nboundaries : \nx = [%E,%E] \ny = [%E %E] \nz = [%E %E]\n\n", xmin, xmax, ymin, ymax, zmin, zmax); /* Set direction vector (needed but not used) */ u = 1.0; v = 0.0; w = 0.0; /* Sample 1000 random points and print coordinates that are inside the */ /* universe and cell */ for (n = 0; n < 1000; n++) { /* Sample random point */ x = RandF(id)*(xmax - xmin) + xmin; y = RandF(id)*(ymax - ymin) + ymin; z = RandF(id)*(zmax - zmin) + zmin; /* Get cell pointer at position */ cell = WhereAmI(x, y, z, u, v, w, id); /* Check pointer and print coordinates */ if (cell == cell0) fprintf(out, "%E %E %E\n", x, y, z); } /***************************************************************************/ /* Reset plotter mode */ WDB[DATA_PLOTTER_MODE] = (double)YES; /* Put root universe pointer */ WDB[DATA_PTR_ROOT_UNIVERSE] = (double)root; /* Terminate calculation */ exit(0); }
long MoveDT(long part, double majorant, double minxs, long *cell, double *xs0, double *x, double *y, double *z, double *l0, double *u, double *v, double *w, double E, long id) { long ptr, type, mat, mat0, bc; double totxs, l, wgt; /* Check particle pointer */ CheckPointer(FUNCTION_NAME, "(part)", DATA_ARRAY, part); /* Check coordinates and direction cosines */ CheckValue(FUNCTION_NAME, "x", "", *x, -INFTY, INFTY); CheckValue(FUNCTION_NAME, "y", "", *y, -INFTY, INFTY); CheckValue(FUNCTION_NAME, "z", "", *z, -INFTY, INFTY); CheckValue(FUNCTION_NAME, "u", "", *u, -1.0, 1.0); CheckValue(FUNCTION_NAME, "v", "", *v, -1.0, 1.0); CheckValue(FUNCTION_NAME, "w", "", *w, -1.0, 1.0); /* Get particle type */ type = (long)RDB[part + PARTICLE_TYPE]; /* Add to DT fraction counter */ ptr = (long)RDB[RES_DT_TRACK_FRAC]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); AddBuf1D(1.0, 1.0, ptr, id, 2 - type); /* Check cross section and sample path length */ CheckValue(FUNCTION_NAME, "majorant", "", majorant, ZERO, INFTY); l = -log(RandF(id))/majorant; /* Move particle to collision site */ *x = *x + *u*l; *y = *y + *v*l; *z = *z + *w*l; /* Set path length */ *l0 = l; /* Reset previous material pointer and total xs */ mat0 = -1; totxs = 0.0; /* Find location */ *cell = WhereAmI(*x, *y, *z, *u, *v, *w, id); CheckPointer(FUNCTION_NAME, "(cell)", DATA_ARRAY, *cell); /* Check if point is outside the geometry */ if ((long)RDB[*cell + CELL_TYPE] == CELL_TYPE_OUTSIDE) { /* Check if track is stopped at outer boundary */ if ((long)RDB[DATA_STOP_AT_BOUNDARY] == NO) { /* Set weight to test that albedo boundary conditions were not */ /* applied */ wgt = 1.0; /* Apply repeated boundary conditions */ bc = BoundaryConditions(cell, x, y, z, u, v, w, &wgt, id); /* Check that condition was applied */ if (bc != YES) Die(FUNCTION_NAME, "Repeated bc not apllied"); /* Check change in weight */ if (wgt != 1.0) Die(FUNCTION_NAME, "Change in weight (albedo)"); /* Find location */ *cell = WhereAmI(*x, *y, *z, *u, *v, *w, id); CheckPointer(FUNCTION_NAME, "(cell)", DATA_ARRAY, *cell); } else { /* Stop track at boundary */ StopAtBoundary(cell, x, y, z, l0, *u, *v, *w, id); /* Set cross section */ *xs0 = -1.0; /* Check distance */ CheckValue(FUNCTION_NAME, "l0", "", *l0, ZERO, INFTY); /* Return surface crossing */ return TRACK_END_SURF; } } /* Get material pointer */ mat = (long)RDB[*cell + CELL_PTR_MAT]; mat = MatPtr(mat, id); /* Check pointer */ if (mat != mat0) { /* Get total cross section */ totxs = TotXS(mat, type, E, id); /* Remember material */ mat0 = mat; } /* Check total xs */ CheckValue(FUNCTION_NAME, "totxs", "", totxs, 0.0, INFTY); /* Compare to minimum value */ if (totxs > minxs) { /* Sample between real and virtual collision */ if (RandF(id) < totxs/majorant) { /* Set cross section */ *xs0 = totxs; /* Add to success counter */ ptr = (long)RDB[RES_DT_TRACK_EFF]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY,ptr); AddBuf1D(1.0, 1.0, ptr, id, 2 - type); /* Check distance */ CheckValue(FUNCTION_NAME, "l0", "", *l0, ZERO, INFTY); /* Return collision */ return TRACK_END_COLL; } else { /* Set cross section */ *xs0 = -1.0; /* Add to failure counter */ ptr = (long)RDB[RES_DT_TRACK_EFF]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY,ptr); AddBuf1D(1.0, 1.0, ptr, id, 4 - type); /* Check distance */ CheckValue(FUNCTION_NAME, "l0", "", *l0, ZERO, INFTY); /* Return virtual */ return TRACK_END_VIRT; } } else { /* Sample scoring */ if (RandF(id) < minxs/majorant) { /* Set cross section */ *xs0 = minxs; /* Sample between real and virtual collision */ if (RandF(id) < totxs/minxs) { /* Add to success counter */ ptr = (long)RDB[RES_DT_TRACK_EFF]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY,ptr); AddBuf1D(1.0, 1.0, ptr, id, 2 - type); /* Check distance */ CheckValue(FUNCTION_NAME, "l0", "", *l0, ZERO, INFTY); /* Return collision */ return TRACK_END_COLL; } else { /* Add to failure counter */ ptr = (long)RDB[RES_DT_TRACK_EFF]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY,ptr); AddBuf1D(1.0, 1.0, ptr, id, 4 - type); /* Check distance */ CheckValue(FUNCTION_NAME, "l0", "", *l0, ZERO, INFTY); /* Return virtual */ return TRACK_END_VIRT; } } else { /* Set cross section */ *xs0 = -1.0; /* Add to failure counter */ ptr = (long)RDB[RES_DT_TRACK_EFF]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY,ptr); AddBuf1D(1.0, 1.0, ptr, id, 4 - type); /* Check distance */ CheckValue(FUNCTION_NAME, "l0", "", *l0, ZERO, INFTY); /* Return virtual */ return TRACK_END_VIRT; } } }
// Remember that this function is called at 2hz static int OnTimerNotify(WindowControl *Sender) { static short rezoom=0; static short limiter=0; // safe limiter #define ORCREZOOM 2 // We wait for some time before forcing nearest search, because we need to be sure // that the visibility scan is updated if (--WaitToCallForce>0) { if (WaitToCallForce==1) { #ifdef DEBUG_ORTIMER StartupStore(_T("..... Force Calculation\n")); #endif MapWindow::RefreshMap(); // trigger rescan or we shall wait for 2 seconds more! LKSW_ForceNearestTopologyCalculation=true; // set wait times for zoom effective in the background and return rezoom=ORCREZOOM; limiter=0; } #ifdef DEBUG_ORTIMER else { StartupStore(_T("..... WaitToCallForce\n")); } #endif return 0; } // If the Nearest topology calculation is still running we wait if (LKSW_ForceNearestTopologyCalculation) { if (++limiter > 20) { // Something is wrong, lets get out of here because there is no exit button! StartupStore(_T("...... Oracle ForceNearestTopo limit exceeded, aborting search%s"),NEWLINE); LKSW_ForceNearestTopologyCalculation=false; // time exceeded, reset forced limiter=0; rezoom=0; goto _end; } #ifdef DEBUG_ORTIMER StartupStore(_T("..... Wait for ForceNearest done\n")); #endif return 0; } limiter=0; // probably useless // Ok the ForceNearestTopo was cleared by Terrain search, so we have the nearesttopo items ready. // Do we need still to rezoom for letting whereami search for nearest waypoints in a visibility // screen range? if (rezoom>0) { // Extend a wide search of farvisible items // We do it now that nearestTopology has been calculated, // because WhereAmI will issue some Nearest search on waypoints // and we need to include airports a bit more far away if (rezoom==ORCREZOOM) { #ifdef DEBUG_ORTIMER StartupStore(_T("..... REZOOM\n")); #endif MapWindow::zoom.EventSetZoom(6); MapWindow::ForceVisibilityScan=true; MapWindow::RefreshMap(); } #ifdef DEBUG_ORTIMER else StartupStore(_T("..... WAIT AFTER REZOOM\n")); #endif // rezoom once, then wait rezoom--; return 0; } _end: #ifdef DEBUG_ORTIMER StartupStore(_T("..... LETS GO\n")); #endif // Dont come back here anymore! wf->SetTimerNotify(NULL); // Bell, and print results if (EnableSoundModes) LKSound(TEXT("LK_GREEN.WAV")); WhereAmI(); // Remember to force exit from showmodal, because there is no Close button wf->SetModalResult(mrOK); return 0; }