/***************************************** * Read nappe characterization in a file * *****************************************/ GEO * file_geo_nappe (BYTE Type, FILE *File) { GEO_NAPPE *Geo; PNT *Pnt, *PntA, *PntB, *PntC, *PntD; FCT *Fct; VECTOR U, V; REAL Real; INDEX Index; INIT_MEM (Geo, 1, GEO_NAPPE); Geo->Type = Type; GET_INDEX (Geo->NbrPnt); INIT_MEM (Geo->TabPnt, Geo->NbrPnt, PNT); GET_INDEX (Geo->NbrFct); INIT_MEM (Geo->TabFct, Geo->NbrFct, FCT); Geo->Min.x = Geo->Min.y = Geo->Min.z = INFINITY; Geo->Max.x = Geo->Max.y = Geo->Max.z = -INFINITY; for (Index = 0, Pnt = Geo->TabPnt; Index < Geo->NbrPnt; Index++, Pnt++) { GET_VECTOR (Pnt->Point); VEC_MIN (Geo->Min, Pnt->Point); VEC_MAX (Geo->Max, Pnt->Point); } for (Index = 0, Fct = Geo->TabFct; Index < Geo->NbrFct; Index++, Fct++) { if (fscanf (File, " ( %d %d %d %d )", &Fct->i, &Fct->j, &Fct->k, &Fct->l) < 4) return (FALSE); Fct->NumFct = Index; PntA = Geo->TabPnt + Fct->i; PntB = Geo->TabPnt + Fct->j; PntC = Geo->TabPnt + Fct->k; PntD = Geo->TabPnt + Fct->l; VEC_SUB (U, PntC->Point, PntA->Point); VEC_SUB (V, PntD->Point, PntB->Point); VEC_CROSS (Fct->Normal, U, V); VEC_UNIT (Fct->Normal, Real); VEC_INC (PntA->Normal, Fct->Normal); VEC_INC (PntB->Normal, Fct->Normal); VEC_INC (PntC->Normal, Fct->Normal); VEC_INC (PntD->Normal, Fct->Normal); } for (Index = 0, Pnt = Geo->TabPnt; Index < Geo->NbrPnt; Index++, Pnt++) VEC_UNIT (Pnt->Normal, Real); return ((GEO *) Geo); }
int copy_strarr(void *d, char *next){ char ***sd=(char***)d; char *v; char *tmp=next; char **p; int i; int n=0; while((v=get_line_word(next,&next))){ n++; } if(n<1) return 1; INIT_MEM(p,n+1); v=tmp; for(i=0;i<n;i++){ p[i]=strdup(v); while(*(v++)); } p[n]=NULL; *sd=p; return 0; }
void* http_init(){ struct http_data *data; curl_global_init(CURL_GLOBAL_ALL); INIT_MEM(data,1); memset(data,0,sizeof(*data)); xmlproc_global_init(); return data; }
void http_fetch_init(struct urllist *ul, void *d, void *db){ struct http_data *data=(struct http_data*)d; int npara=5; struct urllist *tul; if(global_config.parallel_reload>0) data->npara=npara=global_config.parallel_reload; data->cm=curl_multi_init(); INIT_MEM(data->xh,npara); INIT_MEM(data->ce,npara); INIT_MEM(data->ula,npara); for(tul=ul;tul;tul=tul->next) tul->data.n_httperr=-1; data->anp=0; data->rnp=0; data->newentry=0; }
// calculation of every element for one tile int tile_fill(struct TileQueue *tiles) { INDEX i,j; COLOR *TileColor; INIT_MEM(TileColor, TILE_SIZE * TILE_SIZE, COLOR); struct timeval t1, t2; gettimeofday(&t1, NULL); while(!terminated){ pthread_mutex_lock(&mutex); if (!isEmpty(tiles)) { int current_tile = firstElement(tiles); pop(tiles); pthread_mutex_unlock(&mutex); if (fake) { // fake tasks usleep(-current_tile); } else { // regular tasks // assigning first and final index of tile int j_begin = rank_j(current_tile, Cj); int j_end = MIN(j_begin + TILE_SIZE, Img.Pixel.j); int i_begin = rank_i(current_tile, Ci); int i_end = MIN(i_begin + TILE_SIZE, Img.Pixel.i); for (j = j_begin; j < j_end ; j++) { for (i = i_begin ; i < i_end; i++) { TileColor [(j-j_begin) * TILE_SIZE + (i-i_begin)] = pixel_basic (i, j); } } // Sending current tile to proc 0 MPI_Send(TileColor, TILE_SIZE * TILE_SIZE, MPI_COLOR, 0, current_tile + TILE_TAG_INDEX, MPI_COMM_WORLD); } } else { pthread_mutex_unlock(&mutex); if (!vol){ terminated = 1; break; } // if vol de travail, ask for work and wait until we receive it sem_post(&ask_work); sem_wait(&wait_work); } } pthread_mutex_lock(&mutex_time); gettimeofday(&t2, NULL); local_time = MAX(local_time,(t2.tv_sec - t1.tv_sec)*1000000 + t2.tv_usec - t1.tv_usec); printf("time %ld\n",(t2.tv_sec - t1.tv_sec)*1000000 + t2.tv_usec - t1.tv_usec); pthread_mutex_unlock(&mutex_time); return 0; }
GEO * file_geo_sphere (BYTE Type, FILE *File) { GEO_SPHERE *Geo; VECTOR Vector; INIT_MEM (Geo, 1, GEO_SPHERE); Geo->Type = Type; GET_VECTOR (Geo->Point); GET_REAL (Geo->Radius); Vector.x = Vector.y = Vector.z = Geo->Radius; VEC_SUB (Geo->Min, Geo->Point, Vector); VEC_ADD (Geo->Max, Geo->Point, Vector); return ((GEO *) Geo); }
char* get_longest_prefix(char **results){ int i; int prefix=0; int test=0; char *ret=NULL; if(results && results[0]){ prefix=strlen(results[0]); for(i=1;results[i];i++){ test=common_prefix(results[0],results[i]); prefix=minimum(prefix,test); } INIT_MEM(ret,(2*prefix)+1); memcpy(ret,results[0],prefix); ret[prefix]=0; add_slashes(ret,prefix+1); } return ret; }
/* ----- function definitions ---------- */ int main ( int argc, char *argv[] ) { LALStatus status; UserInput_t uvar_s; UserInput_t *uvar = &uvar_s; INIT_MEM ( status ); INIT_MEM ( uvar_s ); struct tms buf; uvar->randSeed = times(&buf); // ---------- register all our user-variable ---------- XLALregBOOLUserStruct ( help, 'h', UVAR_HELP , "Print this help/usage message"); XLALregINTUserStruct ( randSeed, 's', UVAR_OPTIONAL, "Specify random-number seed for reproducible noise."); /* read cmdline & cfgfile */ XLAL_CHECK ( XLALUserVarReadAllInput ( argc, argv ) == XLAL_SUCCESS, XLAL_EFUNC ); if ( uvar->help ) { /* if help was requested, we're done */ exit (0); } srand ( uvar->randSeed ); REAL8 startTimeREAL8 = 714180733; REAL8 duration = 180000; /* 50 hours */ REAL8 Tsft = 1800; /* assume 30min SFTs */ char earthEphem[] = TEST_DATA_DIR "earth00-19-DE200.dat.gz"; char sunEphem[] = TEST_DATA_DIR "sun00-19-DE200.dat.gz"; //REAL8 tolerance = 2e-10; /* same algorithm, should be basically identical results */ LIGOTimeGPS startTime, refTime; XLALGPSSetREAL8 ( &startTime, startTimeREAL8 ); refTime = startTime; // pick skyposition at random ----- */ SkyPosition skypos; skypos.longitude = LAL_TWOPI * (1.0 * rand() / ( RAND_MAX + 1.0 ) ); // alpha uniform in [0, 2pi) skypos.latitude = LAL_PI_2 - acos ( 1 - 2.0 * rand()/RAND_MAX ); // sin(delta) uniform in [-1,1] skypos.system = COORDINATESYSTEM_EQUATORIAL; // pick binary orbital parameters: // somewhat inspired by Sco-X1 parameters from S2-paper (PRD76, 082001 (2007), gr-qc/0605028) // but with a more extreme eccentricity, and random argp REAL8 argp = LAL_TWOPI * (1.0 * rand() / ( RAND_MAX + 1.0 ) ); // uniform in [0, 2pi) BinaryOrbitParams orbit; XLALGPSSetREAL8 ( &orbit.tp, 731163327 ); // time of observed periapsis passage (in SSB) orbit.argp = argp; // argument of periapsis (radians) orbit.asini = 1.44; // projected, normalized orbital semi-major axis (s) */ orbit.ecc = 1e-2; // relatively large value, for better testing orbit.period = 68023; // period (s) : about ~18.9h // ----- step 0: prepare test-case input for calling the BinarySSB-functions // setup detectors const char *sites[3] = { "H1", "L1", "V1" }; UINT4 numDetectors = sizeof( sites ) / sizeof ( sites[0] ); MultiLALDetector multiIFO; multiIFO.length = numDetectors; for ( UINT4 X = 0; X < numDetectors; X ++ ) { LALDetector *det = XLALGetSiteInfo ( sites[X] ); XLAL_CHECK ( det != NULL, XLAL_EFUNC, "XLALGetSiteInfo ('%s') failed for detector X=%d\n", sites[X], X ); multiIFO.sites[X] = (*det); // struct copy XLALFree ( det ); } // load ephemeris EphemerisData *edat = XLALInitBarycenter ( earthEphem, sunEphem ); XLAL_CHECK ( edat != NULL, XLAL_EFUNC, "XLALInitBarycenter('%s','%s') failed\n", earthEphem, sunEphem ); // setup multi-timeseries MultiLIGOTimeGPSVector *multiTS; XLAL_CHECK ( (multiTS = XLALCalloc ( 1, sizeof(*multiTS))) != NULL, XLAL_ENOMEM ); XLAL_CHECK ( (multiTS->data = XLALCalloc (numDetectors, sizeof(*multiTS->data))) != NULL, XLAL_ENOMEM ); multiTS->length = numDetectors; for ( UINT4 X = 0; X < numDetectors; X ++ ) { multiTS->data[X] = XLALMakeTimestamps ( startTime, duration, Tsft, 0 ); XLAL_CHECK ( multiTS->data[X] != NULL, XLAL_EFUNC, "XLALMakeTimestamps() failed.\n"); } /* for X < numIFOs */ // generate detector-states MultiDetectorStateSeries *multiDetStates = XLALGetMultiDetectorStates ( multiTS, &multiIFO, edat, 0 ); XLAL_CHECK ( multiDetStates != NULL, XLAL_EFUNC, "XLALGetMultiDetectorStates() failed.\n"); // generate isolated-NS SSB times MultiSSBtimes *multiSSBIn = XLALGetMultiSSBtimes ( multiDetStates, skypos, refTime, SSBPREC_RELATIVISTICOPT ); XLAL_CHECK ( multiSSBIn != NULL, XLAL_EFUNC, "XLALGetMultiSSBtimes() failed.\n"); // ----- step 1: compute reference-result using old LALGetMultiBinarytimes() MultiSSBtimes *multiBinary_ref = NULL; LALGetMultiBinarytimes (&status, &(multiBinary_ref), multiSSBIn, multiDetStates, &orbit, refTime ); XLAL_CHECK ( status.statusCode == 0, XLAL_EFAILED, "LALGetMultiBinarytimes() failed with status = %d : '%s'\n", status.statusCode, status.statusDescription ); // ----- step 2: compute test-result using new XLALAddMultiBinaryTimes() MultiSSBtimes *multiBinary_test = NULL; PulsarDopplerParams doppler; memset(&doppler, 0, sizeof(doppler)); doppler.tp = orbit.tp; doppler.argp = orbit.argp; doppler.asini = orbit.asini; doppler.ecc = orbit.ecc; doppler.period = orbit.period; XLAL_CHECK ( XLALAddMultiBinaryTimes ( &multiBinary_test, multiSSBIn, &doppler ) == XLAL_SUCCESS, XLAL_EFUNC ); // ----- step 3: compare results REAL8 err_DeltaT, err_Tdot; REAL8 tolerance = 1e-10; int ret = XLALCompareMultiSSBtimes ( &err_DeltaT, &err_Tdot, multiBinary_ref, multiBinary_test ); XLAL_CHECK ( ret == XLAL_SUCCESS, XLAL_EFUNC, "XLALCompareMultiSSBtimes() failed.\n"); XLALPrintWarning ( "INFO: err(DeltaT) = %g, err(Tdot) = %g\n", err_DeltaT, err_Tdot ); XLAL_CHECK ( err_DeltaT < tolerance, XLAL_ETOL, "error(DeltaT) = %g exceeds tolerance of %g\n", err_DeltaT, tolerance ); XLAL_CHECK ( err_Tdot < tolerance, XLAL_ETOL, "error(Tdot) = %g exceeds tolerance of %g\n", err_Tdot, tolerance ); // ---- step 4: clean-up memory XLALDestroyUserVars(); XLALDestroyEphemerisData ( edat ); XLALDestroyMultiSSBtimes ( multiBinary_test ); XLALDestroyMultiSSBtimes ( multiBinary_ref ); XLALDestroyMultiSSBtimes ( multiSSBIn ); XLALDestroyMultiTimestamps ( multiTS ); XLALDestroyMultiDetectorStateSeries ( multiDetStates ); // check for memory-leaks LALCheckMemoryLeaks(); return XLAL_SUCCESS; } // main()
int main ( void ) { const char *fn = __func__; //LALStatus status = empty_status; SFTtype *mySFT; LIGOTimeGPS epoch = { 731210229, 0 }; REAL8 dFreq = 1.0 / 1800.0; REAL8 f0 = 150.0 - 2.0 * dFreq; /* init data array */ COMPLEX8 vals[] = { crectf( -1.249241e-21, 1.194085e-21 ), crectf( 2.207420e-21, 2.472366e-22 ), crectf( 1.497939e-21, 6.593609e-22 ), crectf( 3.544089e-20, -9.365807e-21 ), crectf( 1.292773e-21, -1.402466e-21 ) }; UINT4 numBins = sizeof ( vals ) / sizeof(vals[0] ); if ( (mySFT = XLALCreateSFT ( numBins )) == NULL ) { XLALPrintError ("%s: Failed to create test-SFT using XLALCreateSFT(), xlalErrno = %d\n", fn, xlalErrno ); return XLAL_EFAILED; } /* init header */ strcpy ( mySFT->name, "H1;testSFTRngmed" ); mySFT->epoch = epoch; mySFT->f0 = f0; mySFT->deltaF = dFreq; /* we simply copy over these data-values into the SFT */ UINT4 iBin; for ( iBin = 0; iBin < numBins; iBin ++ ) mySFT->data->data[iBin] = vals[iBin]; /* get memory for running-median vector */ REAL8FrequencySeries rngmed; INIT_MEM ( rngmed ); XLAL_CHECK ( (rngmed.data = XLALCreateREAL8Vector ( numBins )) != NULL, XLAL_EFUNC, "Failed XLALCreateREAL8Vector ( %d )", numBins ); // ---------- Test running-median PSD estimation in simple blocksize cases // ------------------------------------------------------------ // TEST 1: odd blocksize = 3 // ------------------------------------------------------------ UINT4 blockSize3 = 3; /* reference result for 3-bin block running-median computed in octave: octave> sft = [ \ -1.249241e-21 + 1.194085e-21i, \ 2.207420e-21 + 2.472366e-22i, \ 1.497939e-21 + 6.593609e-22i, \ 3.544089e-20 - 9.365807e-21i, \ 1.292773e-21 - 1.402466e-21i \ ]; octave> periodo = abs(sft).^2; octave> m1 = median ( periodo(1:3) ); m2 = median ( periodo(2:4) ); m3 = median ( periodo (3:5 ) ); octave> rngmed = [ m1, m1, m2, m3, m3 ]; octave> printf ("rngmedREF3 = { %.16g, %.16g, %.16g, %.16g, %.16g };\n", rngmed ); rngmedREF3[] = { 2.986442063306e-42, 2.986442063306e-42, 4.933828992779561e-42, 3.638172910684999e-42, 3.638172910684999e-42 }; */ REAL8 rngmedREF3[] = { 2.986442063306e-42, 2.986442063306e-42, 4.933828992779561e-42, 3.638172910684999e-42, 3.638172910684999e-42 }; /* compute running median */ XLAL_CHECK ( XLALSFTtoRngmed ( &rngmed, mySFT, blockSize3 ) == XLAL_SUCCESS, XLAL_EFUNC, "XLALSFTtoRngmed() failed."); /* get median->mean bias correction, needed for octave-reference results, to make * them comparable to the bias-corrected results from LALSFTtoRngmed() */ REAL8 medianBias3 = XLALRngMedBias ( blockSize3 ); XLAL_CHECK ( xlalErrno == 0, XLAL_EFUNC, "XLALRngMedBias() failed."); BOOLEAN pass = 1; const CHAR *passStr; printf ("%4s %22s %22s %8s <%g\n", "Bin", "rngmed(LAL)", "rngmed(Octave)", "relError", tol); for (iBin=0; iBin < numBins; iBin ++ ) { REAL8 rngmedVAL = rngmed.data->data[iBin]; REAL8 rngmedREF = rngmedREF3[iBin] / medianBias3; // apply median-bias correction REAL8 relErr = REL_ERR ( rngmedREF, rngmedVAL ); if ( relErr > tol ) { pass = 0; passStr = "fail"; } else { passStr = "OK."; } printf ("%4d %22.16g %22.16g %8.1g %s\n", iBin, rngmedVAL, rngmedREF, relErr, passStr ); } /* for iBin < numBins */ // ------------------------------------------------------------ // TEST 2: even blocksize = 4 // ------------------------------------------------------------ UINT4 blockSize4 = 4; /* reference result for 4-bin block running-median computed in octave: octave> m1 = median ( periodo(1:4) ); m2 = median ( periodo(2:5) ); octave> rngmed = [ m1, m1, m1, m2, m2 ]; octave> printf ("rngmedREF4[] = { %.16g, %.16g, %.16g, %.16g, %.16g };\n", rngmed ); rngmedREF4[] = { 3.96013552804278e-42, 3.96013552804278e-42, 3.96013552804278e-42, 4.28600095173228e-42, 4.28600095173228e-42 }; */ REAL8 rngmedREF4[] = { 3.96013552804278e-42, 3.96013552804278e-42, 3.96013552804278e-42, 4.28600095173228e-42, 4.28600095173228e-42 }; /* compute running median */ XLAL_CHECK ( XLALSFTtoRngmed ( &rngmed, mySFT, blockSize4 ) == XLAL_SUCCESS, XLAL_EFUNC, "XLALSFTtoRngmed() failed."); /* get median->mean bias correction, needed for octave-reference results, to make * them comparable to the bias-corrected results from LALSFTtoRngmed() */ REAL8 medianBias4 = XLALRngMedBias ( blockSize4 ); XLAL_CHECK ( xlalErrno == 0, XLAL_EFUNC, "XLALRngMedBias() failed."); printf ("%4s %22s %22s %8s <%g\n", "Bin", "rngmed(LAL)", "rngmed(Octave)", "relError", tol); for (iBin=0; iBin < numBins; iBin ++ ) { REAL8 rngmedVAL = rngmed.data->data[iBin]; REAL8 rngmedREF = rngmedREF4[iBin] / medianBias4; // apply median-bias correction REAL8 relErr = REL_ERR ( rngmedREF, rngmedVAL ); if ( relErr > tol ) { pass = 0; passStr = "fail"; } else { passStr = "OK."; } printf ("%4d %22.16g %22.16g %8.1g %s\n", iBin, rngmedVAL, rngmedREF, relErr, passStr ); } /* for iBin < numBins */ /* free memory */ XLALDestroyREAL8Vector ( rngmed.data ); XLALDestroySFT ( mySFT ); LALCheckMemoryLeaks(); if ( !pass ) { printf ("Test failed! Difference exceeded tolerance.\n"); return XLAL_EFAILED; } else { printf ("Test passed.\n"); return XLAL_SUCCESS; } } /* main() */
void img (const char *FileNameImg) { FILE *FileImg; COLOR *TabColor, *Color, *TileColor; STRING Name; INDEX i, j, rank; BYTE Byte; int N = 18988, err, provided; int next_proc; MPI_Request rs; MPI_Status status; MPI_Init_thread(NULL, NULL, MPI_THREAD_MULTIPLE, &provided); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &P); next_proc = (rank + 1) % P; if (next_proc == 0) next_proc++; P--; MPI_Type_vector(1, 3, 0, MPI_FLOAT, &MPI_COLOR); MPI_Type_commit(&MPI_COLOR); if (rank == 0) { strcpy (Name, FileNameImg); strcat (Name, ".ppm"); INIT_FILE (FileImg, Name, "w"); fprintf (FileImg, "P6\n%d %d\n255\n", Img.Pixel.i, Img.Pixel.j); } // number of tiles Ci = Img.Pixel.i / TILE_SIZE + (Img.Pixel.i % TILE_SIZE?1:0); // number of tiles in dimension i Cj = Img.Pixel.j / TILE_SIZE + (Img.Pixel.i % TILE_SIZE?1:0); // number of tiles in dimension j int C = Ci * Cj; int q = (C+P-1)/P; int size = Img.Pixel.i * Img.Pixel.j ; N = C/2+1; // buffer for each tile INIT_MEM (TileColor, TILE_SIZE * TILE_SIZE, COLOR); if (rank != 0) { struct TileQueue tiles = {NULL, NULL}; // Init tasks init(&tiles,rank,q,N,C); // Init mutex, semaphores & threads pthread_mutex_init(&mutex,NULL); pthread_mutex_init(&mutex_time,NULL); sem_init(&wait_work, 0, 0); sem_init(&ask_work, 0, 0); pthread_t tid[NB_THREADS]; for (i = 0; i < NB_THREADS; i++){ err = pthread_create(&(tid[i]), NULL, (void*)tile_fill, (void*)&tiles); if (err != 0) printf("\ncan't create thread :[%s]", strerror(err)); } // vol de travail ? if (vol){ // Main thread: Communicator while (!terminated) { int flag = 0, msg; MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, &status); if (flag) { // We DID receive a communication so we CAN do a blocking receive MPI_Recv(&msg, 1, MPI_INT, status.MPI_SOURCE, status.MPI_TAG, MPI_COMM_WORLD, &status); // TAG contains the information about what the message is switch (status.MPI_TAG){ case TERMINATE: // No more jobs; threads can finish their jobs and return MPI_Isend(&msg, 1, MPI_INT, next_proc, TERMINATE, MPI_COMM_WORLD, &rs); terminated = 1; break; case WORK_ASK: // msg-th process is seeking for job pthread_mutex_lock(&mutex); if(!isEmpty(&tiles)){ int tile = firstElement(&tiles); pop(&tiles); pthread_mutex_unlock(&mutex); MPI_Isend(&tile, 1, MPI_INT, msg, WORK_SEND, MPI_COMM_WORLD, &rs); } else { pthread_mutex_unlock(&mutex); if (msg == rank){ MPI_Isend(&msg, 1, MPI_INT, next_proc, TERMINATE, MPI_COMM_WORLD, &rs); terminated = 1; } else { MPI_Isend(&msg, 1, MPI_INT, next_proc, WORK_ASK, MPI_COMM_WORLD, &rs); } } break; case WORK_SEND: // Received a job pthread_mutex_lock(&mutex); addTile(&tiles, msg); pthread_mutex_unlock(&mutex); sem_post(&wait_work); break; default: fprintf(stderr, "Err: Unknown message: %d, with tag %d\n", msg,status.MPI_TAG); break; } } if (sem_trywait(&ask_work) == 0){ MPI_Isend(&rank, 1, MPI_INT, next_proc, WORK_ASK, MPI_COMM_WORLD, &rs); } } for (i = 0; i < NB_THREADS; i++){ sem_post(&wait_work); } } for (i = 0; i < NB_THREADS; i++){ pthread_join(tid[i],NULL); } pthread_mutex_destroy(&mutex); pthread_mutex_destroy(&mutex_time); sem_destroy(&wait_work); sem_destroy(&ask_work); fprintf(stderr, "%d %ld\n", rank, local_time); } // process 0 gathers all the tiles if (rank == 0){ // If fake tasks: we don't receive anything and don't write the image FILE* fd = fopen("config","r"); if (fd != NULL){ int fake; fscanf(fd,"%d\n",&fake); if (fake){ EXIT_FILE(FileImg); EXIT_MEM(TileColor); MPI_Finalize(); return; } } // final image buffer that will receive the tiles INIT_MEM (TabColor, size, COLOR); // Receive tiles from other procs for (i = 0; i < C ; i++){ MPI_Recv(TileColor, TILE_SIZE * TILE_SIZE, MPI_COLOR, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status); int current_tile = status.MPI_TAG - TILE_TAG_INDEX; int j_begin = rank_j(current_tile,Cj); int index_begin = rank_i(current_tile,Ci) + j_begin * Img.Pixel.i; for (j = 0; j < TILE_SIZE && j_begin + j < Img.Pixel.j; j++) { memcpy(&TabColor[index_begin + j * Img.Pixel.i],&TileColor[j * TILE_SIZE],MIN(Img.Pixel.i - rank_i(current_tile,Ci),TILE_SIZE) * sizeof(COLOR)); } } // writing in file for (j = 0, Color = TabColor; j < size; j++, Color++) { Byte = Color->r < 1.0 ? 255.0*Color->r : 255.0; putc (Byte, FileImg); Byte = Color->g < 1.0 ? 255.0*Color->g : 255.0; putc (Byte, FileImg); Byte = Color->b < 1.0 ? 255.0*Color->b : 255.0; putc (Byte, FileImg); } EXIT_FILE (FileImg); printf("Copied in file\n"); EXIT_MEM (TabColor); } EXIT_MEM (TileColor); MPI_Finalize(); }
ngramlist_t* process(sentencelist_t *wordtok, int n) { int i, j, k, js, len, ngsize, endi; int *sen_len; wordlist_t *p, *q, *nw; ngram_t *ng, *tmp, **sorted; ngramlist_t *ngl; wordlist_t *words; if (n<1) return NULL; INIT_MEM(sen_len,wordtok->filled); INIT_MEM(ngl,1); ngl->ngsize = 0; len = 0; for(i=0;i<wordtok->filled;i++){ sen_len[i] = 0; p = wordtok->words[i]; while (p){ sen_len[i]++; p = p->next; } sen_len[i] -= n-1; if(sen_len[i]<0) sen_len[i]=0; len += sen_len[i]; } if (len<1) return NULL; // Hope this doesn't crash lol INIT_MEM(ng,len); ng->count = 0; INIT_MEM(tmp,len); INIT_MEM(sorted,len); endi=0; i=0; for(j=0;j<wordtok->filled;j++){ if(sen_len[j]<1) continue; /* Add the final ngram to the start of tmp, no nextwords, words stored end:start */ nw = q = p = wordtok->words[j]; tmp[i].tok = get_token(p,n); tmp[i].words = NULL; for (k = 0;k<n;k++){ add_node(tmp[i].words); tmp[i].words->word = q->word; q = q->next; } tmp[i].nextword = NULL; #ifdef NEXTWORDS add_node(tmp[i].nextword); tmp[i].nextword->word.word = NULL; tmp[i].nextword->word.count = 1; #endif sorted[endi] = tmp+i; /* Add the remaining ngrams iteratively */ i = endi+1; endi += sen_len[j]; for (;i<endi;i++){ q = p = nw->next; tmp[i].tok = get_token(p,n); tmp[i].words = NULL; for (k = 0;k<n;k++){ add_node(tmp[i].words); tmp[i].words->word = q->word; q = q->next; } tmp[i].nextword = NULL; #ifdef NEXTWORDS add_node(tmp[i].nextword); tmp[i].nextword->word.word = nw->word; tmp[i].nextword->word.count = 1; #endif sorted[i] = tmp+i; nw = nw->next; } } qsort(sorted,len,sizeof(*sorted),cmp_ngram); ngsize = 0; for (i = 0;i<len;i = j) { js = i; for (j = i+1;j<len && sorted[j]->tok == sorted[i]->tok;j++){ #ifdef NEXTWORDS if ((sorted[js]->nextword->word.word != NULL && sorted[j]->nextword->word.word != NULL && sorted[j]->nextword->word.word->tok == sorted[js]->nextword->word.word->tok) || /* same string, or... */ sorted[j]->nextword->word.word == sorted[js]->nextword->word.word) /* both NULLs (sentence ends) */ sorted[js]->nextword->word.count++; else { add_node(sorted[js]->nextword); sorted[js]->nextword->word.count = 1; sorted[js]->nextword->word.word = sorted[j]->nextword->word.word; } free_list(sorted[j]->nextword); #endif free_list(sorted[j]->words); } #ifdef NEXTWORDS //if (j == i+1) //sorted[i]->nextword->word.count = 1; #endif ng[ngsize].count = j-i; ng[ngsize].words = sorted[i]->words; ng[ngsize].nextword = sorted[i]->nextword; ng[ngsize].tok = sorted[i]->tok; ngsize++; } free(sen_len); free(sorted); free(tmp); ngl->ng = ng; ngl->ngsize = ngsize; ngl->n = n; return ngl; }
char* complete(char *s, int len, int flags){ char *search; char **results; char *ret=NULL; char **paths; char *path; int i; int newlen; int path_len=0; if(flags&COMPLETE_COM){ char *t; path=get_variable("PATH"); path_len=strlen(path); INIT_MEM(t,path_len+3); strcpy(t,".:"); strcpy(t+2,path); path=t; paths=split_colons(t); for(i=0;paths[i];i++){ newlen=strlen(paths[i]); path_len=maximum(newlen,path_len); } path_len++; } INIT_MEM(search,path_len+len+2); memcpy(search,s,len); newlen=strip_quotes(search,len); search[newlen]='*'; search[newlen+1]=0; if(flags&COMPLETE_COM){ char *base=search; for(i=0;paths[i];i++){ path_len=strlen(paths[i]); memmove(search+path_len+1,base,newlen+2); search[path_len]='/'; base=search+path_len+1; memcpy(search,paths[i],path_len); results=simple_glob(search,GLOB_MARK); ret=get_longest_prefix(results); if(ret){ base=strdup(ret+(base-search)); free(ret); ret=base; break; } } } if(!ret && flags&COMPLETE_FILE){ results=simple_glob(search,GLOB_TILDE|GLOB_NOCHECK|GLOB_MARK); ret=get_longest_prefix(results); } free(search); for(i=0;results[i];i++)free(results[i]); free(results); return ret; }