Skip to content

Commit fc1dc72

Browse files
authored
Multi-threaded reader for PSI iO
1 parent 3b0b9e5 commit fc1dc72

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

misc/psi/io/io.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,14 @@ helib::Database<TXT> readDbFromFile(const std::string& databaseFilePath,
7676
}
7777
}
7878
} else { // Ctxt query
79-
for (long i = 0; i < nrow; ++i) {
80-
for (long j = 0; j < ncol; ++j) {
81-
reader.value().readDatum(data(i, j), i, j);
82-
}
79+
NTL_EXEC_RANGE(nrow * ncol, first, last)
80+
Reader<TXT> threadReader(reader.value());
81+
for (long i = first; i < last; ++i) {
82+
long row = i / ncol;
83+
long col = i % ncol;
84+
threadReader.readDatum(data(row, col), row, col);
8385
}
86+
NTL_EXEC_RANGE_END
8487
}
8588

8689
return helib::Database<TXT>(data, contextp);
@@ -128,11 +131,14 @@ helib::Matrix<TXT> readQueryFromFile(const std::string& queryFilePath,
128131
}
129132
} else { // Ctxt query
130133
// Read in ctxts
131-
for (long i = 0; i < nrow; ++i) {
132-
for (long j = 0; j < ncol; ++j) {
133-
reader.value().readDatum(query(i, j), i, j);
134-
}
134+
NTL_EXEC_RANGE(nrow * ncol, first, last)
135+
Reader<TXT> threadReader(reader.value());
136+
for (long i = first; i < last; ++i) {
137+
long row = i / ncol;
138+
long col = i % ncol;
139+
threadReader.readDatum(query(row, col), row, col);
135140
}
141+
NTL_EXEC_RANGE_END
136142
if (ncol == 1) { // Transpose to make row vector
137143
query.transpose();
138144
}

0 commit comments

Comments
 (0)