From 2e86120f7bb835d19591b44cbd2e333a44b83acf Mon Sep 17 00:00:00 2001 From: Shahzad Malik Muzaffar Date: Thu, 3 Oct 2024 09:26:22 +0200 Subject: [PATCH] [CORE] Applying code checks/format --- .../test/tclass_methods_threaded_t.cc | 90 +++++++++---------- FWCore/ROOTTests/test/tformula_threaded_t.cc | 72 +++++++-------- FWCore/ROOTTests/test/tprofile_threaded_t.cc | 65 +++++++------- FWCore/ROOTTests/test/write_threaded_t.cc | 88 +++++++++--------- .../test/google-benchmark-pass-argv.cpp | 5 +- .../bin/bloom_filter_generator.c | 84 +++++++++-------- Validation/Performance/bin/SparseCompRow.c | 50 +++++------ 7 files changed, 213 insertions(+), 241 deletions(-) diff --git a/FWCore/ROOTTests/test/tclass_methods_threaded_t.cc b/FWCore/ROOTTests/test/tclass_methods_threaded_t.cc index db7ab6f717e5a..68e9e4385d1a9 100644 --- a/FWCore/ROOTTests/test/tclass_methods_threaded_t.cc +++ b/FWCore/ROOTTests/test/tclass_methods_threaded_t.cc @@ -8,74 +8,74 @@ #include #include -void printHelp(const char* iName, int iDefaultNThreads) -{ - std::cout << iName <<" [number of threads] \n\n" - <<"If no arguments are given "< 2) { - printHelp(argv[0],kDefaultNThreads); + } + + if (argc > 2) { + printHelp(argv[0], kDefaultNThreads); exit(1); } - return returnValue ; + return returnValue; } -int main(int argc, char** argv) -{ - const int kNThreads = parseOptionsForNumberOfThreads(argc,argv); - +int main(int argc, char** argv) { + const int kNThreads = parseOptionsForNumberOfThreads(argc, argv); + std::atomic canStart{false}; std::vector threads; - + std::atomic classWasGotten{0}; std::atomic firstMethodGotten{0}; - + TThread::Initialize(); //When threading, also have to keep ROOT from logging all TObjects into a list TObject::SetObjectStat(false); //Have to avoid having Streamers modify themselves after they have been used TVirtualStreamerInfo::Optimize(false); - - - for(int i=0; iGetMethodWithPrototype("id","",true /*is const*/, ROOT::kConversionMatch); - --firstMethodGotten; - while(firstMethodGotten !=0) {} - TMethod* method2 = thingClass->GetMethodWithPrototype("operator=","edmtest::Simple const&",false /*is const*/, ROOT::kConversionMatch); - - assert(nullptr != method); - assert(nullptr != method2); - }); + + for (int i = 0; i < kNThreads; ++i) { + threads.emplace_back([&canStart, &classWasGotten, &firstMethodGotten]() { + static thread_local TThread guard; + ++classWasGotten; + ++firstMethodGotten; + while (not canStart) { + } + auto thingClass = TClass::GetClass("edmtest::Simple"); + --classWasGotten; + while (classWasGotten != 0) { + } + + TMethod* method = thingClass->GetMethodWithPrototype("id", "", true /*is const*/, ROOT::kConversionMatch); + --firstMethodGotten; + while (firstMethodGotten != 0) { + } + TMethod* method2 = thingClass->GetMethodWithPrototype( + "operator=", "edmtest::Simple const&", false /*is const*/, ROOT::kConversionMatch); + + assert(nullptr != method); + assert(nullptr != method2); + }); } canStart = true; - - for(auto& thread: threads) { + + for (auto& thread : threads) { thread.join(); } - + return 0; } diff --git a/FWCore/ROOTTests/test/tformula_threaded_t.cc b/FWCore/ROOTTests/test/tformula_threaded_t.cc index 639ffde66eeda..8551c4d227186 100644 --- a/FWCore/ROOTTests/test/tformula_threaded_t.cc +++ b/FWCore/ROOTTests/test/tformula_threaded_t.cc @@ -8,67 +8,63 @@ #include #include - -void printHelp(const char* iName, int iDefaultNThreads) -{ - std::cout << iName <<" [number of threads] \n\n" - <<"If no arguments are given "< 2) { - printHelp(argv[0],kDefaultNThreads); + } + + if (argc > 2) { + printHelp(argv[0], kDefaultNThreads); exit(1); } - return returnValue ; + return returnValue; } -int main(int argc, char** argv) -{ +int main(int argc, char** argv) { const int kNThreads = parseOptionsForNumberOfThreads(argc, argv); std::atomic canStart{kNThreads}; std::vector threads; - + TThread::Initialize(); //When threading, also have to keep ROOT from logging all TObjects into a list TObject::SetObjectStat(false); - + //Have to avoid having Streamers modify themselves after they have been used TVirtualStreamerInfo::Optimize(false); - - - for(int i=0; i 0 ) {} - - TFormula f("testFormula","1./(1.+(4.61587e+06*(((1./(0.5*TMath::Max(1.e-6,x+1.)))-1.)/1.16042e+07)))"); - - for(int i=0; i<100;++i) { - double x = double(i)/100.; - f.Eval(x); - } - }); + static thread_local TThread guard; + --canStart; + while (canStart > 0) { + } + + TFormula f("testFormula", "1./(1.+(4.61587e+06*(((1./(0.5*TMath::Max(1.e-6,x+1.)))-1.)/1.16042e+07)))"); + + for (int i = 0; i < 100; ++i) { + double x = double(i) / 100.; + f.Eval(x); + } + }); } canStart = true; - - for(auto& thread: threads) { + + for (auto& thread : threads) { thread.join(); } - + return 0; } diff --git a/FWCore/ROOTTests/test/tprofile_threaded_t.cc b/FWCore/ROOTTests/test/tprofile_threaded_t.cc index 3038ac2fd980f..dd41b71fb0439 100644 --- a/FWCore/ROOTTests/test/tprofile_threaded_t.cc +++ b/FWCore/ROOTTests/test/tprofile_threaded_t.cc @@ -9,70 +9,67 @@ #include #include -void printHelp(const char* iName, int iDefaultNThreads) -{ - std::cout << iName <<" [number of threads] \n\n" - <<"If no arguments are given "< 2) { - printHelp(argv[0],kDefaultNThreads); + } + + if (argc > 2) { + printHelp(argv[0], kDefaultNThreads); exit(1); } - return returnValue ; + return returnValue; } -int main(int argc, char** argv) -{ +int main(int argc, char** argv) { const int kNThreads = parseOptionsForNumberOfThreads(argc, argv); std::atomic canStart{false}; std::vector> profiles; std::vector threads; - + TH1::AddDirectory(kFALSE); - + TThread::Initialize(); //When threading, also have to keep ROOT from logging all TObjects into a list TObject::SetObjectStat(false); - + //Have to avoid having Streamers modify themselves after they have been used TVirtualStreamerInfo::Optimize(false); - - for(int i=0; i(s.str().c_str(),s.str().c_str(), 100,10,11,0,10)); + profiles.push_back(std::make_unique(s.str().c_str(), s.str().c_str(), 100, 10, 11, 0, 10)); profiles.back()->SetCanExtend(TH1::kAllAxes); auto profile = profiles.back().get(); - threads.emplace_back([profile,&canStart]() { - static thread_local TThread guard; - while(not canStart) {} - for(int x=10; x>0; --x) { - for(int y=0; y<20; ++y) { - profile->Fill(double(x), double(y),1.); - } + threads.emplace_back([profile, &canStart]() { + static thread_local TThread guard; + while (not canStart) { + } + for (int x = 10; x > 0; --x) { + for (int y = 0; y < 20; ++y) { + profile->Fill(double(x), double(y), 1.); } - }); + } + }); } canStart = true; - for(auto& thread: threads) { + for (auto& thread : threads) { thread.join(); } - + return 0; } diff --git a/FWCore/ROOTTests/test/write_threaded_t.cc b/FWCore/ROOTTests/test/write_threaded_t.cc index 0fc5454f71a62..7d29674f006fa 100644 --- a/FWCore/ROOTTests/test/write_threaded_t.cc +++ b/FWCore/ROOTTests/test/write_threaded_t.cc @@ -9,7 +9,6 @@ #include "TObjString.h" #include "TH1F.h" - #include #include #include @@ -20,43 +19,41 @@ std::atomic waitToStart{true}; std::atomic countdownToWrite{0}; -void printHelp(const char* iName, int iDefaultNThreads) -{ - std::cout << iName <<" [number of threads] [gDebug value]\n\n" - <<"[number of threads] number of threads to use in test\n" - <<"[gDebug value] value of gDebug to pass to ROOT (gDebug=1 is useful)\n" - <<"If no arguments are given "< parseOptionsForNumberOfThreadsAndgDebug(int argc, char** argv) -{ +std::pair parseOptionsForNumberOfThreadsAndgDebug(int argc, char** argv) { constexpr int kDefaultNThreads = 4; int kDefaultgDebug = gDebug; int nThreads = kDefaultNThreads; int newGDebug = kDefaultgDebug; - if( argc >= 2 ) { - if(strcmp("-h",argv[1]) ==0) { - printHelp(argv[0],kDefaultNThreads); - exit( 0 ); + if (argc >= 2) { + if (strcmp("-h", argv[1]) == 0) { + printHelp(argv[0], kDefaultNThreads); + exit(0); } - + nThreads = atoi(argv[1]); } - if(argc == 3) { + if (argc == 3) { newGDebug = atoi(argv[2]); } - - if( argc > 3) { - printHelp(argv[0],kDefaultNThreads); + + if (argc > 3) { + printHelp(argv[0], kDefaultNThreads); exit(1); } - return std::make_pair(nThreads, newGDebug) ; + return std::make_pair(nThreads, newGDebug); } TList* createList() { auto returnValue = new TList(); - for(unsigned int i=0; i<10;++i) { + for (unsigned int i = 0; i < 10; ++i) { returnValue->Add(new TList()); returnValue->Add(new TMap()); returnValue->Add(new TObjString()); @@ -68,8 +65,7 @@ TList* createList() { } int main(int argc, char** argv) { - - auto values = parseOptionsForNumberOfThreadsAndgDebug(argc,argv); + auto values = parseOptionsForNumberOfThreadsAndgDebug(argc, argv); const int kNThreads = values.first; countdownToWrite = kNThreads; @@ -83,44 +79,40 @@ int main(int argc, char** argv) { //Have to avoid having Streamers modify themselves after they have been used TVirtualStreamerInfo::Optimize(false); - - std::vector> threads; threads.reserve(kNThreads); - + for (int i = 0; i < kNThreads; ++i) { + threads.push_back(std::make_shared(std::thread([i]() { + static thread_local TThread s_thread_guard; - for(int i=0; i< kNThreads; ++i) { - threads.push_back(std::make_shared( std::thread([i]() { - static thread_local TThread s_thread_guard; + std::stringstream nameStream; + nameStream << "write_thread_" << i << ".root"; - std::stringstream nameStream; - nameStream <<"write_thread_"<Branch("theList","TList",&theList); + auto listTree = new TTree("TheList", "TheList"); + listTree->Branch("theList", "TList", &theList); - --countdownToWrite; - while(countdownToWrite !=0) ; + --countdownToWrite; + while (countdownToWrite != 0) + ; - for(unsigned int i = 0; i<100;++i) { - listTree->Fill(); - } - f.Write(); - f.Close(); - }) ) ); - - } + for (unsigned int i = 0; i < 100; ++i) { + listTree->Fill(); + } + f.Write(); + f.Close(); + }))); + } waitToStart = false; - for(auto& t : threads) { + for (auto& t : threads) { t->join(); } return 0; } - diff --git a/Utilities/General/test/google-benchmark-pass-argv.cpp b/Utilities/General/test/google-benchmark-pass-argv.cpp index e8b2828db478c..530eaa8e30582 100644 --- a/Utilities/General/test/google-benchmark-pass-argv.cpp +++ b/Utilities/General/test/google-benchmark-pass-argv.cpp @@ -6,9 +6,8 @@ static void BM_memcpy(benchmark::State& state) { memset(src, 'x', state.range(0)); for (auto _ : state) memcpy(dst, src, state.range(0)); - state.SetBytesProcessed(int64_t(state.iterations()) * - int64_t(state.range(0))); + state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(state.range(0))); delete[] src; delete[] dst; } -BENCHMARK(BM_memcpy)->Arg(8)->Arg(64)->Arg(512)->Arg(1<<10)->Arg(8<<10); +BENCHMARK(BM_memcpy)->Arg(8)->Arg(64)->Arg(512)->Arg(1 << 10)->Arg(8 << 10); diff --git a/Utilities/StaticAnalyzers/bin/bloom_filter_generator.c b/Utilities/StaticAnalyzers/bin/bloom_filter_generator.c index 34d36ae2e2804..e4559169befb1 100644 --- a/Utilities/StaticAnalyzers/bin/bloom_filter_generator.c +++ b/Utilities/StaticAnalyzers/bin/bloom_filter_generator.c @@ -10,54 +10,50 @@ #define CAPACITY 5000 #define ERROR_RATE 0.0002 -static void chomp_line(char *word) -{ - char *p; - if ((p = strchr(word, '\r'))) { - *p = '\0'; - } - if ((p = strchr(word, '\n'))) { - *p = '\0'; - } +static void chomp_line(char *word) { + char *p; + if ((p = strchr(word, '\r'))) { + *p = '\0'; + } + if ((p = strchr(word, '\n'))) { + *p = '\0'; + } } -int generate_bloom_filter(const char *bloom_file, const char *words_file) -{ - FILE *fp; - char word[1024]; - scaling_bloom_t *bloom; - int i; - - if (!(bloom = new_scaling_bloom(CAPACITY, ERROR_RATE, bloom_file))) { - fprintf(stderr, "ERROR: Could not create bloom filter\n"); - return EXIT_FAILURE; - } - - if (!(fp = fopen(words_file, "r"))) { - fprintf(stderr, "ERROR: Could not open words file\n"); - return EXIT_FAILURE; - } - - for (i = 0; fgets(word, sizeof(word), fp); i++) { - chomp_line(word); - scaling_bloom_add(bloom, word, strlen(word), i); - } - - int result = bitmap_flush(bloom->bitmap); - - return result; +int generate_bloom_filter(const char *bloom_file, const char *words_file) { + FILE *fp; + char word[1024]; + scaling_bloom_t *bloom; + int i; + + if (!(bloom = new_scaling_bloom(CAPACITY, ERROR_RATE, bloom_file))) { + fprintf(stderr, "ERROR: Could not create bloom filter\n"); + return EXIT_FAILURE; + } + + if (!(fp = fopen(words_file, "r"))) { + fprintf(stderr, "ERROR: Could not open words file\n"); + return EXIT_FAILURE; + } + + for (i = 0; fgets(word, sizeof(word), fp); i++) { + chomp_line(word); + scaling_bloom_add(bloom, word, strlen(word), i); + } + + int result = bitmap_flush(bloom->bitmap); + + return result; } +int main(int argc, char *argv[]) { + printf("** dablooms version: %s\n", dablooms_version()); -int main(int argc, char *argv[]) -{ - printf("** dablooms version: %s\n", dablooms_version()); - - if (argc != 3) { - fprintf(stderr, "Usage: %s \n", argv[0]); - return EXIT_FAILURE; - } + if (argc != 3) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return EXIT_FAILURE; + } - int result = generate_bloom_filter(argv[1], argv[2]); - return result; + int result = generate_bloom_filter(argv[1], argv[2]); + return result; } diff --git a/Validation/Performance/bin/SparseCompRow.c b/Validation/Performance/bin/SparseCompRow.c index c7e0dcc2bffce..ee2194e8b2a4c 100644 --- a/Validation/Performance/bin/SparseCompRow.c +++ b/Validation/Performance/bin/SparseCompRow.c @@ -1,17 +1,15 @@ - /* multiple iterations used to make kernel have roughly +/* multiple iterations used to make kernel have roughly same granulairty as other Scimark kernels. */ - double SparseCompRow_num_flops(int N, int nz, int num_iterations) - { - /* Note that if nz does not divide N evenly, then the +double SparseCompRow_num_flops(int N, int nz, int num_iterations) { + /* Note that if nz does not divide N evenly, then the actual number of nonzeros used is adjusted slightly. */ - int actual_nz = (nz/N) * N; - return ((double)actual_nz) * 2.0 * ((double) num_iterations); - } - + int actual_nz = (nz / N) * N; + return ((double)actual_nz) * 2.0 * ((double)num_iterations); +} - /* computes a matrix-vector multiply with a sparse matrix +/* computes a matrix-vector multiply with a sparse matrix held in compress-row format. If the size of the matrix in MxN with nz nonzeros, then the val[] is the nz nonzeros, with its ith entry in column col[i]. The integer vector row[] @@ -19,25 +17,19 @@ ith row in col[]. */ - void SparseCompRow_matmult( int M, double *y, double *val, int *row, - int *col, double *x, int NUM_ITERATIONS) - { - int reps; - int r; - int i; +void SparseCompRow_matmult(int M, double *y, double *val, int *row, int *col, double *x, int NUM_ITERATIONS) { + int reps; + int r; + int i; - for (reps=0; reps