Skip to content

Commit 612e55e

Browse files
authored
Merge pull request #6842 from BOINC/dpa_for_sched
back end code: use range-based for
2 parents 7ad019a + 6f669fb commit 612e55e

38 files changed

+322
-461
lines changed

db/boinc_db.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,15 +2397,15 @@ int DB_SCHED_RESULT_ITEM_SET::enumerate() {
23972397
return 0;
23982398
}
23992399

2400-
int DB_SCHED_RESULT_ITEM_SET::add_result(char* result_name) {
2400+
int DB_SCHED_RESULT_ITEM_SET::add_result(const char* result_name) {
24012401
SCHED_RESULT_ITEM result;
24022402
result.id = 0;
24032403
strcpy2(result.queried_name, result_name);
24042404
results.push_back(result);
24052405
return 0;
24062406
}
24072407

2408-
int DB_SCHED_RESULT_ITEM_SET::lookup_result(char* result_name, SCHED_RESULT_ITEM** rip) {
2408+
int DB_SCHED_RESULT_ITEM_SET::lookup_result(const char* result_name, SCHED_RESULT_ITEM** rip) {
24092409
unsigned int i;
24102410
for (i=0; i<results.size(); i++) {
24112411
if (!strcmp(results[i].name, result_name)) {

db/boinc_db.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,14 +417,14 @@ class DB_SCHED_RESULT_ITEM_SET : public DB_BASE_SPECIAL {
417417
DB_SCHED_RESULT_ITEM_SET(DB_CONN* p=0);
418418
std::vector<SCHED_RESULT_ITEM> results;
419419

420-
int add_result(char* result_name);
420+
int add_result(const char* result_name);
421421

422422
int enumerate();
423423
// using a single SQL query, look up all the reported results,
424424
// (based on queried_name)
425425
// and fill in the rest of the entries in the results vector
426426

427-
int lookup_result(char* result_name, SCHED_RESULT_ITEM** result);
427+
int lookup_result(const char* result_name, SCHED_RESULT_ITEM** result);
428428

429429
int update_result(SCHED_RESULT_ITEM& result);
430430
int update_workunits();

lib/average.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of BOINC.
2-
// http://boinc.berkeley.edu
3-
// Copyright (C) 2010 University of California
2+
// https://boinc.berkeley.edu
3+
// Copyright (C) 2026 University of California
44
//
55
// BOINC is free software; you can redistribute it and/or modify it
66
// under the terms of the GNU Lesser General Public License
@@ -56,7 +56,7 @@ struct AVERAGE {
5656
return truncated;
5757
}
5858

59-
inline double get_avg() {
59+
inline double get_avg() const {
6060
return avg;
6161
}
6262
};

sched/credit.cpp

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of BOINC.
2-
// http://boinc.berkeley.edu
3-
// Copyright (C) 2008 University of California
2+
// https://boinc.berkeley.edu
3+
// Copyright (C) 2026 University of California
44
//
55
// BOINC is free software; you can redistribute it and/or modify it
66
// under the terms of the GNU Lesser General Public License
@@ -828,28 +828,27 @@ double low_average(vector<double>& v) {
828828
// compute the average of number weighted by proximity
829829
// to another number
830830
double pegged_average(vector<double>& v, double anchor) {
831-
int n=v.size();
832-
double weights=0,sum=0,w;
833-
int i;
831+
int n = v.size();
832+
double weights=0, sum=0, w;
834833
if (n==1) {
835834
return v[0];
836835
}
837-
for (i=0; i<n; i++) {
838-
w=(1.0/(0.1*anchor+fabs(anchor-v[i])));
839-
weights+=w;
840-
sum+=w*v[i];
836+
for (double x: v) {
837+
w = (1.0/(0.1*anchor+fabs(anchor-x)));
838+
weights += w;
839+
sum += w*x;
841840
}
842841
return sum/weights;
843842
}
844843

845844
double vec_min(vector<double>& v) {
846-
double x = v[0];
847-
for (unsigned int i=1; i<v.size(); i++) {
848-
if (v[i] < x) {
849-
x = v[i];
845+
double m = v[0];
846+
for (double x: v) {
847+
if (x < m) {
848+
m = x;
850849
}
851850
}
852-
return x;
851+
return m;
853852
}
854853

855854
// Called by validator when canonical result has been selected.
@@ -872,13 +871,12 @@ int assign_credit_set(
872871
double max_granted_credit,
873872
double &credit // out
874873
) {
875-
unsigned int i;
876874
int mode, retval;
877875
double pfc;
878876
vector<double> normal;
879877
vector<double> approx;
880878

881-
for (i=0; i<results.size(); i++) {
879+
for (unsigned int i=0; i<results.size(); i++) {
882880
RESULT &r = results[i];
883881
if (r.validate_state != VALIDATE_STATE_VALID) {
884882
continue;
@@ -970,26 +968,23 @@ int assign_credit_set(
970968
// done at the end of every validator scan.
971969
//
972970
int write_modified_app_versions(vector<DB_APP_VERSION_VAL>& app_versions) {
973-
unsigned int i, j;
974971
int retval = 0;
975972
double now = dtime();
976973

977-
for (i=0; i<app_versions.size(); i++) {
978-
DB_APP_VERSION_VAL &av = app_versions[i];
974+
for (DB_APP_VERSION_VAL &av: app_versions) {
979975
if (av.pfc_samples.empty() && av.credit_samples.empty()) {
980976
continue;
981977
}
982978
for (int k=0; k<10; k++) {
983979
double pfc_n_orig = av.pfc.n;
984980
double expavg_credit_orig = av.expavg_credit;
985981

986-
for (j=0; j<av.pfc_samples.size(); j++) {
982+
for (double x: av.pfc_samples) {
987983
av.pfc.update(
988-
av.pfc_samples[j],
989-
AV_AVG_THRESH, AV_AVG_WEIGHT, AV_AVG_LIMIT
984+
x, AV_AVG_THRESH, AV_AVG_WEIGHT, AV_AVG_LIMIT
990985
);
991986
}
992-
for (j=0; j<av.credit_samples.size(); j++) {
987+
for (unsigned int j=0; j<av.credit_samples.size(); j++) {
993988
update_average(
994989
now,
995990
av.credit_times[j], av.credit_samples[j], CREDIT_HALF_LIFE,

sched/credit_test.cpp

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of BOINC.
2-
// http://boinc.berkeley.edu
3-
// Copyright (C) 2016 University of California
2+
// https://boinc.berkeley.edu
3+
// Copyright (C) 2026 University of California
44
//
55
// BOINC is free software; you can redistribute it and/or modify it
66
// under the terms of the GNU Lesser General Public License
@@ -76,28 +76,22 @@ void read_db() {
7676
}
7777

7878
PLATFORM* lookup_platform(int id) {
79-
unsigned int i;
80-
for (i=0; i<platforms.size(); i++) {
81-
PLATFORM& p = platforms[i];
79+
for (PLATFORM& p: platforms) {
8280
if (p.id == id) return &p;
8381
}
8482
return NULL;
8583
}
8684

8785
APP_VERSION* lookup_av(int id) {
88-
unsigned int i;
89-
for (i=0; i<app_versions.size(); i++) {
90-
APP_VERSION& av = app_versions[i];
86+
for (APP_VERSION& av: app_versions) {
9187
if (av.id == id) return &av;
9288
}
9389
printf(" missing app version %d\n", id);
9490
exit(1);
9591
}
9692

9793
APP& lookup_app(int id) {
98-
unsigned int i;
99-
for (i=0; i<apps.size(); i++) {
100-
APP& app = apps[i];
94+
for (APP& app: apps) {
10195
if (app.id == id) return app;
10296
}
10397
printf("missing app: %d\n", id);
@@ -106,9 +100,7 @@ APP& lookup_app(int id) {
106100
}
107101

108102
HOST_APP_VERSION& lookup_host_app_version(int hostid, int avid) {
109-
unsigned int i;
110-
for (i=0; i<host_app_versions.size(); i++) {
111-
HOST_APP_VERSION& hav = host_app_versions[i];
103+
for (HOST_APP_VERSION& hav: host_app_versions) {
112104
if (hav.host_id != hostid) continue;
113105
if (hav.app_version_id != avid) continue;
114106
return hav;
@@ -120,16 +112,13 @@ HOST_APP_VERSION& lookup_host_app_version(int hostid, int avid) {
120112
return host_app_versions.back();
121113
}
122114

123-
void print_average(AVERAGE& a) {
124-
printf("n %f avg %f\n", a.n, a.get_avg()
125-
);
115+
void print_average(const AVERAGE& a) {
116+
printf("n %f avg %f\n", a.n, a.get_avg());
126117
}
127118

128119
void print_avs() {
129-
unsigned int i;
130120
printf("----- scales --------\n");
131-
for (i=0; i<app_versions.size(); i++) {
132-
APP_VERSION& av = app_versions[i];
121+
for (const APP_VERSION& av: app_versions) {
133122
if (!av.pfc.n) continue;
134123
PLATFORM* p = lookup_platform(av.platformid);
135124
printf("app %lu vers %lu (%s %s)\n scale %f ",
@@ -163,7 +152,7 @@ struct RSC_INFO {
163152
nvers_thresh = 0;
164153
nvers_total = 0;
165154
}
166-
void update(APP_VERSION& av) {
155+
void update(const APP_VERSION& av) {
167156
nvers_total++;
168157
if (av.pfc.n > MIN_VERSION_SAMPLES) {
169158
nvers_thresh++;
@@ -177,12 +166,11 @@ struct RSC_INFO {
177166
};
178167

179168
void scale_versions(APP& app, double avg) {
180-
for (unsigned int j=0; j<app_versions.size(); j++) {
181-
APP_VERSION& av = app_versions[j];
169+
for (APP_VERSION& av: app_versions) {
182170
if (av.appid != app.id) continue;
183171
if (av.pfc.n < MIN_VERSION_SAMPLES) continue;
184172

185-
av.pfc_scale= avg/av.pfc.get_avg();
173+
av.pfc_scale = avg/av.pfc.get_avg();
186174
PLATFORM* p = lookup_platform(av.platformid);
187175
printf("updating scale factor for (%s %s)\n",
188176
p->name, av.plan_class
@@ -198,17 +186,14 @@ void scale_versions(APP& app, double avg) {
198186
// and find the min average PFC for each app
199187
//
200188
void update_av_scales() {
201-
unsigned int i, j;
202189
printf("----- updating scales --------\n");
203-
for (i=0; i<apps.size(); i++) {
204-
APP& app = apps[i];
190+
for (APP& app: apps) {
205191
printf("app %lu\n", app.id);
206192
RSC_INFO cpu_info, gpu_info;
207193

208194
// find the average PFC of CPU and GPU versions
209195

210-
for (j=0; j<app_versions.size(); j++) {
211-
APP_VERSION& av = app_versions[j];
196+
for (const APP_VERSION& av: app_versions) {
212197
if (av.appid != app.id) continue;
213198
if (strstr(av.plan_class, "cuda") || strstr(av.plan_class, "ati")) {
214199
printf("gpu update: %lu %s %f\n", av.id, av.plan_class, av.pfc.get_avg());
@@ -247,8 +232,6 @@ void update_av_scales() {
247232
accumulate_stats = true;
248233
}
249234
}
250-
251-
252235
}
253236
printf("-------------\n");
254237
}

sched/db_dump.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of BOINC.
2-
// http://boinc.berkeley.edu
3-
// Copyright (C) 2019 University of California
2+
// https://boinc.berkeley.edu
3+
// Copyright (C) 2026 University of California
44
//
55
// BOINC is free software; you can redistribute it and/or modify it
66
// under the terms of the GNU Lesser General Public License
@@ -841,7 +841,6 @@ int tables_file(char* dir) {
841841
}
842842

843843
int ENUMERATION::make_it_happen(char* output_dir) {
844-
unsigned int i;
845844
int n, retval;
846845
DB_USER user;
847846
DB_USER_DELETED user_deleted;
@@ -863,8 +862,7 @@ int ENUMERATION::make_it_happen(char* output_dir) {
863862

864863
sprintf(path, "%s/%s", output_dir, filename);
865864

866-
for (i=0; i<outputs.size(); i++) {
867-
OUTPUT& out = outputs[i];
865+
for (OUTPUT& out: outputs) {
868866
if (out.recs_per_file) {
869867
out.nzfile = new NUMBERED_ZFILE(
870868
tag_name[table], out.compression, path, out.recs_per_file
@@ -944,8 +942,7 @@ int ENUMERATION::make_it_happen(char* output_dir) {
944942
if (retval) break;
945943

946944
if (!strncmp("deleted", user.authenticator, 7)) continue;
947-
for (i=0; i<outputs.size(); i++) {
948-
OUTPUT& out = outputs[i];
945+
for (OUTPUT& out: outputs) {
949946
if (sort == SORT_ID && out.recs_per_file) {
950947
out.nzfile->set_id(n++);
951948
}
@@ -969,8 +966,7 @@ int ENUMERATION::make_it_happen(char* output_dir) {
969966
retval = user_deleted.enumerate("order by userid");
970967
if (retval) break;
971968
nusers_deleted++;
972-
for (i=0; i<outputs.size(); i++) {
973-
OUTPUT& out = outputs[i];
969+
for (OUTPUT& out: outputs) {
974970
if (sort == SORT_ID && out.recs_per_file) {
975971
out.nzfile->set_id(n++);
976972
}
@@ -1032,8 +1028,7 @@ int ENUMERATION::make_it_happen(char* output_dir) {
10321028
if (retval) break;
10331029
if (!host.userid) continue;
10341030
if (!strncmp("deleted", host.domain_name, 8)) continue;
1035-
for (i=0; i<outputs.size(); i++) {
1036-
OUTPUT& out = outputs[i];
1031+
for (OUTPUT& out: outputs) {
10371032
if (sort == SORT_ID && out.recs_per_file) {
10381033
out.nzfile->set_id(n++);
10391034
}
@@ -1057,8 +1052,7 @@ int ENUMERATION::make_it_happen(char* output_dir) {
10571052
retval = host_deleted.enumerate("order by hostid");
10581053
if (retval) break;
10591054
nhosts_deleted++;
1060-
for (i=0; i<outputs.size(); i++) {
1061-
OUTPUT& out = outputs[i];
1055+
for (OUTPUT& out: outputs) {
10621056
if (sort == SORT_ID && out.recs_per_file) {
10631057
out.nzfile->set_id(n++);
10641058
}
@@ -1087,8 +1081,7 @@ int ENUMERATION::make_it_happen(char* output_dir) {
10871081
retval = team.enumerate(clause);
10881082
if (retval) break;
10891083
nteams++;
1090-
for (i=0; i<outputs.size(); i++) {
1091-
OUTPUT& out = outputs[i];
1084+
for (OUTPUT& out: outputs) {
10921085
if (sort == SORT_ID && out.recs_per_file) {
10931086
out.nzfile->set_id(n++);
10941087
}
@@ -1107,8 +1100,7 @@ int ENUMERATION::make_it_happen(char* output_dir) {
11071100
}
11081101
break;
11091102
}
1110-
for (i=0; i<outputs.size(); i++) {
1111-
OUTPUT& out = outputs[i];
1103+
for (OUTPUT& out: outputs) {
11121104
if (out.zfile) {
11131105
out.zfile->close();
11141106
delete out.zfile;
@@ -1265,9 +1257,7 @@ int main(int argc, char** argv) {
12651257

12661258
boinc_mkdir(spec.output_dir);
12671259

1268-
unsigned int j;
1269-
for (j=0; j<spec.enumerations.size(); j++) {
1270-
ENUMERATION& e = spec.enumerations[j];
1260+
for (ENUMERATION& e: spec.enumerations) {
12711261
e.make_it_happen(spec.output_dir);
12721262
}
12731263

0 commit comments

Comments
 (0)