int read_list(char *basepath, const char *filename) { size_t len = 0; FILE *f = NULL; char * line = NULL; int confLidas, revsLidas, confsRej, revsRej; confLidas = 0; revsLidas = 0; confsRej = 0; revsRej = 0; int naut = 0; char *absolute = NULL; absolute = (char *) malloc(sizeof (char) *(strlen(basepath) + strlen(filename))); strcat(absolute, basepath); strcat(absolute, filename); initTA(); f = fopen(absolute, "r"); if (f != NULL) { line = (char *) calloc(MAX_CHAR, sizeof (char)); line = fgets(line, MAX_CHAR, f); min_pag = atoi(line); do { line = (char *) calloc(MAX_CHAR, sizeof (char)); line = fgets(line, MAX_CHAR, f); if (line != NULL) { len = strlen(line); if (line[len - 1] == '\n') line[len - 1] = '\0'; absolute = (char *) malloc(sizeof (char) * (strlen(basepath) + len)); clear_str(absolute, strlen(basepath) + len); strcat(absolute, basepath); strcat(absolute, line); if (line[0] == 'c') confLidas += readC(absolute, &confsRej); if (line[0] == 'j') revsLidas += readJ(absolute, &revsRej); } } while (line != NULL && line != "" && !feof(f)); fclose(f); } if (absolute != NULL) { free(absolute); absolute = NULL; } free(line); logStats(confLidas, revsLidas, confsRej, revsRej); return 0; }
virtual void close() { listening_ = false; is_open_ = false; logStats(); Logger::STDOUT("NetworkListener > Packets produced = " + std::to_string(shared_buffer_->getNumPacketsProcessed())); Logger::STDOUT("NetworkListener > Closed."); }
/* At some point, we will want to use the FullPath argument and pass it along to * buildGraphFromPaths. Until then, however, we're only going to build the most * minimal graph possible. */ static void logResult(NodeVecVec *storage, NodePtrVec *result, SearchOptions *options) { NodePtrVec *tips = NodePtrVec_new(2); if ( !storage || !result || !tips ) return; /* We log the stats here, because the storage method below may not hold * the entire path. */ if ( !options->multiThreaded && options->doStatistics ) /* statistics are not thread-safe yet */ logStats(result); /* Ultimately we may want to log more than the ends... */ /* Future: if ( options->buildType == endNodesOnly ) { */ NodePtrVec_push(tips, result->vector[0]); NodePtrVec_push(tips, result->vector[result->contentSize-1]); if ( !NodeVecVec_insert(storage, tips) ) /* makes a copy of tips, so we need to... */ { printf("CrashAndBURN!!!\n\n"); fflush(stdout); } NodePtrVec_delete(tips); /* ... free the mallocs! */ }
void Collapser::collapse() { int numStreams = mStreams.size(); unsigned int lCurrent = 0; // first create an interleaved version of geometry // to compare vertices in one memcmp call // char *interleaved = (char*) malloc( mVertexSize * mNumVertices ); char *ptr = interleaved; for ( lCurrent = 0; lCurrent < mNumVertices; lCurrent++ ) { for ( int streamIndex = 0; streamIndex < numStreams; streamIndex++ ) { unsigned int csize = mStreams[streamIndex]->csize; memcpy( ptr, &mStreams[streamIndex]->bytes[lCurrent*csize], csize ); ptr += csize; } } // hash and split vertices into bucket // for faster compare/collapse // int ** buckets; hash *hashList = new hash[ mNumVertices ]; unsigned int *bucketCounts = new unsigned int[ NBUCKETS ]; memset( bucketCounts, 0, NBUCKETS * sizeof(unsigned int) ); // hash all vertices, store hashes and count vertices per buckets // for ( lCurrent = 0; lCurrent < mNumVertices; lCurrent++ ) { hash vHash = hashVertex( (char*) &interleaved[lCurrent * mVertexSize], mVertexSize ); vHash = vHash % NBUCKETS; hashList[lCurrent] = vHash; bucketCounts[vHash] ++; } // allocate buckets // buckets = (int **) malloc( NBUCKETS * sizeof(void *) ); for( hash i = 0; i < NBUCKETS; i++ ) { buckets[i] = new int[ bucketCounts[i] ]; } // for each buckets, create le list of corresponding vertex indices // memset( bucketCounts, 0, NBUCKETS * sizeof(unsigned int) ); for ( lCurrent = 0; lCurrent < mNumVertices; lCurrent++ ) { hash vHash = hashList[lCurrent]; buckets[vHash][ bucketCounts[vHash] ] = lCurrent; bucketCounts[vHash] ++; } // collapse each buckets // int bPerThreads = NBUCKETS / MAX_THREADS; pthread_t threads[MAX_THREADS]; COLLAPSE_PARAM* cParams = (COLLAPSE_PARAM*) malloc( MAX_THREADS * sizeof(COLLAPSE_PARAM)); for ( int i = 0; i < MAX_THREADS; i++ ) { cParams[i].buckets = buckets; cParams[i].bucketCounts = bucketCounts; cParams[i].boffset = i*bPerThreads; cParams[i].bcount = bPerThreads; cParams[i].interleaved = interleaved; cParams[i].mVertexSize = mVertexSize; cParams[i].mRemapTable = mRemapTable; int rc = pthread_create(&threads[i], NULL, collapseBucket, (void *) &cParams[i]); assert(0 == rc); } for (int i=0; i<MAX_THREADS; ++i) { // block until thread i completes int rc = pthread_join(threads[i], NULL); assert(0 == rc); } // free memory for( int i = 0; i < NBUCKETS; i++ ) { delete buckets[i]; } delete buckets; delete bucketCounts; delete hashList; // calculate new length // ===================== mCollapsedNumVertices = 0; for (int i = 0; i < mNumVertices; i++) { if( mRemapTable[i] == i ) mCollapsedNumVertices++; } // remap indices // ============= remap(); logStats(); }