std::vector<std::shared_ptr<Node>> CalcNodeComparison(std::vector<int> &idxs, int szGrp1) { // TODO: Probably need to make this thread safe std::vector<std::shared_ptr<Node>> nodeStats(_nodeCount); //for(int nodeIndex=0; nodeIndex<_nodeCount; nodeIndex++) con::parallel_for((size_t)0, _nodeCount, [=, &idxs, &nodeStats](int nodeIndex) { // Pull out a view of the subject values for a single edge //auto nodeValues = _nodes[nodeIndex]; TStatCalc calcDegree; TStatCalc calcStrength; // Loop through the vals we were passed for (size_t idx = 0; idx < _subjectCount; ++idx) { auto nodeVal = _nodes[nodeIndex][idxs[idx]]; double avgStrength = nodeVal->TotalStrength / _nodeCount; int grpId = 1; if (idx < szGrp1) grpId = 0; calcDegree.IncludeValue(grpId, nodeVal->Degree); calcStrength.IncludeValue(grpId, avgStrength); } auto node = std::make_shared<Node>(); node->Index = nodeIndex; node->Degree = calcDegree.Calculate(); node->Strength = calcStrength.Calculate(); nodeStats[nodeIndex] = node; }); return nodeStats; }
void printFileCache(const char *fname, unsigned &globtot, unsigned &globfs, bool verbose, bool onlykey, unsigned &totlf, unsigned &totnl) { if (onlykey&&(strstr(fname,"_of_")==NULL)) return; size_t page_index; unsigned leaves=0; unsigned nonleaves=0; int fd = open(fname,O_RDONLY); if (fd==-1) { int err = errno; if (err==ENOENT) return; printf("ERROR: open %s failed %d\n",fname,err); return; } struct stat file_stat; fstat(fd, &file_stat); if (!S_ISREG(file_stat.st_mode)) return; void * file_mmap = mmap((void *)0, file_stat.st_size, PROT_NONE, MAP_SHARED, fd, 0); page_size = getpagesize(); unsigned fs = (file_stat.st_size+page_size-1)/page_size; if (!fs) return; unsigned char *mincore_vec = (unsigned char *)calloc(1, fs); mincore(file_mmap, file_stat.st_size, mincore_vec); printf("%s:\n",fname); size_t s = 0; size_t e = (size_t)-1; unsigned tot = 0; for (size_t page_index = 0; page_index < fs; page_index++) { if (mincore_vec[page_index]&1) { if (page_index&&onlykey&&(pagetoofs(page_index)%8192==0)) nodeStats(fd,pagetoofs(page_index),leaves,nonleaves); if (e!=-1) { if (page_index!=e+1) { tot += (e-s+1); if (verbose) printf(" 0x%"I64F"x-0x%"I64F"x = %"I64F"d\n",pagetoofs(s),pagetoofs(e+1)-1,pagetoofs(e-s+1)); s = page_index; } } else s = page_index; e = page_index; } } if (e!=-1) { if (verbose) printf(" 0x%"I64F"x-0x%"I64F"x = %"I64F"d\n",pagetoofs(s),pagetoofs(e+1)-1,pagetoofs(e-s+1)); tot += (e-s+1); } if (onlykey) printf(" Cached %"I64F"d of %"I64F"d = %0.2f% NonLeaves: %u, Leaves: %u\n",pagetoofs(tot),pagetoofs(fs),(double)tot*100.0/(double)fs,nonleaves,leaves); else printf(" Cached %"I64F"d of %"I64F"d = %0.2f%\n",pagetoofs(tot),pagetoofs(fs),(double)tot*100.0/(double)fs); free(mincore_vec); munmap(file_mmap, file_stat.st_size); close(fd); globtot += tot; globfs += fs; totlf += leaves; totnl += nonleaves; }