/* PUBLIC */ Fpa_chunk flist_delete(Fpa_chunk f, Term x) { if (f == NULL) fprintf(stderr, "WARNING: flist_delete, item %p not found (1)!\n", x); else if (FLT(x,FLAST(f))) f->next = flist_delete(f->next, x); else { int n = f->n; int i = FMAX - n; while (i < FMAX && FLT(x,f->d[i])) i++; if (x != f->d[i]) fprintf(stderr, "WARNING: flist_delete, item %p not found (2)!\n", x); else { /* delete and close the hole */ int j; for (j = i; j > FMAX-n; j--) f->d[j] = f->d[j-1]; f->d[j] = NULL; f->n = n-1; if (f->n == 0) { /* delete this chunk */ Fpa_chunk next = f->next; free_fpa_chunk(f); f = next; } else { /* try to join this chunk with the next */ f = consolidate(f); } } } return f; } /* flist_delete */
// feed adaptation data from a batch file containing entries (rawFile alignmentFile) void FMLLREstimator::feedAdaptationData(const char *strBatchFile, const char *strAlignmentFormat, double *dLikelihood) { BatchFile batchFile(strBatchFile,"features|alignment"); batchFile.load(); for(unsigned int i=0 ; i < batchFile.size() ; ++i) { //for(int i=0 ; i < 5 ; ++i) { // load the alignment Alignment *alignment = NULL; if (strcmp(strAlignmentFormat,"text") == 0) { AlignmentFile alignmentFile(m_phoneSet); VPhoneAlignment *vPhoneAlignment = alignmentFile.load(batchFile.getField(i,"alignment")); assert(vPhoneAlignment); alignment = AlignmentFile::toAlignment(m_phoneSet,m_hmmManager,vPhoneAlignment); AlignmentFile::destroyPhoneAlignment(vPhoneAlignment); } else { alignment = Alignment::load(batchFile.getField(i,"alignment"),NULL); assert(alignment); } // load the feature vectors FeatureFile featureFile(batchFile.getField(i,"features"),MODE_READ); featureFile.load(); Matrix<float> *mFeatures = featureFile.getFeatureVectors(); // load and apply the transform /* Transform *transform = new Transform(); transform->load("/data/daniel/tasks/wsj/experiments/may16th_2013_CMNUtterance/5/fmllr1/transforms/440m.fmllr.bin"); Matrix<float> *mFeaturesX = transform->apply(*mFeatures); mFeatures = mFeaturesX; delete transform; */ // check consistency if (mFeatures->getRows() != alignment->getFrames()) { BVC_ERROR << "inconsistent number of feature vectors / alignment file"; } // accumulate adaptation data double dLikelihoodAlignment = 0.0; feedAdaptationData(*mFeatures,alignment,&dLikelihoodAlignment); BVC_VERB << "loaded file: " << batchFile.getField(i,"alignment") << " likelihood: " << FLT(10,2) << dLikelihoodAlignment << " (" << mFeatures->getRows() << "frames)"; *dLikelihood += dLikelihoodAlignment; // clean-up delete alignment; delete mFeatures; } double dLikelihoodFrame = (*dLikelihood)/m_fOccupancyTotal; BVC_VERB << "total likelihood: " << FLT(20,6) << *dLikelihood << " (likelihood per frame: " << FLT(8,4) << dLikelihoodFrame << ")"; }
static void dump_immediate_verbose( struct tgsi_full_immediate *imm, unsigned ignored ) { unsigned i; TXT( "\nDataType : " ); ENM( imm->Immediate.DataType, TGSI_IMMS ); if( ignored ) { TXT( "\nPadding : " ); UIX( imm->Immediate.Padding ); } for( i = 0; i < imm->Immediate.Size - 1; i++ ) { EOL(); switch( imm->Immediate.DataType ) { case TGSI_IMM_FLOAT32: TXT( "\nFloat: " ); FLT( imm->u.ImmediateFloat32[i].Float ); break; default: assert( 0 ); } } }
static void dump_imm_data(struct tgsi_iterate_context *iter, union tgsi_immediate_data *data, unsigned num_tokens, unsigned data_type) { struct dump_ctx *ctx = (struct dump_ctx *)iter; unsigned i ; TXT( " {" ); assert( num_tokens <= 4 ); for (i = 0; i < num_tokens; i++) { switch (data_type) { case TGSI_IMM_FLOAT32: FLT( data[i].Float ); break; case TGSI_IMM_UINT32: UID(data[i].Uint); break; case TGSI_IMM_INT32: SID(data[i].Int); break; default: assert( 0 ); } if (i < num_tokens - 1) TXT( ", " ); } TXT( "}" ); }
// print the features (debugging) void FeatureFile::print(MatrixBase<float> &mFeatures, unsigned int iDelta) { assert((mFeatures.getCols()%iDelta) == 0); cout << endl; for(unsigned int i=0 ; i < mFeatures.getRows() ; ++i) { for(unsigned int j=0 ; j < iDelta ; ++j) { for(unsigned int h=0 ; h < mFeatures.getCols()/iDelta ; ++h) { cout << " " << FLT(9,6) << mFeatures(i,h+j*(mFeatures.getCols()/iDelta)); } cout << endl; } cout << endl; } }
void ENTRYPOINT three_d_box( three_d_handle handle, float x1, float x2, float y1, float y2, float z1, float z2, unsigned red, unsigned green, unsigned blue ) { if( hThreedDLL == NULL ) return; // Use a trick to pass floats rather than as doubles // (_Call16 is a varargs function, which makes all float // parameters passed as doubles) #define FLT(x) (*(long *) &(x)) _Call16( three_d_box_Proc, "wddddddwww", handle, FLT(x1), FLT(x2), FLT(y1), FLT(y2), FLT(z1), FLT(z2), red, green, blue ); }
static void dump_imm_data(struct tgsi_iterate_context *iter, union tgsi_immediate_data *data, unsigned num_tokens, unsigned data_type) { struct dump_ctx *ctx = (struct dump_ctx *)iter; unsigned i ; TXT( " {" ); assert( num_tokens <= 4 ); for (i = 0; i < num_tokens; i++) { switch (data_type) { case TGSI_IMM_FLOAT64: { union di d; d.ui = data[i].Uint | (uint64_t)data[i+1].Uint << 32; DBL( d.d ); i++; break; } case TGSI_IMM_FLOAT32: if (ctx->dump_float_as_hex) HFLT( data[i].Float ); else FLT( data[i].Float ); break; case TGSI_IMM_UINT32: UID(data[i].Uint); break; case TGSI_IMM_INT32: SID(data[i].Int); break; default: assert( 0 ); } if (i < num_tokens - 1) TXT( ", " ); } TXT( "}" ); }
/*! This function represents the core of the SPH density computation. The * target particle may either be local, or reside in the communication * buffer. */ int cs_update_weight_evaluate(int target, int mode, int *nexport, int *nsend_local) { int j, n; int startnode, numngb, listindex = 0; double h, h2, hinv, hinv3; double wk; double r, r2, u; MyLongDouble weighted_numngb; MyDouble *pos; weighted_numngb = 0; if(mode == 0) { pos = P[target].Pos; h = PPP[target].Hsml; } else { pos = UpdateweightGet[target].Pos; h = UpdateweightGet[target].Hsml; } h2 = h * h; hinv = 1.0 / h; #ifndef TWODIMS hinv3 = hinv * hinv * hinv; #else hinv3 = hinv * hinv / boxSize_Z; #endif if(mode == 0) { startnode = All.MaxPart; /* root node */ } else { startnode = UpdateweightGet[target].NodeList[0]; startnode = Nodes[startnode].u.d.nextnode; /* open it */ } numngb = 0; while(startnode >= 0) { while(startnode >= 0) { numngb = cs_ngb_treefind_variable_phases(pos, h, target, &startnode, mode, nexport, nsend_local); if(numngb < 0) return -1; for(n = 0; n < numngb; n++) { j = Ngblist[n]; r2 = R2ngblist[n]; r = sqrt(r2); u = r * hinv; if(u < 0.5) { wk = hinv3 * (KERNEL_COEFF_1 + KERNEL_COEFF_2 * (u - 1) * u * u); } else { wk = hinv3 * KERNEL_COEFF_5 * (1.0 - u) * (1.0 - u) * (1.0 - u); } weighted_numngb += FLT(NORM_COEFF * wk / hinv3); /* 4.0/3 * PI = 4.188790204786 */ } } if(mode == 1) { listindex++; if(listindex < NODELISTLENGTH) { startnode = UpdateweightGet[target].NodeList[listindex]; if(startnode >= 0) startnode = Nodes[startnode].u.d.nextnode; /* open it */ } } } if(mode == 0) { PPP[target].n.dNumNgb = weighted_numngb; } else { UpdateweightResult[target].Ngb = weighted_numngb; } return 0; }
// Read in the config file for the whole application int ConfigAppLoad() { TCHAR szConfig[MAX_PATH]; TCHAR szLine[1024]; FILE* h; #ifdef _UNICODE setlocale(LC_ALL, ""); #endif CreateConfigName(szConfig); if ((h = _tfopen(szConfig, _T("rt"))) == NULL) { return 1; } // Go through each line of the config file while (_fgetts(szLine, sizeof(szLine), h)) { int nLen = _tcslen(szLine); // Get rid of the linefeed at the end if (szLine[nLen - 1] == 10) { szLine[nLen - 1] = 0; nLen--; } #define VAR(x) { TCHAR* szValue = LabelCheck(szLine,_T(#x)); \ if (szValue) x = _tcstol(szValue, NULL, 0); } #define VAR64(x) { TCHAR* szValue = LabelCheck(szLine,_T(#x)); \ if (szValue) x = (long long)_tcstod(szValue, NULL); } #define FLT(x) { TCHAR* szValue = LabelCheck(szLine,_T(#x)); \ if (szValue) x = _tcstod(szValue, NULL); } #define STR(x) { TCHAR* szValue = LabelCheck(szLine,_T(#x) _T(" ")); \ if (szValue) _tcscpy(x,szValue); } VAR(nIniVersion); // Emulation VAR(bBurnUseASMCPUEmulation); // Video VAR(nVidDepth); VAR(nVidRefresh); VAR(nVidRotationAdjust); // horizontal oriented VAR(nVidHorWidth); VAR(nVidHorHeight); VAR(bVidArcaderesHor); VAR(VidPreset[0].nWidth); VAR(VidPreset[0].nHeight); VAR(VidPreset[1].nWidth); VAR(VidPreset[1].nHeight); VAR(VidPreset[2].nWidth); VAR(VidPreset[2].nHeight); VAR(VidPreset[3].nWidth); VAR(VidPreset[3].nHeight); VAR(nScreenSizeHor); // vertical oriented VAR(nVidVerWidth); VAR(nVidVerHeight); VAR(bVidArcaderesVer); VAR(VidPresetVer[0].nWidth); VAR(VidPresetVer[0].nHeight); VAR(VidPresetVer[1].nWidth); VAR(VidPresetVer[1].nHeight); VAR(VidPresetVer[2].nWidth); VAR(VidPresetVer[2].nHeight); VAR(VidPresetVer[3].nWidth); VAR(VidPresetVer[3].nHeight); VAR(nScreenSizeVer); VAR(nWindowSize); VAR(nWindowPosX); VAR(nWindowPosY); VAR(bDoGamma); VAR(bVidUseHardwareGamma); VAR(bHardwareGammaOnly); FLT(nGamma); VAR(bVidFullStretch); VAR(bVidCorrectAspect); VAR(bVidAutoSwitchFull); VAR(bVidTripleBuffer); VAR(bVidVSync); VAR(bVidScanlines); VAR(nVidScanIntensity); VAR(bMonitorAutoCheck); VAR(nVidScrnAspectX); VAR(nVidScrnAspectY); VAR(bForce60Hz); VAR(bAlwaysDrawFrames); VAR(bVidUsePlaceholder); STR(szPlaceHolder); VAR(nVidSelect); VAR(nVidBlitterOpt[0]); VAR64(nVidBlitterOpt[1]); VAR(nVidBlitterOpt[2]); VAR(nVidBlitterOpt[3]); // DirectDraw blitter VAR(bVidScanHalf); // Direct3D blitter VAR(bVidBilinear); VAR(bVidScanDelay); VAR(bVidScanRotate); VAR(bVidScanBilinear); VAR(nVidFeedbackIntensity); VAR(nVidFeedbackOverSaturation); FLT(fVidScreenAngle); FLT(fVidScreenCurvature); VAR(bVidForce16bit); VAR(nVidTransferMethod); // DirectX Graphics blitter FLT(dVidCubicB); FLT(dVidCubicC); // Sound VAR(nAudSelect); VAR(nAudSegCount); VAR(nInterpolation); VAR(nFMInterpolation); VAR(nAudSampleRate[0]); VAR(nAudDSPModule[0]); VAR(nAudSampleRate[1]); VAR(nAudDSPModule[1]); // Other STR(szLocalisationTemplate); STR(szGamelistLocalisationTemplate); VAR(nVidSDisplayStatus); VAR(nMinChatFontSize); VAR(nMaxChatFontSize); VAR(bModelessMenu); VAR(nSplashTime); VAR(bDrvSaveAll); VAR(nAppThreadPriority); VAR(bAlwaysProcessKeyboardInput); VAR(bAutoPause); VAR(bSaveInputs); VAR(nLoadMenuShowX); VAR(nLoadMenuBoardTypeFilter); VAR(nLoadMenuGenreFilter); VAR(nLoadMenuFamilyFilter); STR(szAppRomPaths[0]); STR(szAppRomPaths[1]); STR(szAppRomPaths[2]); STR(szAppRomPaths[3]); STR(szAppRomPaths[4]); STR(szAppRomPaths[5]); STR(szAppRomPaths[6]); STR(szAppRomPaths[7]); STR(szAppPreviewsPath); STR(szAppTitlesPath); STR(szAppSelectPath); STR(szAppVersusPath); STR(szAppHowtoPath); STR(szAppScoresPath); STR(szAppBossesPath); STR(szAppGameoverPath); STR(szAppFlyersPath); STR(szAppMarqueesPath); STR(szAppControlsPath); STR(szAppCabinetsPath); STR(szAppPCBsPath); STR(szAppCheatsPath); STR(szAppHistoryPath); STR(szAppListsPath); STR(szAppDatListsPath); STR(szAppIpsPath); STR(szAppIconsPath); STR(szAppArchivesPath); STR(szAppHiscorePath); VAR(nMenuUITheme); VAR(bNoChangeNumLock); VAR(bSaveCRoms); VAR(EnableHiscores); VAR(nSelectedLanguage); VAR(bEnableIcons); VAR(nIconsSize); STR(szPrevGames[0]); STR(szPrevGames[1]); STR(szPrevGames[2]); STR(szPrevGames[3]); STR(szPrevGames[4]); STR(szPrevGames[5]); STR(szPrevGames[6]); STR(szPrevGames[7]); STR(szPrevGames[8]); STR(szPrevGames[9]); // Default Controls VAR(nPlayerDefaultControls[0]); STR(szPlayerDefaultIni[0]); VAR(nPlayerDefaultControls[1]); STR(szPlayerDefaultIni[1]); VAR(nPlayerDefaultControls[2]); STR(szPlayerDefaultIni[2]); VAR(nPlayerDefaultControls[3]); STR(szPlayerDefaultIni[3]); #undef STR #undef FLT #undef VAR #undef VAR64 } fclose(h); return 0; }
// Write out the config file for the whole application int ConfigAppSave() { TCHAR szConfig[MAX_PATH]; FILE *h; if (bCmdOptUsed) { return 1; } #ifdef _UNICODE setlocale(LC_ALL, ""); #endif CreateConfigName(szConfig); if ((h = _tfopen(szConfig, _T("wt"))) == NULL) { return 1; } // Write title _ftprintf(h, _T("// ") _T(APP_TITLE) _T(" v%s --- Main Config File\n\n"), szAppBurnVer); _ftprintf(h, _T("// Don't edit this file manually unless you know what you're doing\n")); _ftprintf(h, _T("// ") _T(APP_TITLE) _T(" will restore default settings when this file is deleted\n")); #define VAR(x) _ftprintf(h, _T(#x) _T(" %d\n"), x) #define VAR64(x) _ftprintf(h, _T(#x) _T(" %lf\n"), (float)x) #define FLT(x) _ftprintf(h, _T(#x) _T(" %lf\n"), x) #define STR(x) _ftprintf(h, _T(#x) _T(" %s\n"), x) _ftprintf(h, _T("\n// The application version this file was saved from\n")); // We can't use the macros for this! _ftprintf(h, _T("nIniVersion 0x%06X"), nBurnVer); _ftprintf(h, _T("\n\n\n")); _ftprintf(h, _T("// --- emulation --------------------------------------------------------------\n")); _ftprintf(h, _T("\n// If non-zero, use A68K for MC68000 emulation\n")); VAR(bBurnUseASMCPUEmulation); _ftprintf(h, _T("\n\n\n")); _ftprintf(h, _T("// --- Video ------------------------------------------------------------------\n")); // Horizontal oriented _ftprintf(h, _T("\n// (Horizontal Oriented) The display mode to use for fullscreen\n")); VAR(nVidHorWidth); VAR(nVidHorHeight); _ftprintf(h, _T("\n// (Horizontal Oriented) If non-zero, use the same fullscreen resolution as the original arcade game\n")); VAR(bVidArcaderesHor); _ftprintf(h, _T("\n// (Horizontal Oriented) The preset resolutions appearing in the menu\n")); VAR(VidPreset[0].nWidth); VAR(VidPreset[0].nHeight); VAR(VidPreset[1].nWidth); VAR(VidPreset[1].nHeight); VAR(VidPreset[2].nWidth); VAR(VidPreset[2].nHeight); VAR(VidPreset[3].nWidth); VAR(VidPreset[3].nHeight); _ftprintf(h, _T("\n// (Horizontal Oriented) Full-screen size (0 = use display mode variables)\n")); VAR(nScreenSizeHor); // Vertical oriented _ftprintf(h, _T("\n// (Vertical Oriented) The display mode to use for fullscreen\n")); VAR(nVidVerWidth); VAR(nVidVerHeight); _ftprintf(h, _T("\n// (Vertical Oriented) If non-zero, use the same fullscreen resolution as the original arcade game\n")); VAR(bVidArcaderesVer); _ftprintf(h, _T("\n// (Vertical Oriented) The preset resolutions appearing in the menu\n")); VAR(VidPresetVer[0].nWidth); VAR(VidPresetVer[0].nHeight); VAR(VidPresetVer[1].nWidth); VAR(VidPresetVer[1].nHeight); VAR(VidPresetVer[2].nWidth); VAR(VidPresetVer[2].nHeight); VAR(VidPresetVer[3].nWidth); VAR(VidPresetVer[3].nHeight); _ftprintf(h, _T("\n// (Vertical Oriented) Full-screen size (0 = use display mode variables)\n")); VAR(nScreenSizeVer); _ftprintf(h, _T("\n// Full-screen bit depth\n")); VAR(nVidDepth); _ftprintf(h, _T("\n// Specify the refresh rate, 0 = default (changing this will not work with many video cards)\n")); VAR(nVidRefresh); _ftprintf(h, _T("\n// If non-zero, do not rotate the graphics for vertical games\n")); VAR(nVidRotationAdjust); _ftprintf(h, _T("\n// Initial window size (0 = autosize)\n")); VAR(nWindowSize); _ftprintf(h, _T("\n// Window position\n")); VAR(nWindowPosX); VAR(nWindowPosY); _ftprintf(h, _T("\n// If non-zero, perform gamma correction\n")); VAR(bDoGamma); _ftprintf(h, _T("\n// If non-zero, use the video hardware to correct gamma\n")); VAR(bVidUseHardwareGamma); _ftprintf(h, _T("\n// If non-zero, don't fall back on software gamma correction\n")); VAR(bHardwareGammaOnly); _ftprintf(h, _T("\n// Gamma to correct with\n")); FLT(nGamma); _ftprintf(h, _T("\n// If non-zero, auto-switch to fullscreen after loading game\n")); VAR(bVidAutoSwitchFull); _ftprintf(h, _T("\n// If non-zero, allow stretching of the image to any size\n")); VAR(bVidFullStretch); _ftprintf(h, _T("\n// If non-zero, stretch the image to the largest size preserving aspect ratio\n")); VAR(bVidCorrectAspect); _ftprintf(h, _T("\n// If non-zero, try to use a triple buffer in fullscreen\n")); VAR(bVidTripleBuffer); _ftprintf(h, _T("\n// If non-zero, try to synchronise blits with the display\n")); VAR(bVidVSync); _ftprintf(h, _T("\n// Transfer method: 0 = blit from system memory / use driver/DirectX texture management;\n")); _ftprintf(h, _T("// 1 = copy to a video memory surface, then use bltfast();\n")); _ftprintf(h, _T("// -1 = autodetect for DirectDraw, equals 1 for Direct3D\n")); VAR(nVidTransferMethod); _ftprintf(h, _T("\n// If non-zero, draw scanlines to simulate a low-res monitor\n")); VAR(bVidScanlines); _ftprintf(h, _T("\n// Maximum scanline intensity\n")); VAR(nVidScanIntensity); _ftprintf(h, _T("\n// If non-zero, rotate scanlines and RGB effects for rotated games\n")); VAR(bVidScanRotate); _ftprintf(h, _T("\n// The selected blitter module\n")); VAR(nVidSelect); _ftprintf(h, _T("\n// Options for the blitter modules\n")); VAR(nVidBlitterOpt[0]); VAR64(nVidBlitterOpt[1]); VAR(nVidBlitterOpt[2]); VAR(nVidBlitterOpt[3]); _ftprintf(h, _T("\n// If non-zero, attempt to auto-detect the monitor aspect ratio\n")); VAR(bMonitorAutoCheck); _ftprintf(h, _T("\n// The aspect ratio of the monitor\n")); VAR(nVidScrnAspectX); VAR(nVidScrnAspectY); _ftprintf(h, _T("\n// If non-zero, force all games to use a 60Hz refresh rate\n")); VAR(bForce60Hz); _ftprintf(h, _T("\n// If non-zero, skip frames when needed to keep the emulation running at full speed\n")); VAR(bAlwaysDrawFrames); _ftprintf(h, _T("\n// If non-zero, use a placeholder image when no game is loaded\n")); VAR(bVidUsePlaceholder); _ftprintf(h, _T("\n// The filename of the placeholder image to use (empty filename = use built-in)\n")); STR(szPlaceHolder); _ftprintf(h, _T("\n")); _ftprintf(h, _T("// --- DirectDraw blitter module settings -------------------------------------\n")); _ftprintf(h, _T("\n// If non-zero, draw scanlines at 50%% intensity\n")); VAR(bVidScanHalf); _ftprintf(h, _T("\n")); _ftprintf(h, _T("// --- Direct3D 7 blitter module settings -------------------------------------\n")); _ftprintf(h, _T("\n// If non-zero, use bi-linear filtering to display the image\n")); VAR(bVidBilinear); _ftprintf(h, _T("\n// If non-zero, simulate slow phosphors (feedback)\n")); VAR(bVidScanDelay); _ftprintf(h, _T("\n// If non-zero, use bi-linear filtering for the scanlines\n")); VAR(bVidScanBilinear); _ftprintf(h, _T("\n// Feedback amount for slow phosphor simulation\n")); VAR(nVidFeedbackIntensity); _ftprintf(h, _T("\n// Oversaturation amount for slow phosphor simulation\n")); VAR(nVidFeedbackOverSaturation); _ftprintf(h, _T("\n// Angle at wich the emulated screen is tilted (in radians)\n")); FLT(fVidScreenAngle); _ftprintf(h, _T("\n// Angle of the sphere segment used for the 3D screen (in radians)\n")); FLT(fVidScreenCurvature); _ftprintf(h, _T("\n// If non-zero, force 16 bit emulation even in 32-bit screenmodes\n")); VAR(bVidForce16bit); _ftprintf(h, _T("\n")); _ftprintf(h, _T("// --- DirectX Graphics 9 blitter module settings -----------------------------\n")); _ftprintf(h, _T("\n// The filter parameters for the cubic filter\n")); FLT(dVidCubicB); FLT(dVidCubicC); _ftprintf(h, _T("\n\n\n")); _ftprintf(h, _T("// --- Sound ------------------------------------------------------------------\n")); _ftprintf(h, _T("\n// The selected audio plugin\n")); VAR(nAudSelect); _ftprintf(h, _T("\n// Number of frames in sound buffer (= sound lag)\n")); VAR(nAudSegCount); _ftprintf(h, _T("\n// The order of PCM/ADPCM interpolation\n")); VAR(nInterpolation); _ftprintf(h, _T("\n// The order of FM interpolation\n")); VAR(nFMInterpolation); _ftprintf(h, _T("\n")); _ftprintf(h, _T("// --- DirectSound plugin settings --------------------------------------------\n")); _ftprintf(h, _T("\n// Sample rate\n")); VAR(nAudSampleRate[0]); _ftprintf(h, _T("\n// DSP module to use for sound enhancement: 0 = none, 1 = low-pass filter\n")); VAR(nAudDSPModule[0]); _ftprintf(h, _T("\n")); _ftprintf(h, _T("// --- XAudio2 plugin settings ------------------------------------------------\n")); _ftprintf(h, _T("\n// Sample rate\n")); VAR(nAudSampleRate[1]); _ftprintf(h, _T("\n// DSP module to use for sound enhancement: 0 = none, 1 = low-pass filter, 2 = reverb\n")); VAR(nAudDSPModule[1]); _ftprintf(h, _T("\n\n\n")); _ftprintf(h, _T("// --- UI ---------------------------------------------------------------------\n")); _ftprintf(h, _T("\n// Filename of the active UI translation template\n")); STR(szLocalisationTemplate); _ftprintf(h, _T("\n// Filename of the active game list translation template\n")); STR(szGamelistLocalisationTemplate); _ftprintf(h, _T("\n// 1 = display pause/record/replay/kaillera icons in the upper right corner of the display\n")); VAR(nVidSDisplayStatus); _ftprintf(h, _T("\n// Minimum height (in pixels) of the font used for the Kaillera chat function (used for arcade resolution)\n")); VAR(nMinChatFontSize); _ftprintf(h, _T("\n// Maximum height (in pixels) of the font used for the Kaillera chat function (used for 1280x960 or higher).\n")); VAR(nMaxChatFontSize); _ftprintf(h, _T("\n// Make the menu modeless\n")); VAR(bModelessMenu); _ftprintf(h, _T("\n// Minimum length of time to display the splash screen (in milliseconds)\n")); VAR(nSplashTime); _ftprintf(h, _T("\n// If non-zero, load and save all ram (the state)\n")); VAR(bDrvSaveAll); _ftprintf(h, _T("\n// The thread priority for the application. Do *NOT* edit this manually\n")); VAR(nAppThreadPriority); _ftprintf(h, _T("\n// If non-zero, process keyboard input even when the application loses focus\n")); VAR(bAlwaysProcessKeyboardInput); _ftprintf(h, _T("\n// If non-zero, pause when the application loses focus\n")); VAR(bAutoPause); _ftprintf(h, _T("\n// If non-zero, save the inputs for each game\n")); VAR(bSaveInputs); _ftprintf(h, _T("\n")); _ftprintf(h, _T("// --- Load Game Dialog -------------------------------------------------------\n")); _ftprintf(h, _T("\n// Load game dialog options\n")); VAR(nLoadMenuShowX); _ftprintf(h, _T("\n// Load game dialog board type filter options\n")); VAR(nLoadMenuBoardTypeFilter); _ftprintf(h, _T("\n// Load game dialog genre filter options\n")); VAR(nLoadMenuGenreFilter); _ftprintf(h, _T("\n// Load game dialog family filter options\n")); VAR(nLoadMenuFamilyFilter); _ftprintf(h, _T("\n// The paths to search for rom zips (include trailing backslash)\n")); STR(szAppRomPaths[0]); STR(szAppRomPaths[1]); STR(szAppRomPaths[2]); STR(szAppRomPaths[3]); STR(szAppRomPaths[4]); STR(szAppRomPaths[5]); STR(szAppRomPaths[6]); STR(szAppRomPaths[7]); _ftprintf(h, _T("\n// The paths to search for support files (include trailing backslash)\n")); STR(szAppPreviewsPath); STR(szAppTitlesPath); STR(szAppSelectPath); STR(szAppVersusPath); STR(szAppHowtoPath); STR(szAppScoresPath); STR(szAppBossesPath); STR(szAppGameoverPath); STR(szAppFlyersPath); STR(szAppMarqueesPath); STR(szAppControlsPath); STR(szAppCabinetsPath); STR(szAppPCBsPath); STR(szAppCheatsPath); STR(szAppHistoryPath); STR(szAppListsPath); STR(szAppDatListsPath); STR(szAppIpsPath); STR(szAppIconsPath); STR(szAppArchivesPath); STR(szAppHiscorePath); _ftprintf(h, _T("\n\n\n")); _ftprintf(h, _T("// --- miscellaneous ---------------------------------------------------------\n")); _ftprintf(h, _T("\n// If non-zero, use an image menu theme.\n")); VAR(nMenuUITheme); _ftprintf(h, _T("\n// If non-zero, don't change the status of the Num Lock key.\n")); VAR(bNoChangeNumLock); _ftprintf(h, _T("\n// If non-zero, write the decrypted Neo-Geo 'C' roms to disc.\n")); VAR(bSaveCRoms); _ftprintf(h, _T("\n// If non-zero, enable high score saving support.\n")); VAR(EnableHiscores); _ftprintf(h, _T("\n// The language index to use for the IPS Patch Manager dialog.\n")); VAR(nSelectedLanguage); _ftprintf(h, _T("\n// If non-zero, display drivers icons.\n")); VAR(bEnableIcons); _ftprintf(h, _T("\n// Specify icons display size, 0 = 16x16 , 1 = 24x24, 2 = 32x32.\n")); VAR(nIconsSize); _ftprintf(h, _T("\n// Previous games list.\n")); STR(szPrevGames[0]); STR(szPrevGames[1]); STR(szPrevGames[2]); STR(szPrevGames[3]); STR(szPrevGames[4]); STR(szPrevGames[5]); STR(szPrevGames[6]); STR(szPrevGames[7]); STR(szPrevGames[8]); STR(szPrevGames[9]); _ftprintf(h, _T("\n// Player default controls, number is the index of the configuration in the input dialog\n")); VAR(nPlayerDefaultControls[0]); STR(szPlayerDefaultIni[0]); VAR(nPlayerDefaultControls[1]); STR(szPlayerDefaultIni[1]); VAR(nPlayerDefaultControls[2]); STR(szPlayerDefaultIni[2]); VAR(nPlayerDefaultControls[3]); STR(szPlayerDefaultIni[3]); _ftprintf(h, _T("\n\n\n")); #undef STR #undef FLT #undef VAR fclose(h); return 0; }
/*! This function computes the gravitational potential for ALL the particles. * First, the (short-range) tree potential is computed, and then, if needed, * the long range PM potential is added. */ void compute_potential(void) { int i; #ifndef NOGRAVITY int j, k, ret, sendTask, recvTask; int ndone, ndone_flag, dummy; int ngrp, place, nexport, nimport; double fac; MPI_Status status; double r2; if(All.ComovingIntegrationOn) set_softenings(); if(ThisTask == 0) { printf("Start computation of potential for all particles...\n"); fflush(stdout); } CPU_Step[CPU_MISC] += measure_time(); if(TreeReconstructFlag) { if(ThisTask == 0) printf("Tree construction.\n"); CPU_Step[CPU_MISC] += measure_time(); #if defined(SFR) || defined(BLACK_HOLES) rearrange_particle_sequence(); #endif force_treebuild(NumPart, NULL); CPU_Step[CPU_TREEBUILD] += measure_time(); TreeReconstructFlag = 0; if(ThisTask == 0) printf("Tree construction done.\n"); } /* allocate buffers to arrange communication */ All.BunchSize = (int) ((All.BufferSize * 1024 * 1024) / (sizeof(struct data_index) + sizeof(struct data_nodelist) + sizeof(struct gravdata_in) + sizeof(struct potdata_out) + sizemax(sizeof(struct gravdata_in), sizeof(struct potdata_out)))); DataIndexTable = (struct data_index *) mymalloc(All.BunchSize * sizeof(struct data_index)); DataNodeList = (struct data_nodelist *) mymalloc(All.BunchSize * sizeof(struct data_nodelist)); for(i = 0; i < NumPart; i++) if(P[i].Ti_current != All.Ti_Current) drift_particle(i, All.Ti_Current); i = 0; /* beginn with this index */ do { for(j = 0; j < NTask; j++) { Send_count[j] = 0; Exportflag[j] = -1; } /* do local particles and prepare export list */ for(nexport = 0; i < NumPart; i++) { #ifndef PMGRID ret = force_treeevaluate_potential(i, 0, &nexport, Send_count); #else ret = force_treeevaluate_potential_shortrange(i, 0, &nexport, Send_count); #endif if(ret < 0) break; /* export buffer has filled up */ } #ifdef MYSORT mysort_dataindex(DataIndexTable, nexport, sizeof(struct data_index), data_index_compare); #else qsort(DataIndexTable, nexport, sizeof(struct data_index), data_index_compare); #endif MPI_Allgather(Send_count, NTask, MPI_INT, Sendcount_matrix, NTask, MPI_INT, MPI_COMM_WORLD); for(j = 0, nimport = 0, Recv_offset[0] = 0, Send_offset[0] = 0; j < NTask; j++) { Recv_count[j] = Sendcount_matrix[j * NTask + ThisTask]; nimport += Recv_count[j]; if(j > 0) { Send_offset[j] = Send_offset[j - 1] + Send_count[j - 1]; Recv_offset[j] = Recv_offset[j - 1] + Recv_count[j - 1]; } } GravDataGet = (struct gravdata_in *) mymalloc(nimport * sizeof(struct gravdata_in)); GravDataIn = (struct gravdata_in *) mymalloc(nexport * sizeof(struct gravdata_in)); /* prepare particle data for export */ for(j = 0; j < nexport; j++) { place = DataIndexTable[j].Index; for(k = 0; k < 3; k++) GravDataIn[j].Pos[k] = P[place].Pos[k]; #ifdef UNEQUALSOFTENINGS GravDataIn[j].Type = P[place].Type; #ifdef ADAPTIVE_GRAVSOFT_FORGAS if(P[place].Type == 0) GravDataIn[j].Soft = SphP[place].Hsml; #endif #endif GravDataIn[j].OldAcc = P[place].OldAcc; for(k = 0; k < NODELISTLENGTH; k++) GravDataIn[j].NodeList[k] = DataNodeList[DataIndexTable[j].IndexGet].NodeList[k]; } /* exchange particle data */ for(ngrp = 1; ngrp < (1 << PTask); ngrp++) { sendTask = ThisTask; recvTask = ThisTask ^ ngrp; if(recvTask < NTask) { if(Send_count[recvTask] > 0 || Recv_count[recvTask] > 0) { /* get the particles */ MPI_Sendrecv(&GravDataIn[Send_offset[recvTask]], Send_count[recvTask] * sizeof(struct gravdata_in), MPI_BYTE, recvTask, TAG_POTENTIAL_A, &GravDataGet[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(struct gravdata_in), MPI_BYTE, recvTask, TAG_POTENTIAL_A, MPI_COMM_WORLD, &status); } } } myfree(GravDataIn); PotDataResult = (struct potdata_out *) mymalloc(nimport * sizeof(struct potdata_out)); PotDataOut = (struct potdata_out *) mymalloc(nexport * sizeof(struct potdata_out)); /* now do the particles that were sent to us */ for(j = 0; j < nimport; j++) { #ifndef PMGRID force_treeevaluate_potential(j, 1, &dummy, &dummy); #else force_treeevaluate_potential_shortrange(j, 1, &dummy, &dummy); #endif } if(i >= NumPart) ndone_flag = 1; else ndone_flag = 0; MPI_Allreduce(&ndone_flag, &ndone, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); /* get the result */ for(ngrp = 1; ngrp < (1 << PTask); ngrp++) { sendTask = ThisTask; recvTask = ThisTask ^ ngrp; if(recvTask < NTask) { if(Send_count[recvTask] > 0 || Recv_count[recvTask] > 0) { /* send the results */ MPI_Sendrecv(&PotDataResult[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(struct potdata_out), MPI_BYTE, recvTask, TAG_POTENTIAL_B, &PotDataOut[Send_offset[recvTask]], Send_count[recvTask] * sizeof(struct potdata_out), MPI_BYTE, recvTask, TAG_POTENTIAL_B, MPI_COMM_WORLD, &status); } } } /* add the results to the local particles */ for(j = 0; j < nexport; j++) { place = DataIndexTable[j].Index; P[place].p.dPotential += PotDataOut[j].Potential; } myfree(PotDataOut); myfree(PotDataResult); myfree(GravDataGet); } while(ndone < NTask); myfree(DataNodeList); myfree(DataIndexTable); /* add correction to exclude self-potential */ for(i = 0; i < NumPart; i++) { #ifdef FLTROUNDOFFREDUCTION P[i].p.Potential = FLT(P[i].p.dPotential); #endif /* remove self-potential */ P[i].p.Potential += P[i].Mass / All.SofteningTable[P[i].Type]; if(All.ComovingIntegrationOn) if(All.PeriodicBoundariesOn) P[i].p.Potential -= 2.8372975 * pow(P[i].Mass, 2.0 / 3) * pow(All.Omega0 * 3 * All.Hubble * All.Hubble / (8 * M_PI * All.G), 1.0 / 3); } /* multiply with the gravitational constant */ for(i = 0; i < NumPart; i++) P[i].p.Potential *= All.G; #ifdef PMGRID #ifdef PERIODIC pmpotential_periodic(); #ifdef PLACEHIGHRESREGION i = pmpotential_nonperiodic(1); if(i == 1) /* this is returned if a particle lied outside allowed range */ { pm_init_regionsize(); pm_setup_nonperiodic_kernel(); i = pmpotential_nonperiodic(1); /* try again */ } if(i == 1) endrun(88686); #endif #else i = pmpotential_nonperiodic(0); if(i == 1) /* this is returned if a particle lied outside allowed range */ { pm_init_regionsize(); pm_setup_nonperiodic_kernel(); i = pmpotential_nonperiodic(0); /* try again */ } if(i == 1) endrun(88687); #ifdef PLACEHIGHRESREGION i = pmpotential_nonperiodic(1); if(i == 1) /* this is returned if a particle lied outside allowed range */ { pm_init_regionsize(); i = pmpotential_nonperiodic(1); } if(i != 0) endrun(88688); #endif #endif #endif if(All.ComovingIntegrationOn) { #ifndef PERIODIC fac = -0.5 * All.Omega0 * All.Hubble * All.Hubble; for(i = 0; i < NumPart; i++) { for(k = 0, r2 = 0; k < 3; k++) r2 += P[i].Pos[k] * P[i].Pos[k]; P[i].p.Potential += fac * r2; } #endif } else { fac = -0.5 * All.OmegaLambda * All.Hubble * All.Hubble; if(fac != 0) { for(i = 0; i < NumPart; i++) { for(k = 0, r2 = 0; k < 3; k++) r2 += P[i].Pos[k] * P[i].Pos[k]; P[i].p.Potential += fac * r2; } } } if(ThisTask == 0) { printf("potential done.\n"); fflush(stdout); } #else for(i = 0; i < NumPart; i++) P[i].Potential = 0; #endif CPU_Step[CPU_POTENTIAL] += measure_time(); }
static void sobel (TileDrawable *drawable, gint do_horizontal, gint do_vertical, gint keep_sign) { GPixelRgn srcPR, destPR; gint width, height; gint num_channels; guchar *dest; guchar *prev_row; guchar *cur_row; guchar *next_row; guchar *pr; guchar *cr; guchar *nr; guchar *tmp; gint row, col; gint x1, y1, x2, y2; gint alpha; gint counter; GPrecisionType precision = gimp_drawable_precision (drawable->id); /* Get the input area. This is the bounding box of the selection in * the image (or the entire image if there is no selection). Only * operating on the input area is simply an optimization. It doesn't * need to be done for correct operation. (It simply makes it go * faster, since fewer pixels need to be operated on). */ gimp_drawable_mask_bounds (drawable->id, &x1, &y1, &x2, &y2); gimp_progress_init (_("Sobel Edge Detect")); /* Get the size of the input image. (This will/must be the same * as the size of the output image. */ width = drawable->width; height = drawable->height; num_channels = drawable->num_channels; alpha = gimp_drawable_has_alpha (drawable -> id); /* allocate generic data row buffers */ prev_row = (guchar *) malloc ((x2 - x1 + 2) * drawable->bpp); cur_row = (guchar *) malloc ((x2 - x1 + 2) * drawable->bpp); next_row = (guchar *) malloc ((x2 - x1 + 2) * drawable->bpp); dest = (guchar *) malloc ((x2 - x1) * drawable->bpp); /* initialize the pixel regions */ gimp_pixel_rgn_init (&srcPR, drawable, 0, 0, width, height, FALSE, FALSE); gimp_pixel_rgn_init (&destPR, drawable, 0, 0, width, height, TRUE, TRUE); /* generic data pointers to the three rows */ pr = prev_row + drawable->bpp; cr = cur_row + drawable->bpp; nr = next_row + drawable->bpp; sobel_prepare_row (&srcPR, pr, x1, y1 - 1, (x2 - x1)); sobel_prepare_row (&srcPR, cr, x1, y1, (x2 - x1)); counter = 0; /* loop through the rows, applying the sobel convolution */ for (row = y1; row < y2; row++) { /* prepare the next row */ sobel_prepare_row (&srcPR, nr, x1, row + 1, (x2 - x1)); switch(precision) { case PRECISION_U8: { guint8* d = (guint8*)dest; guint8* p = (guint8*)pr; guint8* c = (guint8*)cr; guint8* n = (guint8*)nr; gint gradient, hor_gradient, ver_gradient; for (col = 0; col < (x2 - x1) * num_channels; col++) { if (do_horizontal) hor_gradient = (p[col - num_channels] + 2 * p[col] + p[col + num_channels]) - (n[col - num_channels] + 2 * n[col] + n[col + num_channels]); else hor_gradient = 0; if (do_vertical) ver_gradient = (p[col - num_channels] + 2 * c[col - num_channels] + n[col - num_channels]) - (p[col + num_channels] + 2 * c[col + num_channels] + n[col + num_channels]); else ver_gradient = 0; if (do_vertical && do_horizontal) gradient = ROUND_TO_INT (RMS (hor_gradient, ver_gradient)) / 5.66; else { if (keep_sign) gradient = 127 + (ROUND_TO_INT ((hor_gradient + ver_gradient) / 8.0)); else gradient = ROUND_TO_INT (abs (hor_gradient + ver_gradient) / 4.0); } if (alpha && (((col + 1) % num_channels) == 0)) { *d++ = (counter == 0) ? 0 : 255; counter = 0; } else { *d++ = gradient; if (gradient > 10) counter ++; } } } break; case PRECISION_U16: { guint16* d = (guint16*)dest; guint16* p = (guint16*)pr; guint16* c = (guint16*)cr; guint16* n = (guint16*)nr; gint gradient, hor_gradient, ver_gradient; for (col = 0; col < (x2 - x1) * num_channels; col++) { if (do_horizontal) hor_gradient = (p[col - num_channels] + 2 * p[col] + p[col + num_channels]) - (n[col - num_channels] + 2 * n[col] + n[col + num_channels]); else hor_gradient = 0; if (do_vertical) ver_gradient = (p[col - num_channels] + 2 * c[col - num_channels] + n[col - num_channels]) - (p[col + num_channels] + 2 * c[col + num_channels] + n[col + num_channels]); else ver_gradient = 0; if (do_vertical && do_horizontal) gradient = ROUND_TO_INT (RMS (hor_gradient, ver_gradient)) / 5.66; else { if (keep_sign) gradient = 32767 + (ROUND_TO_INT ((hor_gradient + ver_gradient) / 8.0)); else gradient = ROUND_TO_INT (abs (hor_gradient + ver_gradient) / 4.0); } if (alpha && (((col + 1) % num_channels) == 0)) { *d++ = (counter == 0) ? 0 : 65535; counter = 0; } else { *d++ = gradient; if (gradient > (10/255.0) * 65535) counter ++; } } } break; case PRECISION_FLOAT: { gfloat* d = (gfloat*)dest; gfloat* p = (gfloat*)pr; gfloat* c = (gfloat*)cr; gfloat* n = (gfloat*)nr; gfloat gradient, hor_gradient, ver_gradient; for (col = 0; col < (x2 - x1) * num_channels; col++) { if (do_horizontal) hor_gradient = (p[col - num_channels] + 2 * p[col] + p[col + num_channels]) - (n[col - num_channels] + 2 * n[col] + n[col + num_channels]); else hor_gradient = 0; if (do_vertical) ver_gradient = (p[col - num_channels] + 2 * c[col - num_channels] + n[col - num_channels]) - (p[col + num_channels] + 2 * c[col + num_channels] + n[col + num_channels]); else ver_gradient = 0; if (do_vertical && do_horizontal) gradient = (RMS (hor_gradient, ver_gradient)) / 5.66; else { if (keep_sign) gradient = .5 + (hor_gradient + ver_gradient) / 8.0; else gradient = abs (hor_gradient + ver_gradient) / 4.0; } if (alpha && (((col + 1) % num_channels) == 0)) { *d++ = (counter == 0) ? 0.0 : 1.0; counter = 0; } else { *d++ = gradient; if (gradient > (10/255.0)) counter ++; } } } break; case PRECISION_FLOAT16: { guint16* d = (guint16*)dest; guint16* p = (guint16*)pr; guint16* c = (guint16*)cr; guint16* n = (guint16*)nr; gfloat gradient, hor_gradient, ver_gradient; ShortsFloat u,v,s, u1, v1, s1; for (col = 0; col < (x2 - x1) * num_channels; col++) { if (do_horizontal) hor_gradient = ( FLT(p[col - num_channels],u) + 2 * FLT(p[col], v) + FLT(p[col + num_channels], s) ) - ( FLT(n[col - num_channels],u1) + 2 * FLT(n[col], v1) + FLT(n[col + num_channels], s1) ); else hor_gradient = 0; if (do_vertical) ver_gradient = ( FLT(p[col - num_channels], u) + 2 * FLT (c[col - num_channels],v) + FLT(n[col - num_channels],s) ) - ( FLT(p[col + num_channels], u1) + 2 * FLT (c[col + num_channels],v1) + FLT(n[col + num_channels], s1) ); else ver_gradient = 0; if (do_vertical && do_horizontal) gradient = (RMS (hor_gradient, ver_gradient)) / 5.66; else { if (keep_sign) gradient = .5 + (hor_gradient + ver_gradient) / 8.0; else gradient = abs (hor_gradient + ver_gradient) / 4.0; } if (alpha && (((col + 1) % num_channels) == 0)) { *d++ = (counter == 0) ? 0.0 : 1.0; counter = 0; } else { *d++ = FLT16(gradient, u); if (gradient > (10/255.0)) counter ++; } } } break; } /* store the dest */ gimp_pixel_rgn_set_row (&destPR, dest, x1, row, (x2 - x1)); /* shuffle the row pointers */ tmp = pr; pr = cr; cr = nr; nr = tmp; if ((row % 5) == 0) gimp_progress_update ((double) row / (double) (y2 - y1)); } /* update the sobeled region */ gimp_drawable_flush (drawable); gimp_drawable_merge_shadow (drawable->id, TRUE); gimp_drawable_update (drawable->id, x1, y1, (x2 - x1), (y2 - y1)); free (prev_row); free (cur_row); free (next_row); free (dest); }
/* * dooper() will execute a constant operation in a node and return * the node to be the result of the operation. */ static EXPR *dooper P1 (EXPR *, ep) { EXPRTYPE type = ep->nodetype; ep->nodetype = ep->v.p[0]->nodetype; switch (ep->v.p[0]->nodetype) { #ifdef FLOAT_SUPPORT #ifndef FLOAT_BOOTSTRAP RVAL f; #endif /* FLOAT_BOOTSTRAP */ case en_fcon: #ifndef FLOAT_BOOTSTRAP FASSIGN (f, ep->v.p[0]->v.f); switch (type) { case en_uminus: FASSIGN (ep->v.f, f); FNEG (ep->v.f); break; case en_test: ep->v.i = FTST (f) ? (IVAL) 1 : (IVAL) 0; ep->nodetype = en_icon; break; case en_not: ep->v.i = FTST (f) ? (IVAL) 0 : (IVAL) 1; ep->nodetype = en_icon; break; case en_cast: if (is_real_floating_type (ep->etp)) { ep->v.f = f; } else if (is_bool (ep->etp)) { ep->v.u = (UVAL) (f ? 1 : 0); ep->nodetype = en_icon; } else { FTOL (ep->v.i, f); ep->v.i = strip_icon (ep->v.i, ep->etp); ep->nodetype = en_icon; } break; case en_add: FADD3 (ep->v.f, f, ep->v.p[1]->v.f); break; case en_sub: FSUB3 (ep->v.f, f, ep->v.p[1]->v.f); break; case en_mul: FMUL3 (ep->v.f, f, ep->v.p[1]->v.f); break; case en_div: if (FTST (ep->v.p[1]->v.f)) { FDIV3 (ep->v.f, f, ep->v.p[1]->v.f); } else { ep->nodetype = en_div; } break; case en_eq: ep->v.i = (IVAL) FEQ (f, ep->v.p[1]->v.f); ep->nodetype = en_icon; break; case en_ne: ep->v.i = (IVAL) FNE (f, ep->v.p[1]->v.f); ep->nodetype = en_icon; break; case en_land: ep->v.i = (IVAL) (FTST (f) && FTST (ep->v.p[1]->v.f)); ep->nodetype = en_icon; break; case en_lor: ep->v.i = (IVAL) (FTST (f) || FTST (ep->v.p[1]->v.f)); ep->nodetype = en_icon; break; case en_lt: ep->v.i = (IVAL) FLT (f, ep->v.p[1]->v.f); ep->nodetype = en_icon; break; case en_le: ep->v.i = (IVAL) FLE (f, ep->v.p[1]->v.f); ep->nodetype = en_icon; break; case en_gt: ep->v.i = (IVAL) FGT (f, ep->v.p[1]->v.f); ep->nodetype = en_icon; break; case en_ge: ep->v.i = (IVAL) FGE (f, ep->v.p[1]->v.f); ep->nodetype = en_icon; break; default: CANNOT_REACH_HERE (); break; } break; #endif /* FLOAT_BOOTSTRAP */ #endif /* FLOAT_SUPPORT */ case en_icon: if (is_unsigned_type (ep->v.p[0]->etp)) { UVAL u = ep->v.p[0]->v.u; switch (type) { case en_uminus: /* * unary minus on an unsigned is normally a mistake so we must * fool the compiler into not giving a warning. */ ep->v.u = (UVAL) (-(IVAL) u); break; case en_test: ep->v.u = (u ? (UVAL) 1 : (UVAL) 0); break; case en_not: ep->v.u = (u ? (UVAL) 0 : (UVAL) 1); break; case en_compl: ep->v.u = (UVAL) strip_icon ((IVAL) ~u, ep->etp); break; case en_cast: if (is_bool (ep->etp)) { ep->v.u = (UVAL) (u ? 1 : 0); #ifdef FLOAT_SUPPORT } else if (is_real_floating_type (ep->etp)) { ep->nodetype = en_fcon; UTOF (ep->v.f, u); break; #endif /* FLOAT_SUPPORT */ } else { ep->v.u = (UVAL) strip_icon ((IVAL) u, ep->etp); } break; case en_add: ep->v.u = u + ep->v.p[1]->v.u; break; case en_sub: ep->v.u = u - ep->v.p[1]->v.u; break; case en_mul: ep->v.u = u * ep->v.p[1]->v.u; break; case en_div: if (ep->v.p[1]->v.u == (UVAL) 0) { ep->nodetype = en_div; } else { ep->v.u = u / ep->v.p[1]->v.u; } break; case en_mod: if (ep->v.p[1]->v.u == (UVAL) 0) { ep->nodetype = en_mod; } else { ep->v.u = u % ep->v.p[1]->v.u; } break; case en_and: ep->v.u = u & ep->v.p[1]->v.u; break; case en_or: ep->v.u = u | ep->v.p[1]->v.u; break; case en_xor: ep->v.u = u ^ ep->v.p[1]->v.u; break; case en_eq: ep->v.u = (UVAL) (u == ep->v.p[1]->v.u); break; case en_ne: ep->v.u = (UVAL) (u != ep->v.p[1]->v.u); break; case en_land: ep->v.u = (UVAL) (u && ep->v.p[1]->v.u); break; case en_lor: ep->v.u = (UVAL) (u || ep->v.p[1]->v.u); break; case en_lt: ep->v.u = (UVAL) (u < ep->v.p[1]->v.u); break; case en_le: ep->v.u = (UVAL) (u <= ep->v.p[1]->v.u); break; case en_gt: ep->v.u = (UVAL) (u > ep->v.p[1]->v.u); break; case en_ge: ep->v.u = (UVAL) (u >= ep->v.p[1]->v.u); break; case en_lsh: ep->v.u = u << ep->v.p[1]->v.u; break; case en_rsh: ep->v.u = u >> ep->v.p[1]->v.u; break; default: CANNOT_REACH_HERE (); break; } } else {
/* PUBLIC */ Fpa_chunk flist_insert(Fpa_chunk f, Term x) { if (f == NULL) { f = get_fpa_chunk(); FLAST(f) = x; f->n = 1; } else if (f->n == FMAX) { if (FLT(x,FLAST(f))) f->next = flist_insert(f->next, x); else if (x == FLAST(f)) fprintf(stderr, "WARNING: flist_insert, item %p already here (1)!\n", x); else if (FGT(x,FFIRST(f))) { /* This special case isn't necessary. It is to improve performance. The application for which I'm writing this inserts items in increasing order (most of the time), and this prevents a lot of half-empty chunks in that case. */ Fpa_chunk f2 = flist_insert(NULL, x); f2->next = f; f = f2; } else { /* split this chunk in half */ Fpa_chunk f2 = get_fpa_chunk(); int move = FMAX / 2; int i, j; for (i = 0, j = FMAX-move; i < move; i++, j++) { f2->d[j] = f->d[i]; f->d[i] = NULL; } f2->n = move; f->n = FMAX - move; f2->next = f; f = flist_insert(f2, x); } } else { if (f->next && FLE(x,FFIRST(f->next))) f->next = flist_insert(f->next, x); else { /* insert into this pa_chunk */ int n = f->n; int i = FMAX - n; while (i < FMAX && FLT(x,f->d[i])) i++; if (i < FMAX && x == f->d[i]) fprintf(stderr, "WARNING: flist_insert, item %p already here (2)!\n", x); else if (i == FMAX - n) { f->d[i-1] = x; f->n = n+1; } else { /* insert at i-1, shifting the rest */ int j; for (j = FMAX-n; j < i; j++) f->d[j-1] = f->d[j]; f->d[i-1] = x; f->n = n+1; } } } return f; } /* flist_insert */
int main() { int i,j,n,pt; #ifdef TEST class quadtree<2> testtree,testtree2; TinyVector<FLT,2> x1(0.0,0.0),x2(1.0,1.0),x3(1.1,1.1); FLT vtest[17][2] = {{0.1,0.1},{0.2,0.4},{.9,0.2},{.125,0.7},{0.51,0.53},{0.85,0.15},{0.25,0.85},{0.99,0.99},{0.001,.3},{0.01,0.3},{0.2,0.1}, {2.0,2.0},{0.9,0.9},{0.9,0.9},{0.9,0.9},{0.9,0.9},{0.9,0.9}}; blitz::Array<blitz::TinyVector<FLT,2>,1> vtest2(17); FLT dist; for(i=0;i<17;++i) { vtest2(i)(0) = vtest[i][0]; vtest2(i)(1) = vtest[i][1]; } testtree.init(vtest2, 2000, x1, x2); printf("%f %f %f %f\n",testtree.xmin(0),testtree.xmax(0),testtree.xmin(1),testtree.xmax(1)); for(i=0;i<11;++i) { printf("%d\n",i); testtree.addpt(i); } // /* Test what happens for point outside domain */ // printf("point outside test\n"); // testtree.addpt(11); // // /* Test what happens for same point 5 times */ // printf("5 times test\n"); // for(i=12;i<17;++i) // testtree.addpt(i); quadtree<2> copytree(testtree); dist = testtree.nearpt(9, i); printf("%d %f\n",i,dist); dist = copytree.nearpt(9, i); printf("%d %f\n",i,dist); vtest2(0)[0] = 0.9; vtest2(0)[1] = 0.9; testtree.update(0,10); printf("update ok\n"); testtree.reinit(); dist = testtree.nearpt(vtest2(0), i); printf("%d %f\n",i,dist); dist = testtree.nearpt(0, i); printf("%d %f\n",i,dist); dist = testtree.nearpt(x3.data(), i); printf("%d %f\n",i,dist); testtree.output("out"); testtree.output("out",quadtree<2>::text); /* What happens if I insert point twice? */ testtree.addpt(0); // class quadtree<3> octtree; // FLT y1[3] = {0.0,0.0,0.0},y2[3] ={1.0,1.0,1.0}; // FLT wtest[9][3] = {{0.1,0.1,0.1},{0.1,0.1,0.9},{0.1,0.9,0.1},{0.1,0.9,0.9},{0.9,0.1,0.1},{0.9,0.1,0.9},{0.9,0.9,0.1},{0.9,0.9,0.9}, {0.9,0.85,0.9}}; // octtree.init(wtest, 20, y1, y2); // for(i=0;i<9;++i) { // printf("%d\n",i); // octtree.addpt(i); // } // // quadtree<3> copytree3(octtree); // // dist = octtree.nearpt(8, i); // printf("%d %f\n",i,dist); // dist = copytree3.nearpt(8, i); // printf("%d %f\n",i,dist); // // // wtest[0][0] = 0.9; // wtest[0][1] = 0.9; // wtest[0][2] = 0.87; // octtree.update(0,9); // // printf("update ok\n"); // // octtree.reinit(); // // dist = octtree.nearpt(0, i); // printf("%d %f\n",i,dist); // // octtree.output("out3"); // octtree.output("out3",quadtree<3>::text); // // /* What happens if I insert 4 points outside of domain? */ // quadtree<2> bigtree; // bigtree.init(vtest,100000, x1, x2); // for(i=0;i<16;++i) { // printf("%d\n",i); // bigtree.addpt(i); // } // bigtree.output("huh",quadtree<2>::text); #endif #ifdef FINDUNIQUE int nvrts = 556732; class quadtree<3> dups; FLT (*vrts)[3]; FLT xmax[3],xmin[3]; FLT dist1; int tvrtx[3]; int *ipoint; ipoint = new int[nvrts]; if (ipoint == 0) printf("shit\n"); vrts = (FLT (*)[3]) malloc(nvrts*3*sizeof(double)); if (vrts == NULL) printf("shit\n"); dups.allocate(vrts,nvrts); scanf("%lf %lf %lf\n",&vrts[0][0],&vrts[0][1],&vrts[0][2]); for(n=0;n<3;++n) { xmax[n] = vrts[0][n]; xmin[n] = vrts[0][n]; } for(i=1;i<nvrts;++i) { scanf("%lf %lf %lf",&vrts[i][0],&vrts[i][1],&vrts[i][2]); for(n=0;n<3;++n) { xmax[n] = MAX(vrts[i][n],xmax[n]); xmin[n] = MIN(vrts[i][n],xmin[n]); } } for(i=0;i<nvrts;++i) for(n=0;n<3;++n) vrts[i][n] -= xmax[n]; for(n=0;n<3;++n) { xmin[n] -= xmax[n]; xmax[n] = 0.0; } dups.init(vrts,nvrts,xmin,xmax); dups.addpt(0); printf("%17.10e %17.10e %17.10e\n",vrts[0][0],vrts[0][1],vrts[0][2]); ipoint[0] = 0; int count = 1; for(i=0;i<nvrts;i+=4) { for(j=0;j<3;++j) { dist1 = dups.nearpt(vrts[i+j], pt); if (fabs((vrts[i+j][0]-vrts[pt][0])/xmin[0]) > 1.0e-4 || fabs((vrts[i+j][1]-vrts[pt][1])/xmin[1]) > 1.0e-4 || fabs((vrts[i+j][2]-vrts[pt][2])/xmin[2]) > 1.0e-4) { printf("%17.10e %17.10e %17.10e\n",vrts[i+j][0],vrts[i+j][1],vrts[i+j][2]); dups.addpt(i+j); ipoint[i+j] = count; pt = count++; } else { pt = ipoint[pt]; } tvrtx[j] = pt; } printf("# %d %d %d\n",tvrtx[0]+1,tvrtx[1]+1,tvrtx[2]+1); } #endif return(0); }
/* This function updates the weights for SN before exploding. This is * necessary due to the fact that gas particles neighbours of a given star * could have been transformed into stars and they need to be taken off the * neighbour list for the exploding star. */ void cs_update_weights(void) { MyFloat *Left, *Right; int i, j, ndone, ndone_flag, npleft, dummy, iter = 0; int ngrp, sendTask, recvTask, place, nexport, nimport; long long ntot; double dmax1, dmax2; double desnumngb; if(ThisTask == 0) { printf("... start update weights phase = %d ...\n", Flag_phase); fflush(stdout); } Left = (MyFloat *) mymalloc(NumPart * sizeof(MyFloat)); Right = (MyFloat *) mymalloc(NumPart * sizeof(MyFloat)); for(i = FirstActiveParticle; i >= 0; i = NextActiveParticle[i]) { if(P[i].Type == 6 || P[i].Type == 7) { Left[i] = Right[i] = 0; } } /* allocate buffers to arrange communication */ Ngblist = (int *) mymalloc(NumPart * sizeof(int)); R2ngblist = (double *) mymalloc(NumPart * sizeof(double)); All.BunchSize = (int) ((All.BufferSize * 1024 * 1024) / (sizeof(struct data_index) + sizeof(struct data_nodelist) + sizeof(struct updateweight_in) + sizeof(struct updateweight_out) + sizemax(sizeof(struct updateweight_in), sizeof(struct updateweight_out)))); DataIndexTable = (struct data_index *) mymalloc(All.BunchSize * sizeof(struct data_index)); DataNodeList = (struct data_nodelist *) mymalloc(All.BunchSize * sizeof(struct data_nodelist)); desnumngb = All.DesNumNgb; /* we will repeat the whole thing for those particles where we didn't find enough neighbours */ do { i = FirstActiveParticle; /* begin with this index */ do { for(j = 0; j < NTask; j++) { Send_count[j] = 0; Exportflag[j] = -1; } /* do local particles and prepare export list */ for(nexport = 0; i >= 0; i = NextActiveParticle[i]) { if((P[i].Type == 6 || P[i].Type == 7) && P[i].TimeBin >= 0) { if(cs_update_weight_evaluate(i, 0, &nexport, Send_count) < 0) break; } } #ifdef MYSORT mysort_dataindex(DataIndexTable, nexport, sizeof(struct data_index), data_index_compare); #else qsort(DataIndexTable, nexport, sizeof(struct data_index), data_index_compare); #endif MPI_Allgather(Send_count, NTask, MPI_INT, Sendcount_matrix, NTask, MPI_INT, MPI_COMM_WORLD); for(j = 0, nimport = 0, Recv_offset[0] = 0, Send_offset[0] = 0; j < NTask; j++) { Recv_count[j] = Sendcount_matrix[j * NTask + ThisTask]; nimport += Recv_count[j]; if(j > 0) { Send_offset[j] = Send_offset[j - 1] + Send_count[j - 1]; Recv_offset[j] = Recv_offset[j - 1] + Recv_count[j - 1]; } } UpdateweightGet = (struct updateweight_in *) mymalloc(nimport * sizeof(struct updateweight_in)); UpdateweightIn = (struct updateweight_in *) mymalloc(nexport * sizeof(struct updateweight_in)); /* prepare particle data for export */ for(j = 0; j < nexport; j++) { place = DataIndexTable[j].Index; UpdateweightIn[j].Pos[0] = P[place].Pos[0]; UpdateweightIn[j].Pos[1] = P[place].Pos[1]; UpdateweightIn[j].Pos[2] = P[place].Pos[2]; UpdateweightIn[j].Hsml = PPP[place].Hsml; memcpy(UpdateweightIn[j].NodeList, DataNodeList[DataIndexTable[j].IndexGet].NodeList, NODELISTLENGTH * sizeof(int)); } /* exchange particle data */ for(ngrp = 1; ngrp < (1 << PTask); ngrp++) { sendTask = ThisTask; recvTask = ThisTask ^ ngrp; if(recvTask < NTask) { if(Send_count[recvTask] > 0 || Recv_count[recvTask] > 0) { /* get the particles */ MPI_Sendrecv(&UpdateweightIn[Send_offset[recvTask]], Send_count[recvTask] * sizeof(struct updateweight_in), MPI_BYTE, recvTask, TAG_DENS_A, &UpdateweightGet[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(struct updateweight_in), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } } } myfree(UpdateweightIn); UpdateweightResult = (struct updateweight_out *) mymalloc(nimport * sizeof(struct updateweight_out)); UpdateweightOut = (struct updateweight_out *) mymalloc(nexport * sizeof(struct updateweight_out)); /* now do the particles that were sent to us */ for(j = 0; j < nimport; j++) cs_update_weight_evaluate(j, 1, &dummy, &dummy); if(i < 0) ndone_flag = 1; else ndone_flag = 0; MPI_Allreduce(&ndone_flag, &ndone, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); /* get the result */ for(ngrp = 1; ngrp < (1 << PTask); ngrp++) { sendTask = ThisTask; recvTask = ThisTask ^ ngrp; if(recvTask < NTask) { if(Send_count[recvTask] > 0 || Recv_count[recvTask] > 0) { /* send the results */ MPI_Sendrecv(&UpdateweightResult[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(struct updateweight_out), MPI_BYTE, recvTask, TAG_DENS_B, &UpdateweightOut[Send_offset[recvTask]], Send_count[recvTask] * sizeof(struct updateweight_out), MPI_BYTE, recvTask, TAG_DENS_B, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } } } /* add the result to the local particles */ for(j = 0; j < nexport; j++) { place = DataIndexTable[j].Index; PPP[place].n.dNumNgb += UpdateweightOut[j].Ngb; } myfree(UpdateweightOut); myfree(UpdateweightResult); myfree(UpdateweightGet); } while(ndone < NTask); /* do final operations on results */ for(i = FirstActiveParticle, npleft = 0; i >= 0; i = NextActiveParticle[i]) { if(P[i].Type == 6 || P[i].Type == 7) { #ifdef FLTROUNDOFFREDUCTION PPP[i].n.NumNgb = FLT(PPP[i].n.dNumNgb); #endif /* now check whether we had enough neighbours */ if(PPP[i].n.NumNgb < (desnumngb - All.MaxNumNgbDeviation) || (PPP[i].n.NumNgb > (desnumngb + All.MaxNumNgbDeviation) && PPP[i].Hsml > (1.01 * All.MinGasHsml))) { /* need to redo this particle */ npleft++; if(Left[i] > 0 && Right[i] > 0) if((Right[i] - Left[i]) < 1.0e-3 * Left[i]) { /* this one should be ok */ npleft--; P[i].TimeBin = -P[i].TimeBin - 1; /* Mark as inactive */ continue; } if(PPP[i].n.NumNgb < (desnumngb - All.MaxNumNgbDeviation)) Left[i] = DMAX(PPP[i].Hsml, Left[i]); else { if(Right[i] != 0) { if(PPP[i].Hsml < Right[i]) Right[i] = PPP[i].Hsml; } else Right[i] = PPP[i].Hsml; } if(iter >= MAXITER - 10) { printf ("i=%d task=%d ID=%d Hsml=%g Left=%g Right=%g Ngbs=%g Right-Left=%g\n pos=(%g|%g|%g)\n", i, ThisTask, (int) P[i].ID, PPP[i].Hsml, Left[i], Right[i], (float) PPP[i].n.NumNgb, Right[i] - Left[i], P[i].Pos[0], P[i].Pos[1], P[i].Pos[2]); fflush(stdout); } if(Right[i] > 0 && Left[i] > 0) PPP[i].Hsml = pow(0.5 * (pow(Left[i], 3) + pow(Right[i], 3)), 1.0 / 3); else { if(Right[i] == 0 && Left[i] == 0) endrun(8188); /* can't occur */ if(Right[i] == 0 && Left[i] > 0) { PPP[i].Hsml *= 1.26; } if(Right[i] > 0 && Left[i] == 0) { PPP[i].Hsml /= 1.26; } } if(PPP[i].Hsml < All.MinGasHsml) PPP[i].Hsml = All.MinGasHsml; } else P[i].TimeBin = -P[i].TimeBin - 1; /* Mark as inactive */ /* CECILIA */ if(iter == MAXITER) { int old_type; old_type = P[i].Type; P[i].Type = 4; /* no SN mark any more */ PPP[i].n.NumNgb = 0; printf("part=%d of type=%d was assigned NumNgb=%g and type=%d\n", i, old_type, PPP[i].n.NumNgb, P[i].Type); } } } sumup_large_ints(1, &npleft, &ntot); if(ntot > 0) { iter++; if(iter > 0 && ThisTask == 0) { printf("ngb iteration %d: need to repeat for %d%09d particles.\n", iter, (int) (ntot / 1000000000), (int) (ntot % 1000000000)); fflush(stdout); } if(iter > MAXITER) { #ifndef CS_FEEDBACK printf("failed to converge in neighbour iteration in update_weights \n"); fflush(stdout); endrun(1155); #else /* CECILIA */ if(Flag_phase == 2) /* HOT */ { printf("Not enough hot neighbours for energy/metal distribution part=%d Type=%d\n", i, P[i].Type); fflush(stdout); break; /* endrun(1156); */ } else { printf("Not enough cold neighbours for energy/metal distribution part=%d Type=%d\n", i, P[i].Type); fflush(stdout); break; } #endif } } } while(ntot > 0); myfree(DataNodeList); myfree(DataIndexTable); myfree(R2ngblist); myfree(Ngblist); myfree(Right); myfree(Left); /* mark as active again */ for(i = FirstActiveParticle; i >= 0; i = NextActiveParticle[i]) if(P[i].TimeBin < 0) P[i].TimeBin = -P[i].TimeBin - 1; /* collect some timing information */ if(ThisTask == 0) { printf("... update weights phase = %d done...\n", Flag_phase); fflush(stdout); } }
void cs_find_hot_neighbours(void) { MyFloat *Left, *Right; int nimport; int i, j, n, ndone_flag, dummy; int ndone, ntot, npleft; int iter = 0; int ngrp, sendTask, recvTask; int place, nexport; double dmax1, dmax2; double xhyd, yhel, ne, mu, energy, temp; double a3inv; if(All.ComovingIntegrationOn) a3inv = 1 / (All.Time * All.Time * All.Time); else a3inv = 1; /* allocate buffers to arrange communication */ Left = (MyFloat *) mymalloc(NumPart * sizeof(MyFloat)); Right = (MyFloat *) mymalloc(NumPart * sizeof(MyFloat)); Ngblist = (int *) mymalloc(NumPart * sizeof(int)); All.BunchSize = (int) ((All.BufferSize * 1024 * 1024) / (sizeof(struct data_index) + sizeof(struct data_nodelist) + sizeof(struct hotngbs_in) + sizeof(struct hotngbs_out) + sizemax(sizeof(struct hotngbs_in), sizeof(struct hotngbs_out)))); DataIndexTable = (struct data_index *) mymalloc(All.BunchSize * sizeof(struct data_index)); DataNodeList = (struct data_nodelist *) mymalloc(All.BunchSize * sizeof(struct data_nodelist)); CPU_Step[CPU_MISC] += measure_time(); for(n = FirstActiveParticle; n >= 0; n = NextActiveParticle[n]) { if(P[n].Type == 0) { /* select reservoir and cold phase particles */ if(P[n].EnergySN > 0 && SphP[n].d.Density * a3inv > All.PhysDensThresh * All.DensFrac_Phase) { xhyd = P[n].Zm[6] / P[n].Mass; yhel = (1 - xhyd) / (4. * xhyd); ne = SphP[n].Ne; mu = (1 + 4 * yhel) / (1 + yhel + ne); energy = SphP[n].Entropy * P[n].Mass / GAMMA_MINUS1 * pow(SphP[n].d.Density * a3inv, GAMMA_MINUS1); /* Total Energys */ temp = GAMMA_MINUS1 / BOLTZMANN * energy / P[n].Mass * PROTONMASS * mu; temp *= All.UnitEnergy_in_cgs / All.UnitMass_in_g; /* Temperature in Kelvin */ if(temp < All.Tcrit_Phase) { Left[n] = Right[n] = 0; if(!(SphP[n].HotHsml > 0.)) SphP[n].HotHsml = All.InitialHotHsmlFactor * PPP[n].Hsml; /* Estimation of HotHsml : ONLY first step */ P[n].Type = 10; /* temporarily mark particles of interest with this number */ } } } } /* we will repeat the whole thing for those particles where we didn't find enough neighbours */ do { i = FirstActiveParticle; /* beginn with this index */ do { for(j = 0; j < NTask; j++) { Send_count[j] = 0; Exportflag[j] = -1; } /* do local particles and prepare export list */ for(nexport = 0; i >= 0; i = NextActiveParticle[i]) if(P[i].Type == 10 && P[i].TimeBin >= 0) { if(cs_hotngbs_evaluate(i, 0, &nexport, Send_count) < 0) break; } #ifdef MYSORT mysort_dataindex(DataIndexTable, nexport, sizeof(struct data_index), data_index_compare); #else qsort(DataIndexTable, nexport, sizeof(struct data_index), data_index_compare); #endif MPI_Allgather(Send_count, NTask, MPI_INT, Sendcount_matrix, NTask, MPI_INT, MPI_COMM_WORLD); for(j = 0, nimport = 0, Recv_offset[0] = 0, Send_offset[0] = 0; j < NTask; j++) { Recv_count[j] = Sendcount_matrix[j * NTask + ThisTask]; nimport += Recv_count[j]; if(j > 0) { Send_offset[j] = Send_offset[j - 1] + Send_count[j - 1]; Recv_offset[j] = Recv_offset[j - 1] + Recv_count[j - 1]; } } HotNgbsGet = (struct hotngbs_in *) mymalloc(nimport * sizeof(struct hotngbs_in)); HotNgbsIn = (struct hotngbs_in *) mymalloc(nexport * sizeof(struct hotngbs_in)); /* prepare particle data for export */ for(j = 0; j < nexport; j++) { place = DataIndexTable[j].Index; HotNgbsIn[j].Pos[0] = P[place].Pos[0]; HotNgbsIn[j].Pos[1] = P[place].Pos[1]; HotNgbsIn[j].Pos[2] = P[place].Pos[2]; HotNgbsIn[j].HotHsml = SphP[place].HotHsml; HotNgbsIn[j].Entropy = SphP[place].Entropy; memcpy(HotNgbsIn[j].NodeList, DataNodeList[DataIndexTable[j].IndexGet].NodeList, NODELISTLENGTH * sizeof(int)); } for(ngrp = 1; ngrp < (1 << PTask); ngrp++) { sendTask = ThisTask; recvTask = ThisTask ^ ngrp; if(recvTask < NTask) { if(Send_count[recvTask] > 0 || Recv_count[recvTask] > 0) { /* get the particles */ MPI_Sendrecv(&HotNgbsIn[Send_offset[recvTask]], Send_count[recvTask] * sizeof(struct hotngbs_in), MPI_BYTE, recvTask, TAG_DENS_A, &HotNgbsGet[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(struct hotngbs_in), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } } } myfree(HotNgbsIn); HotNgbsResult = (struct hotngbs_out *) mymalloc(nimport * sizeof(struct hotngbs_out)); HotNgbsOut = (struct hotngbs_out *) mymalloc(nexport * sizeof(struct hotngbs_out)); /* now do the particles that need to be exported */ for(j = 0; j < nimport; j++) cs_hotngbs_evaluate(j, 1, &dummy, &dummy); if(i < 0) ndone_flag = 1; else ndone_flag = 0; MPI_Allreduce(&ndone_flag, &ndone, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); /* get the result */ for(ngrp = 1; ngrp < (1 << PTask); ngrp++) { sendTask = ThisTask; recvTask = ThisTask ^ ngrp; if(recvTask < NTask) { if(Send_count[recvTask] > 0 || Recv_count[recvTask] > 0) { /* send the results */ MPI_Sendrecv(&HotNgbsResult[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(struct hotngbs_out), MPI_BYTE, recvTask, TAG_DENS_B, &HotNgbsOut[Send_offset[recvTask]], Send_count[recvTask] * sizeof(struct hotngbs_out), MPI_BYTE, recvTask, TAG_DENS_B, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } } } /* add the result to the local particles */ for(j = 0; j < nexport; j++) { place = DataIndexTable[j].Index; SphP[place].da.dDensityAvg += HotNgbsOut[j].DensitySum; SphP[place].ea.dEntropyAvg += HotNgbsOut[j].EntropySum; SphP[place].HotNgbNum += HotNgbsOut[j].HotNgbNum; } myfree(HotNgbsOut); myfree(HotNgbsResult); myfree(HotNgbsGet); } while(ndone < NTask); /* do final operations on results */ for(i = FirstActiveParticle, npleft = 0; i >= 0; i = NextActiveParticle[i]) { if(P[i].Type == 10 && P[i].TimeBin >= 0) { #ifdef FLTROUNDOFFREDUCTION SphP[i].da.DensityAvg = FLT(SphP[i].da.dDensityAvg); SphP[i].ea.EntropyAvg = FLT(SphP[i].ea.dEntropyAvg); #endif if(SphP[i].HotNgbNum > 0) { SphP[i].da.DensityAvg /= SphP[i].HotNgbNum; SphP[i].ea.EntropyAvg /= SphP[i].HotNgbNum; } else { SphP[i].da.DensityAvg = 0; SphP[i].ea.EntropyAvg = 0; } /* now check whether we had enough neighbours */ if(SphP[i].HotNgbNum < (All.DesNumNgb - All.MaxNumHotNgbDeviation) || (SphP[i].HotNgbNum > (All.DesNumNgb + All.MaxNumHotNgbDeviation))) { /* need to redo this particle */ npleft++; if(Left[i] > 0 && Right[i] > 0) if((Right[i] - Left[i]) < 1.0e-3 * Left[i]) { /* this one should be ok */ npleft--; P[i].TimeBin = -P[i].TimeBin - 1; /* Mark as inactive */ continue; } if(SphP[i].HotNgbNum < (All.DesNumNgb - All.MaxNumHotNgbDeviation)) Left[i] = DMAX(SphP[i].HotHsml, Left[i]); else { if(Right[i] != 0) { if(SphP[i].HotHsml < Right[i]) Right[i] = SphP[i].HotHsml; } else Right[i] = SphP[i].HotHsml; } if(Left[i] > All.MaxHotHsmlParam * PPP[i].Hsml) /* prevent us from searching too far */ { npleft--; P[i].TimeBin = -P[i].TimeBin - 1; /* Mark as inactive */ /* Ad-hoc definition of SAvg and RhoAvg when there are no hot neighbours */ /* Note that a minimum nunmber of hot neighbours are required for promotion, see c_enrichment.c */ if(SphP[i].HotNgbNum == 0) { SphP[i].da.DensityAvg = SphP[i].d.Density / 100; SphP[i].ea.EntropyAvg = SphP[i].Entropy * 1000; printf("WARNING: Used ad-hoc values for SAvg and RhoAvg, No hot neighbours\n"); } continue; } if(iter >= MAXITER_HOT - 10) { printf ("i=%d task=%d ID=%d Hsml=%g Left=%g Right=%g Ngbs=%g Right-Left=%g\n pos=(%g|%g|%g)\n", i, ThisTask, P[i].ID, SphP[i].HotHsml, Left[i], Right[i], (float) SphP[i].HotNgbNum, Right[i] - Left[i], P[i].Pos[0], P[i].Pos[1], P[i].Pos[2]); fflush(stdout); } if(Right[i] > 0 && Left[i] > 0) SphP[i].HotHsml = pow(0.5 * (pow(Left[i], 3) + pow(Right[i], 3)), 1.0 / 3); else { if(Right[i] == 0 && Left[i] == 0) endrun(8188); /* can't occur */ if(Right[i] == 0 && Left[i] > 0) SphP[i].HotHsml *= 1.26; if(Right[i] > 0 && Left[i] == 0) SphP[i].HotHsml /= 1.26; } } else P[i].TimeBin = -P[i].TimeBin - 1; /* Mark as inactive */ } } MPI_Allreduce(&npleft, &ntot, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); if(ntot > 0) { iter++; if(iter > 0 && ThisTask == 0) { printf("hotngb iteration %d: need to repeat for %d particles.\n", iter, ntot); fflush(stdout); } if(iter > MAXITER_HOT) { printf("failed to converge in hot-neighbour iteration\n"); fflush(stdout); endrun(1155); } } } while(ntot > 0); myfree(DataNodeList); myfree(DataIndexTable); myfree(Ngblist); myfree(Right); myfree(Left); for(i = FirstActiveParticle; i >= 0; i = NextActiveParticle[i]) if(P[i].Type == 10) { P[i].Type = 0; /* mark as active again */ if(P[i].TimeBin < 0) P[i].TimeBin = -P[i].TimeBin - 1; } CPU_Step[CPU_HOTNGBS] += measure_time(); }
/* solves the recombination equation and updates the HI and HII abundances */ void radtransfer_update_chemistry(void) { int i, j, n; double inter_dt, nH, temp, alpha, a3inv, gamma, molecular_weight; #ifdef RT_PHOTOHEATING double dtemp, e1, sigma1, de1, rate1; double eV_to_erg = 1.60184e-12; #endif #ifdef RT_COOLING double de2, de3, de4, de5, rate2, rate3, rate4, rate5; #endif double a, b, c, s = 1, q; n = 1; inter_dt = dt / FLT(n); if(All.ComovingIntegrationOn) a3inv = 1 / (All.Time * All.Time * All.Time); else a3inv = 1.0; /* begin substepping */ for(j = 0; j < n; j++) for(i = 0; i < N_gas; i++) if(P[i].Type == 0) #ifdef RT_VAR_DT if(SphP[i].rt_flag == 1) #endif { SphP[i].n_gamma /= P[i].Mass; /* number of photons should be positive */ if(SphP[i].n_gamma < 0) { printf("NEGATIVE n_gamma: %g %d %d \n", SphP[i].n_gamma, i, ThisTask); endrun(111); } nH = (SphP[i].d.Density * a3inv) / (PROTONMASS / All.UnitMass_in_g * All.HubbleParam); //physical molecular_weight = 4 / (1 + 3 * HYDROGEN_MASSFRAC); //needed to obtain correct temperatures /* molecular_weight should equal 1 in this case, but then HYDROGEN_MASSFRAC has to be set to 1 in allvars.h */ temp = SphP[i].Entropy * pow(SphP[i].d.Density * a3inv, GAMMA_MINUS1) * molecular_weight * (PROTONMASS / All.UnitMass_in_g) / (BOLTZMANN / All.UnitEnergy_in_cgs); //printf("temp %g %g %g\n", temp, molecular_weight, HYDROGEN_MASSFRAC); /* collisional ionization rate */ #ifdef RT_COLLISIONAL_IONIZATION gamma = 5.85e-11 * pow(temp,0.5) * exp(-157809.1/temp) / (1.0 + pow(temp/1e5,0.5)); gamma *= All.UnitTime_in_s / All.UnitLength_in_cm / All.UnitLength_in_cm / All.UnitLength_in_cm; gamma *= All.HubbleParam * All.HubbleParam; #else gamma=0; #endif /* alpha_B recombination coefficient */ alpha = 2.59e-13 * pow(temp/1e4,-0.7); alpha *= All.UnitTime_in_s / All.UnitLength_in_cm / All.UnitLength_in_cm / All.UnitLength_in_cm; alpha *= All.HubbleParam * All.HubbleParam; #ifndef SEMI_IMPLICIT /* implicit scheme for ionization*/ a = inter_dt * alpha * nH; b = -2.0 * inter_dt * alpha * nH - inter_dt * c_light * sigma * nH * SphP[i].n_gamma - 1.0; c = SphP[i].nHI + inter_dt * alpha * nH; if(b > 0) s = 1.0; if(b < 0) s = -1.0; if(b == 0) s = 0.0; q = -0.5 * (b + s * sqrt(b * b - 4.0 * a * c)); SphP[i].nHI = c / q; #ifdef RT_NO_RECOMBINATIONS SphP[i].nHII += inter_dt * c_light * sigma * nH * SphP[i].n_gamma * SphP[i].nHI; SphP[i].nHI = 1.0 - SphP[i].nHII; #endif if(SphP[i].nHI < 0 && SphP[i].nHI > -EPSILON) SphP[i].nHI = 0; if(SphP[i].nHI > 1 && SphP[i].nHI < (1+EPSILON)) SphP[i].nHI = 1; if(SphP[i].nHI < -EPSILON || SphP[i].nHI > (1+EPSILON)) { printf("WRONG nHII: %g %d %d \n", SphP[i].nHII, i, ThisTask); endrun(222); } SphP[i].nHII = 1 - SphP[i].nHI; SphP[i].n_elec = SphP[i].nHII; #else /* semi-implicit scheme for ionization*/ SphP[i].nHII = (SphP[i].nHII + inter_dt * c_light * sigma * nH * SphP[i].n_gamma + inter_dt * gamma * nH * SphP[i].n_elec) / (1.0 + inter_dt * c_light * sigma * nH * SphP[i].n_gamma + inter_dt * alpha * nH * SphP[i].n_elec + inter_dt * gamma * nH * SphP[i].n_elec); /* fraction should be between 0 and 1 */ if(SphP[i].nHII < 0 || SphP[i].nHII > 1) { printf("WRONG nHII: %g %d %d \n", SphP[i].nHII, i, ThisTask); endrun(222); } SphP[i].nHI = 1 - SphP[i].nHII; SphP[i].n_elec = SphP[i].nHII; #endif #ifdef RT_PHOTOHEATING /*photoheating for 10^5K blackbody*/ sigma1 = 1.63e-18 / All.UnitLength_in_cm / All.UnitLength_in_cm; //code units sigma1 *= All.HubbleParam * All.HubbleParam; e1 = 29.65 * eV_to_erg; //real units /* all rates in erg cm^3 s^-1 in code units and energy in ergs*/ /* photoheating rate */ rate1 = c_light * e1 * sigma1; de1 = SphP[i].nHI * nH * SphP[i].n_gamma * nH * rate1; dtemp = de1 * GAMMA_MINUS1 / nH / BOLTZMANN * inter_dt; SphP[i].Entropy += dtemp * (BOLTZMANN / All.UnitEnergy_in_cgs) / pow(SphP[i].d.Density * a3inv, GAMMA_MINUS1) / molecular_weight / (PROTONMASS / All.UnitMass_in_g); #endif #ifdef RT_COOLING /* recombination cooling rate */ rate2 = 8.7e-27 * pow(temp,0.5) * pow(temp/1e3,-0.2) / (1.0 + pow(temp/1e6,0.7)); rate2 *= All.UnitTime_in_s / All.UnitLength_in_cm / All.UnitLength_in_cm / All.UnitLength_in_cm; rate2 *= All.HubbleParam * All.HubbleParam; /* collisional ionization cooling rate */ rate3 = 1.27e-21 * pow(temp,0.5) * exp(-157809.1/temp) / (1.0 + pow(temp/1e5,0.5)); rate3 *= All.UnitTime_in_s / All.UnitLength_in_cm / All.UnitLength_in_cm / All.UnitLength_in_cm; rate3 *= All.HubbleParam * All.HubbleParam; /* collisional excitation cooling rate */ rate4 = 7.5e-19 * (1.0 + pow(temp/1e5,0.5)) * exp(-118348/temp); rate4 *= All.UnitTime_in_s / All.UnitLength_in_cm / All.UnitLength_in_cm / All.UnitLength_in_cm; rate4 *= All.HubbleParam * All.HubbleParam; /* Bremsstrahlung cooling rate */ rate5 = 1.42e-27 * 1.3 * pow(temp,0.5); rate5 *= All.UnitTime_in_s / All.UnitLength_in_cm / All.UnitLength_in_cm / All.UnitLength_in_cm; rate5 *= All.HubbleParam * All.HubbleParam; de2 = SphP[i].nHII * nH * SphP[i].n_elec * nH * rate2; de3 = SphP[i].nHI * nH * SphP[i].n_elec * nH * rate3; de4 = SphP[i].nHI * nH * SphP[i].n_elec * nH * rate4; de5 = SphP[i].nHII * nH * SphP[i].n_elec * nH * rate5; dtemp = (de2 + de3 + de4 + de5) * GAMMA_MINUS1 / nH / BOLTZMANN * inter_dt; SphP[i].Entropy -= dtemp * (BOLTZMANN / All.UnitEnergy_in_cgs) / pow(SphP[i].d.Density * a3inv, GAMMA_MINUS1) / molecular_weight / (PROTONMASS / All.UnitMass_in_g); #endif SphP[i].n_gamma *= P[i].Mass; } }
int main() { fs_hash_init(FS_HASH_UMAC); int passes = 0; int fails = 0; #if 1 #define DUMP(t) printf("%lld %s\n", fs_c.xsd_##t, #t); DUMP(double); DUMP(float); DUMP(decimal); DUMP(integer); DUMP(boolean); #endif #define TEST1(f, a, x) printf("[%s] ", fs_value_equal(f(NULL, a), x) ? "PASS" : "FAIL"); printf("%s(", #f); fs_value_print(a); printf(") = "); fs_value_print(f(NULL, a)); printf("\n"); if (!fs_value_equal(f(NULL, a), x)) { fails++; printf(" should have been "); fs_value_print(x); printf("\n"); } else { passes++; } #define TEST2(f, a, b, x) printf("[%s] ", fs_value_equal(f(NULL, a, b), x) ? "PASS" : "FAIL"); printf("%s(", #f); fs_value_print(a); printf(", "); fs_value_print(b); printf(") = "); fs_value_print(f(NULL, a, b)); printf("\n"); if (!fs_value_equal(f(NULL, a, b), x)) { fails++; printf(" should have been "); fs_value_print(x); printf("\n"); } else { passes++; } #define TEST3(f, a, b, c, x) printf("[%s] ", fs_value_equal(f(NULL, a, b, c), x) ? "PASS" : "FAIL"); printf("%s(", #f); fs_value_print(a); printf(", "); fs_value_print(b); printf(", "); fs_value_print(c); printf(") = "); fs_value_print(f(NULL, a, b, c)); printf("\n"); if (!fs_value_equal(f(NULL, a, b, c), x)) { fails++; printf(" should have been "); fs_value_print(x); printf("\n"); } else { passes++; } #define URI(x) fs_value_uri(x) #define RID(x) fs_value_rid(x) #define BND(x) fs_value_rid(0x8000000000000000LL | x) #define STR(x) fs_value_string(x) #define PLN(x) fs_value_plain(x) #define PLN_L(x, l) fs_value_plain_with_lang(x, l) #define DBL(x) fs_value_double(x) #define FLT(x) fs_value_float(x) #define DEC(x) fs_value_decimal(x) #define INT(x) fs_value_integer(x) #define BLN(x) fs_value_boolean(x) #define DAT(x) fs_value_datetime(x) #define DAT_S(x) fs_value_datetime_from_string(x) #define ERR() fs_value_error(FS_ERROR_INVALID_TYPE, NULL) #define BLK() fs_value_blank() TEST2(fn_numeric_add, BLK(), BLK(), ERR()); TEST2(fn_numeric_add, INT(1), URI("test:"), ERR()); TEST2(fn_numeric_add, STR("2"), INT(3), ERR()); TEST2(fn_numeric_add, INT(2), INT(3), INT(5)); TEST2(fn_numeric_add, DEC(2.5), DEC(-1), DEC(1.5)); TEST2(fn_numeric_add, DEC(-2.5), DEC(-1.5), DEC(-4)); TEST2(fn_numeric_subtract, INT(2), INT(3), INT(-1)); TEST2(fn_numeric_add, DBL(1), INT(2), DBL(3)); TEST2(fn_numeric_add, FLT(17000), INT(2), FLT(17002)); TEST2(fn_numeric_subtract, FLT(17000), INT(2), FLT(16998)); TEST2(fn_numeric_subtract, DEC(17000.5), INT(2), DEC(16998.5)); TEST2(fn_numeric_multiply, URI("http://example.com/"), INT(2), ERR()); TEST2(fn_numeric_multiply, DEC(3.5), INT(2), DEC(7)); TEST2(fn_numeric_multiply, DEC(35), DBL(-0.1), DBL(-3.5)); TEST2(fn_numeric_multiply, INT(1), FLT(23), FLT(23)); TEST2(fn_numeric_multiply, INT(10), INT(23), INT(230)); TEST2(fn_numeric_divide, INT(9), URI("http://example.org/"), ERR()); TEST2(fn_numeric_divide, INT(9), INT(2), DEC(4.5)); TEST2(fn_numeric_divide, INT(-9), INT(2), DEC(-4.5)); TEST2(fn_numeric_divide, INT(-9), INT(-2), DEC(4.5)); TEST2(fn_numeric_divide, DBL(90), FLT(10), DBL(9)); TEST2(fn_numeric_divide, FLT(99), FLT(-10), FLT(-9.9)); TEST2(fn_equal, URI("http://example.com/"), DEC(23), BLN(0)); TEST2(fn_equal, URI("http://example.com/"), URI("http://example.com/"), BLN(1)); TEST2(fn_equal, INT(23), DEC(23), BLN(1)); TEST2(fn_equal, fs_value_decimal_from_string("-23.0"), DEC(-23), BLN(1)); TEST2(fn_equal, STR("foo"), PLN("foo"), BLN(0)); TEST2(fn_equal, PLN("foo"), PLN("foo"), BLN(1)); TEST2(fn_equal, BLN(0), BLN(0), BLN(1)); TEST2(fn_greater_than, STR("BBB"), STR("AAA"), BLN(1)); TEST2(fn_greater_than, PLN("BBB"), PLN("AAA"), BLN(1)); TEST2(fn_greater_than, PLN("AAA"), PLN("BBB"), BLN(0)); TEST2(fn_less_than, PLN("BBB"), PLN("AAA"), BLN(0)); TEST2(fn_less_than, PLN("AAA"), PLN("BBB"), BLN(1)); TEST2(fn_less_than, INT(20), INT(15), BLN(0)); TEST2(fn_numeric_equal, INT(23), INT(23), BLN(1)); TEST2(fn_numeric_equal, INT(23), DEC(23), BLN(1)); TEST2(fn_numeric_equal, INT(23), FLT(23), BLN(1)); TEST2(fn_numeric_equal, INT(23), DBL(23), BLN(1)); TEST2(fn_numeric_equal, fn_minus(NULL, INT(23)), DBL(-23), BLN(1)); TEST2(fn_datetime_equal, DAT(1000), DAT(1000), BLN(1)); TEST2(fn_datetime_equal, DAT(time(NULL)), DAT(1000), BLN(0)); TEST2(fn_numeric_less_than, INT(0), DBL(23), BLN(1)); TEST2(fn_numeric_less_than, INT(23), DBL(23), BLN(0)); TEST2(fn_numeric_less_than, DBL(22.99999), INT(23), BLN(1)); TEST2(fn_numeric_less_than, DEC(-18.51), DEC(-18.5), BLN(1)); TEST2(fn_numeric_less_than, DBL(-18.51), DBL(-18.5), BLN(1)); TEST2(fn_numeric_less_than, DEC(-18.5), DEC(-18.51), BLN(0)); TEST2(fn_numeric_less_than, DBL(-18.5), DBL(-18.51), BLN(0)); TEST2(fn_numeric_greater_than, DEC(-121.98882), DEC(-121.739856), BLN(0)); TEST2(fn_numeric_greater_than, DEC(37.67473), DEC(37.677954), BLN(0)); TEST2(fn_numeric_greater_than, INT(0), DBL(23), BLN(0)); TEST2(fn_numeric_greater_than, INT(23), DBL(23), BLN(0)); TEST2(fn_numeric_greater_than, DBL(22.99999), INT(23), BLN(0)); TEST2(fn_numeric_greater_than, DEC(-18.51), DEC(-18.5), BLN(0)); TEST2(fn_numeric_greater_than, DBL(-18.51), DBL(-18.5), BLN(0)); TEST2(fn_numeric_greater_than, DEC(-18.5), DEC(-18.51), BLN(1)); TEST2(fn_numeric_greater_than, DBL(-18.5), DBL(-18.51), BLN(1)); TEST2(fn_logical_and, BLN(1), BLN(0), BLN(0)); TEST2(fn_logical_and, BLN(1), BLN(1), BLN(1)); TEST2(fn_logical_and, INT(0), INT(1), BLN(0)); TEST2(fn_logical_and, INT(1), INT(1), BLN(1)); TEST2(fn_logical_and, STR("true"), INT(1), BLN(1)); TEST2(fn_logical_and, STR("false"), INT(1), BLN(1)); TEST2(fn_logical_and, INT(1), ERR(), ERR()); TEST2(fn_logical_and, ERR(), INT(1), ERR()); TEST2(fn_logical_and, INT(0), ERR(), BLN(0)); TEST2(fn_logical_and, ERR(), INT(0), BLN(0)); TEST2(fn_logical_and, ERR(), ERR(), ERR()); TEST2(fn_logical_or, BLN(1), BLN(0), BLN(1)); TEST2(fn_logical_or, BLN(1), BLN(1), BLN(1)); TEST2(fn_logical_or, INT(0), INT(1), BLN(1)); TEST2(fn_logical_or, INT(1), INT(1), BLN(1)); TEST2(fn_logical_or, STR("true"), INT(32), BLN(1)); TEST2(fn_logical_or, STR("false"), INT(1), BLN(1)); TEST2(fn_logical_or, INT(1), ERR(), BLN(1)); TEST2(fn_logical_or, ERR(), INT(1), BLN(1)); TEST2(fn_logical_or, INT(0), ERR(), ERR()); TEST2(fn_logical_or, ERR(), INT(0), ERR()); TEST2(fn_logical_or, ERR(), ERR(), ERR()); TEST2(fn_compare, STR("AAA"), STR("BBB"), INT(-1)); TEST2(fn_compare, STR("BBB"), STR("BBB"), INT(0)); TEST2(fn_compare, STR("BBB"), STR("AAA"), INT(1)); TEST2(fn_compare, PLN("BBB"), PLN("AAA"), INT(1)); TEST2(fn_compare, STR("BBB"), PLN("BBB"), ERR()); TEST2(fn_compare, STR("http://example.com/"), URI("http://example.com/"), ERR()); TEST2(fn_compare, URI("http://example.com/"), URI("http://example.com/"), ERR()); TEST2(fn_compare, INT(1), PLN("BBB"), ERR()); TEST3(fn_matches, PLN("foobar"), PLN("foo"), BLK(), BLN(1)); TEST3(fn_matches, PLN("foobar"), PLN("^foo"), BLK(), BLN(1)); TEST3(fn_matches, PLN("foobar"), PLN("bar$"), BLK(), BLN(1)); TEST3(fn_matches, PLN("foobar"), PLN("BAR"), STR("i"), BLN(1)); TEST3(fn_matches, PLN("foobar"), PLN("^FOOB[AO]R$"), STR("i"), BLN(1)); TEST3(fn_matches, PLN("foobar"), PLN("^bar"), BLK(), BLN(0)); TEST3(fn_matches, PLN("foobar"), PLN("^foo$"), BLK(), BLN(0)); TEST3(fn_matches, PLN("foobar"), PLN("foo bar"), PLN("x"), BLN(1)); TEST3(fn_matches, INT(23), PLN("foo bar"), PLN("x"), ERR()); TEST3(fn_matches, PLN("foobar"), DAT(1000), PLN("x"), ERR()); TEST1(fn_bound, URI("http://example.com/"), BLN(1)); TEST1(fn_bound, STR("http"), BLN(1)); TEST1(fn_bound, PLN(""), BLN(1)); TEST1(fn_bound, BND(100), BLN(1)); TEST1(fn_bound, RID(FS_RID_NULL), BLN(0)); TEST1(fn_is_blank, URI("http://example.com/"), BLN(0)); TEST1(fn_is_blank, STR("http"), BLN(0)); TEST1(fn_is_blank, PLN(""), BLN(0)); TEST1(fn_is_blank, BND(100), BLN(1)); TEST1(fn_is_blank, RID(FS_RID_NULL), BLN(0)); TEST1(fn_is_iri, URI("http://example.com/"), BLN(1)); TEST1(fn_is_iri, STR("http"), BLN(0)); TEST1(fn_is_iri, PLN(""), BLN(0)); TEST1(fn_is_iri, BND(100), BLN(0)); TEST1(fn_is_iri, RID(FS_RID_NULL), BLN(0)); TEST1(fn_is_literal, URI("http://example.com/"), BLN(0)); TEST1(fn_is_literal, STR("http"), BLN(1)); TEST1(fn_is_literal, PLN(""), BLN(1)); TEST1(fn_is_literal, BND(100), BLN(0)); TEST1(fn_is_literal, RID(FS_RID_NULL), BLN(0)); TEST1(fn_str, URI("http://example.com/"), PLN("http://example.com/")); TEST1(fn_str, STR("http"), PLN("http")); TEST1(fn_str, PLN(""), PLN("")); TEST1(fn_str, BLN(1), PLN("true")); TEST1(fn_str, INT(1), PLN("1")); TEST1(fn_str, FLT(11.1), PLN("11.100000")); TEST1(fn_str, DBL(11.1), PLN("11.100000")); TEST1(fn_str, DEC(23), PLN("23.000000")); TEST1(fn_str, DAT(1000), PLN("1970-01-01T00:16:40")); TEST1(fn_str, BND(100), ERR()); TEST1(fn_str, RID(FS_RID_NULL), ERR()); TEST1(fn_lang, PLN("foo"), PLN("")); TEST1(fn_lang, STR("foo"), PLN("")); TEST1(fn_lang, PLN_L("foo", "en"), PLN("en")); TEST1(fn_lang, PLN_L("foo", ""), PLN("")); TEST1(fn_lang, BLN(1), PLN("")); TEST1(fn_lang, INT(1), PLN("")); TEST1(fn_lang, DEC(1.1), PLN("")); TEST1(fn_lang, FLT(1.1), PLN("")); TEST1(fn_lang, DBL(1.1), PLN("")); TEST1(fn_lang, URI("http://example.org/"), ERR()); TEST1(fn_datatype, PLN("foo"), ERR()); TEST1(fn_datatype, STR("foo"), URI(XSD_STRING)); TEST1(fn_datatype, PLN_L("foo", "en"), ERR()); TEST1(fn_datatype, PLN_L("foo", ""), ERR()); TEST1(fn_datatype, BLN(1), URI(XSD_BOOLEAN)); TEST1(fn_datatype, INT(1), URI(XSD_INTEGER)); TEST1(fn_datatype, DEC(1.1), URI(XSD_DECIMAL)); TEST1(fn_datatype, FLT(1.1), URI(XSD_FLOAT)); TEST1(fn_datatype, DBL(1.1), URI(XSD_DOUBLE)); TEST1(fn_datatype, DAT(1000), URI(XSD_DATETIME)); TEST1(fn_datatype, URI("http://example.org/"), ERR()); TEST2(fn_equal, DAT_S("1975-01-07"), DAT(158284800), BLN(1)); TEST2(fn_equal, DAT_S("1975-01-07T00:00:01"), DAT(158284801), BLN(1)); TEST2(fn_equal, DAT_S("1975-01-07T01:00:01+0000"), DAT(158288401), BLN(1)); TEST2(fn_equal, DAT_S("1975-01-07T01:00:01-0900"), DAT(158320801), BLN(1)); TEST2(fn_cast, DBL(2.1), URI(XSD_INTEGER), INT(2)); TEST2(fn_cast, PLN("2.23"), URI(XSD_DOUBLE), DBL(2.23)); TEST2(fn_cast, PLN_L("2.23", "en"), URI(XSD_DOUBLE), DBL(2.23)); TEST2(fn_cast, STR("2.23"), URI(XSD_DOUBLE), DBL(2.23)); TEST2(fn_cast, URI("http://example.com/"), URI(XSD_STRING), ERR()); TEST2(fn_cast, DAT(1000), URI(XSD_STRING), STR("1970-01-01T00:16:40")); TEST2(fn_cast, STR("1975-01-07T01:00:01-0900"), URI(XSD_DATETIME), DAT(158320801)); printf("\n=== pass %d, fail %d\n", passes, fails); if (fails) { return 1; } return 0; }
// Viterbi search void WFSADecoder::viterbi(float *fFeatureVectors, unsigned int iFeatureVectors) { double dTimeBegin = TimeUtils::getTimeMilliseconds(); float fScore = 0.0; HMMStateDecoding *hmmStateDecoding; m_iFeatureVectors = iFeatureVectors; m_hmmManager->resetHMMEmissionProbabilityComputation(); m_activeStateTable->beginUtterance(); unsigned int iLexUnitEndSentence = m_lexiconManager->m_lexUnitEndSentence->iLexUnit; // create the initial set of active states (states coming from the initial state and non-epsilon arcs) StateX *stateInitial = m_wfsAcceptor->getInitialState(); m_activeStateTable->activateStateInitial(stateInitial); TransitionX *transition = NULL; TransitionX *transitionEnd = NULL; TransitionX *transitionAux = NULL; ActiveState *activeStatesCurrent = NULL; unsigned int iActiveStatesCurrent = 0; //m_activeStateTable->printSubgraph(stateInitial); //exit(-1); // process the feature vectors for(unsigned int t=0 ; t < iFeatureVectors ; ++t) { m_fScoreBest = -FLT_MAX; #ifdef SIMD float *fFeatureVector = &(fFeatureVectors[t*FEATURE_VECTOR_LENGTH_ALIGNED_16]); #else float *fFeatureVector = &(fFeatureVectors[t*FEATURE_VECTOR_LENGTH]); #endif activeStatesCurrent = m_activeStateTable->getActiveStatesCurrent(&iActiveStatesCurrent); m_activeStateTable->m_iStatesExpanded = 0; m_activeStateTable->m_iStatesActivated = 0; m_activeStateTable->m_iStatesPruned = 0; // (1) process all the active states (these are non-epsilon states) for(unsigned int i = 0 ; i < iActiveStatesCurrent ; ++i) { // skip pruned states if (activeStatesCurrent[i].state == NULL) { continue; } bool bExpanded = false; ++m_activeStateTable->m_iStatesExpanded; ActiveState &activeState = activeStatesCurrent[i]; // (1.1) self-loop (this is a simulated transition) // compute emission probability #ifdef SIMD fScore = activeState.hmmStateDecoding->computeEmissionProbabilityNearestNeighborSIMD(fFeatureVector,t); #else fScore = activeState.hmmStateDecoding->computeEmissionProbabilityNearestNeighborPDE(fFeatureVector,t); #endif // preventive pruning goes here if (activeState.fScore+fScore < (m_fScoreBest-m_fPruningLikelihood)) { continue; } // lattice generation int iWGToken = -1; if (m_bLatticeGeneration) { assert(activeState.iWGToken != -1); iWGToken = m_activeStateTable->newWGToken(activeState.iWGToken); WGToken *wgToken = iWGToken+m_activeStateTable->m_wgTokens; // update the scores for(int i=0 ; ((i < m_activeStateTable->m_iMaxWordSequencesState) && (wgToken[i].iWordSequence != -1)) ; ++i) { wgToken[i].fScore += fScore; } } // activate the state m_activeStateTable->activateState(activeState.state,activeState.fScore+fScore,&m_fScoreBest, activeState.hmmStateDecoding,activeState.iHistoryItem,iWGToken,0.0); // (1.2) standard transitions // get the first and last transitions from the state transition = *activeState.state; transitionEnd = *(activeState.state+1); assert(transition <= transitionEnd); unsigned int iTransitions = 0; TransitionX *transitions = m_wfsAcceptor->getTransitions(&iTransitions); assert(transition < (transitions+iTransitions)); assert(transitionEnd <= (transitions+iTransitions)); while(transition != transitionEnd) { assert(transition != NULL); // epsilon-transition if (transition->iSymbol & EPSILON_TRANSITION) { // lattice generation int iWGToken = -1; if (m_bLatticeGeneration) { assert(activeState.iWGToken != -1); iWGToken = m_activeStateTable->newWGToken(activeState.iWGToken); WGToken *wgToken = iWGToken+m_activeStateTable->m_wgTokens; // update the scores for(int i=0 ; ((i < m_activeStateTable->m_iMaxWordSequencesState) && (wgToken[i].iWordSequence != -1)) ; ++i) { wgToken[i].fScore += transition->fWeight; } } // activate the state m_activeStateTable->activateStateEpsilon(transition->state,activeState.fScore+transition->fWeight, activeState.iHistoryItem,iWGToken,0.0); } // fake-transition else if (transition->iSymbol & FAKE_TRANSITION) { //bool bStop = true; } // lexical-unit transition else if (transition->iSymbol & LEX_UNIT_TRANSITION) { // create a new history item int iHistoryItem = m_activeStateTable->newHistoryItem(); HistoryItem *historyItem = m_activeStateTable->m_historyItems+iHistoryItem; historyItem->iPrev = activeState.iHistoryItem; historyItem->iLexUnitPron = transition->iSymbol & LEX_UNIT_TRANSITION_COMPLEMENT; historyItem->iEndFrame = t-1; historyItem->fScore = activeState.fScore+transition->fWeight; historyItem->iActive = -1; // lattice generation int iWGToken = -1; int iWordSequence = -1; if (m_bLatticeGeneration) { // keep the N word sequences arriving to the state assert(activeState.iWGToken != -1); historyItem->iWGToken = activeState.iWGToken; // checks for(int i=0 ; i < m_iMaxWordSequencesState ; ++i) { if ((historyItem->iWGToken+m_activeStateTable->m_wgTokens)[i].iWordSequence == -1) { break; } bool bFlag = false; if (m_activeStateTable->m_mWGTokenDeleted.find(historyItem->iWGToken+m_activeStateTable->m_wgTokens) != m_activeStateTable->m_mWGTokenDeleted.end()) { //printf("%x !!\n",historyItem->iWGToken+m_activeStateTable->m_wgTokens); bFlag = true; } assert(historyItem->iEndFrame > (m_activeStateTable->m_historyItems+ (historyItem->iWGToken+m_activeStateTable->m_wgTokens)[i].iHistoryItem)->iEndFrame); } // generate a new hash value for the new word sequence iWordSequence = m_activeStateTable->hashWordSequence(historyItem); } if ((transition->iSymbol & LEX_UNIT_TRANSITION_COMPLEMENT) == iLexUnitEndSentence) { //bool bStop = true; } for(transitionAux = *(transition->state) ; transitionAux != *(transition->state+1) ; ++transitionAux) { // epsilon-transition if (transitionAux->iSymbol & EPSILON_TRANSITION) { // preventive pruning if (activeState.fScore+transition->fWeight+transitionAux->fWeight < (m_fScoreBest-m_fPruningLikelihood)) { continue; } // lattice generation if (m_bLatticeGeneration) { bExpanded = true; iWGToken = m_activeStateTable->newWGToken(iWordSequence, activeState.fScore+transition->fWeight+transitionAux->fWeight,iHistoryItem); } // activate the state m_activeStateTable->activateStateEpsilon(transitionAux->state, activeState.fScore+transition->fWeight+transitionAux->fWeight,iHistoryItem,iWGToken,0.0); } // fake transition else if (transitionAux->iSymbol & FAKE_TRANSITION) { //bool bStop = true; } // lex-unit transition (end-of-sentence) else if (transitionAux->iSymbol & LEX_UNIT_TRANSITION) { if ((transitionAux->iSymbol & LEX_UNIT_TRANSITION_COMPLEMENT) == iLexUnitEndSentence) { //bool bStop = true; } } // leaf-transition else { // compute emission probability hmmStateDecoding = &m_hmmStatesDecoding[transitionAux->iSymbol]; #ifdef SIMD fScore = hmmStateDecoding->computeEmissionProbabilityNearestNeighborSIMD(fFeatureVector,t); #else fScore = hmmStateDecoding->computeEmissionProbabilityNearestNeighborPDE(fFeatureVector,t); #endif // preventive pruning if (activeState.fScore+transition->fWeight+transitionAux->fWeight+fScore < (m_fScoreBest-m_fPruningLikelihood)) { continue; } // lattice generation if (m_bLatticeGeneration) { bExpanded = true; iWGToken = m_activeStateTable->newWGToken(iWordSequence, activeState.fScore+transition->fWeight+transitionAux->fWeight+fScore,iHistoryItem); } // activate the state m_activeStateTable->activateState(transitionAux->state, activeState.fScore+transition->fWeight+transitionAux->fWeight+fScore, &m_fScoreBest,hmmStateDecoding,iHistoryItem,iWGToken,0.0); //printf("new lexical unit: %f\n",activeState.fScore+transition->fWeight+transitionAux->fWeight+fScore); } } } // leaf-transition else { // compute emission probability hmmStateDecoding = &m_hmmStatesDecoding[transition->iSymbol]; #ifdef SIMD fScore = hmmStateDecoding->computeEmissionProbabilityNearestNeighborSIMD(fFeatureVector,t); #else fScore = hmmStateDecoding->computeEmissionProbabilityNearestNeighborPDE(fFeatureVector,t); #endif // preventive pruning goes here if (activeState.fScore+transition->fWeight+fScore < (m_fScoreBest-m_fPruningLikelihood)) { transition++; continue; } // lattice generation int iWGToken = -1; if (m_bLatticeGeneration) { assert(activeState.iWGToken != -1); iWGToken = m_activeStateTable->newWGToken(activeState.iWGToken); WGToken *wgToken = iWGToken+m_activeStateTable->m_wgTokens; // update the scores for(int i=0 ; ((i < m_activeStateTable->m_iMaxWordSequencesState) && (wgToken[i].iWordSequence != -1)) ; ++i) { wgToken[i].fScore += transition->fWeight+fScore; } } // activate the state m_activeStateTable->activateState(transition->state,activeState.fScore+transition->fWeight+fScore, &m_fScoreBest,hmmStateDecoding,activeState.iHistoryItem,iWGToken,0.0); } transition++; } } //printf("# active states before processing epsilon-transitions: %d\n",); // sanity check if (m_bLatticeGeneration) { // active nodes of next time frame ActiveState *activeState = m_activeStateTable->m_activeStatesNext; while(activeState != m_activeStateTable->m_activeStateAvailable) { // make sure the WGToken structure keeps the historyItem if (activeState->iWGToken != -1) { assert(activeState->iHistoryItem != -1); WGToken *wgToken = activeState->iWGToken+m_activeStateTable->m_wgTokens; bool bFound = false; for(int i=0 ; ((i < m_activeStateTable->m_iMaxWordSequencesState) && (wgToken[i].iWordSequence != -1)) ; ++i) { if (wgToken[i].iHistoryItem == activeState->iHistoryItem) { bFound = true; } } assert(bFound); } ++activeState; } } // (3) process epsilon transitions in topological order m_activeStateTable->processEpsilonTransitions(fFeatureVector,&m_fScoreBest); if (t != iFeatureVectors-1) { // (4) apply beam pruning m_activeStateTable->beamPruning(&m_fScoreBest); // move to the next time frame m_activeStateTable->nextTimeFrame(); } else { cout << "t=" << setw(5) << t << " bestScore: " << FLT(14,6) << m_fScoreBest << endl; } } //m_activeStateTable->printInfo(); m_activeStateTable->endUtterance(); double dTimeEnd = TimeUtils::getTimeMilliseconds(); double dTimeSeconds = (dTimeEnd-dTimeBegin)/1000.0; BVC_VERB << "decoding time: " << FLT(8,2) << dTimeSeconds << " seconds (RTF: " << FLT(5,2) << dTimeSeconds/(((float)iFeatureVectors)/100.0) << ")"; }