Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CORE] Applying code checks/format #46209

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 45 additions & 45 deletions FWCore/ROOTTests/test/tclass_methods_threaded_t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,74 +8,74 @@
#include <cassert>
#include <iostream>

void printHelp(const char* iName, int iDefaultNThreads)
{
std::cout << iName <<" [number of threads] \n\n"
<<"If no arguments are given "<<iDefaultNThreads<<" threads will be used"<<std::endl;
void printHelp(const char* iName, int iDefaultNThreads) {
std::cout << iName << " [number of threads] \n\n"
<< "If no arguments are given " << iDefaultNThreads << " threads will be used" << std::endl;
}

int parseOptionsForNumberOfThreads(int argc, char** argv)
{
int parseOptionsForNumberOfThreads(int argc, char** argv) {
constexpr int kDefaultNThreads = 4;
int returnValue = kDefaultNThreads;
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);
}

returnValue = atoi(argv[1]);
}
if( argc > 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<bool> canStart{false};
std::vector<std::thread> threads;

std::atomic<int> classWasGotten{0};
std::atomic<int> 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; 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);
});

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;
}
72 changes: 34 additions & 38 deletions FWCore/ROOTTests/test/tformula_threaded_t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,67 +8,63 @@
#include <cassert>
#include <iostream>


void printHelp(const char* iName, int iDefaultNThreads)
{
std::cout << iName <<" [number of threads] \n\n"
<<"If no arguments are given "<<iDefaultNThreads<<" threads will be used"<<std::endl;
void printHelp(const char* iName, int iDefaultNThreads) {
std::cout << iName << " [number of threads] \n\n"
<< "If no arguments are given " << iDefaultNThreads << " threads will be used" << std::endl;
}

int parseOptionsForNumberOfThreads(int argc, char** argv)
{
int parseOptionsForNumberOfThreads(int argc, char** argv) {
constexpr int kDefaultNThreads = 4;
int returnValue = kDefaultNThreads;
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);
}

returnValue = atoi(argv[1]);
}
if( argc > 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<int> canStart{kNThreads};
std::vector<std::thread> 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<kNThreads; ++i) {

for (int i = 0; i < kNThreads; ++i) {
threads.emplace_back([&canStart]() {
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);
}
});
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;
}
65 changes: 31 additions & 34 deletions FWCore/ROOTTests/test/tprofile_threaded_t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,70 +9,67 @@
#include <sstream>
#include <iostream>

void printHelp(const char* iName, int iDefaultNThreads)
{
std::cout << iName <<" [number of threads] \n\n"
<<"If no arguments are given "<<iDefaultNThreads<<" threads will be used"<<std::endl;
void printHelp(const char* iName, int iDefaultNThreads) {
std::cout << iName << " [number of threads] \n\n"
<< "If no arguments are given " << iDefaultNThreads << " threads will be used" << std::endl;
}

int parseOptionsForNumberOfThreads(int argc, char** argv)
{
int parseOptionsForNumberOfThreads(int argc, char** argv) {
constexpr int kDefaultNThreads = 4;
int returnValue = kDefaultNThreads;
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);
}

returnValue = atoi(argv[1]);
}
if( argc > 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<bool> canStart{false};
std::vector<std::unique_ptr<TProfile>> profiles;
std::vector<std::thread> 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<kNThreads; ++i) {
for (int i = 0; i < kNThreads; ++i) {
std::ostringstream s;
profiles.push_back(std::make_unique<TProfile>(s.str().c_str(),s.str().c_str(), 100,10,11,0,10));
profiles.push_back(std::make_unique<TProfile>(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;
}
Loading