static int fft_wisdom (lua_State *L) { if (lua_isnoneornil(L, 1)) { /* return wisdom? */ luaL_Buffer b; luaL_buffinit(L, &b); fftw_export_wisdom(write_char, (void *)&b); luaL_pushresult(&b); return 1; } if (lua_toboolean(L, 1)) /* forget wisdom? */ fftw_forget_wisdom(); else /* get wisdom */ fftw_import_wisdom_from_string(luaL_checkstring(L, 1)); return 0; }
void cleanup( Search_settings *sett, Command_line_opts *opts, Search_range *s_range, FFTW_plans *plans, FFTW_arrays *fftw_arr, Aux_arrays *aux, double *F) { int i; for(i=0; i<sett->nifo; i++) { free(ifo[i].sig.xDat); free(ifo[i].sig.xDatma); free(ifo[i].sig.xDatmb); free(ifo[i].sig.DetSSB); free(ifo[i].sig.aa); free(ifo[i].sig.bb); free(ifo[i].sig.shftf); free(ifo[i].sig.shft); } free(aux->sinmodf); free(aux->cosmodf); free(aux->t2); free(F); fftw_free(fftw_arr->xa); free(sett->M); fftw_destroy_plan(plans->plan); fftw_destroy_plan(plans->plan2); fftw_destroy_plan(plans->pl_int); fftw_destroy_plan(plans->pl_int2); fftw_destroy_plan(plans->pl_inv); fftw_destroy_plan(plans->pl_inv2); fftw_forget_wisdom(); fftw_cleanup(); } // end of cleanup & memory free
/* * Class: jfftw_Wisdom * Method: clear * Signature: ()V */ JNIEXPORT void JNICALL Java_jfftw_Wisdom_clear( JNIEnv * env, jclass clazz ) { fftw_forget_wisdom(); }
/** * Find the mismatches without filtering. This is the complete method in the case where * the complexity is unbounded by k, but only applies in one case in the bounded method. * @TODO: Move this elsewhere; it doesn't apply just to unbounded. Perhaps the same for the above * @param text A character array containing the text * @param pattern A character array containing the pattern * @param n the length of the text * @param m the length of the pattern * @param k The threshold, k. If k < 0 or >= m hamming distance at all * alignments will be found * @param results. An unsigned array to store the hamming distance in. Must be * of size n-m+1. If NULL, results are printed to stdout. * @param numMatches an unsigned pointer to a location to store the number * of k-mismatches found. Note that if k < 0 or >= m this is just n-m. * @param sortedPattern. An array of charAndPosition structs, that is sorted but contain * indices of original location in the pattern * @param positionLookup. An int array of indexes into the sortedPattern saying where to find * the start of infrequent characters, or NOT_IN_PATTERN or FREQUENT_CHAR. */ void findMismatchesWithoutFiltering(char *text, char *pattern, int n, int m,int k, int *numMatches,struct SP_KM_MATCHING_POSITIONS *listOfMatches,unsigned flags, struct charAndPosition *sortedPattern,struct position *positionLookup){ int i; int transformSize = 2*m; if(transformSize < 2048 && n > 4096){ transformSize = 2048; } //Use double as we will compute Fourier Transform of this double *maskedPattern = (double *)fftw_malloc(sizeof(double)*transformSize); //Zero the top "half" of the masked pattern -- this will never be touched for(i=m;i<transformSize;i++){ maskedPattern[i] = 0.0; } //Repeat for text, except we mask potential "overflow" of chunks past n int overflowed = n + (transformSize - m); double *maskedText = (double *)fftw_malloc(sizeof(double)*overflowed); for(i=n;i<overflowed;i++){ maskedText[i] = 0.0; } //We will re-use plans across multiple masked patterns, so define these here fftw_plan forward = NULL; fftw_plan inverse =NULL; if(!fftw_import_system_wisdom()){ printf("Failed to read system wisdom!\n"); } //Create an array that we will use to add matches for each character at //each alignment int *matches = (int *) calloc(n-m+1,sizeof(int)); int positionInPattern; short charType; int numFFTMatches = 0; double numInfrequentComparisons = 0.0; for(i=0;i<n;i++){ charType = positionLookup[(int)text[i]].charType; positionInPattern = positionLookup[(int)text[i]].index; if(charType==FREQUENT_CHAR){ maskTextAndPattern(text,pattern,n,m,maskedText,maskedPattern,text[i]); printf("Frequent char %c\n",text[i]); computeNumMatchesWithFFT(maskedText,maskedPattern,n,m,transformSize,matches,&forward,&inverse); numFFTMatches++; //This will compute matches for ALL of the same character in the text, so now mark this as not occuring in the pattern positionLookup[(int)text[i]].charType=NOT_IN_PATTERN; }else if(charType ==INFREQUENT_CHAR){ //printf("Infrequent char %c\n",text[i]); //Loop though all of the up to O(threshold) characters that are infrequent while(positionInPattern < m && sortedPattern[positionInPattern].index <= i && sortedPattern[positionInPattern].c == text[i]){ // printf("i-sortedPattern[positionInPattern].index+1: %d\n",i-sortedPattern[positionInPattern].index+1); // printf("i: %d\n",i); // printf("sortedPattern[positionInPattern].index: %d\n",sortedPattern[positionInPattern].index); if(i-sortedPattern[positionInPattern].index < n-m+1){ matches[i-sortedPattern[positionInPattern].index]++; } positionInPattern++; numInfrequentComparisons++; } } } //printf("Calculated %d matches using Fourier Transforms\n",numFFTMatches); //printf("Performed %d (*c) comparisons for infrequent characters\n",(int)numInfrequentComparisons); //We now have matches, so we can compute (and output if necessary) mis-matches int hamDistance; for(i=0;i<n-m+1;i++){ hamDistance = m - matches[i]; if(hamDistance <= k){ (*numMatches)++; if(listOfMatches!=NULL){ sp_km_addToListOfMatches(listOfMatches,i,hamDistance); }else{ printf("Hamming distance at text[%d]: %d\n",i,hamDistance); } if(flags & SP_KM_FIRST_MATCH_ONLY){ return; } } } done(); free(matches); fftw_free(maskedPattern); fftw_free(maskedText); fftw_destroy_plan(forward); fftw_destroy_plan(inverse); fftw_forget_wisdom(); fftw_cleanup(); }