Skip to content

Commit 1d8f4ad

Browse files
Extending PM1 Stage 1 - Backup ok
1 parent 2eaf452 commit 1d8f4ad

File tree

1 file changed

+35
-98
lines changed

1 file changed

+35
-98
lines changed

src/modes/RunPM1.cpp

Lines changed: 35 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,6 @@ int App::runPM1Marin() {
15281528
if (rr < 0) rr = read_ckpt(ckpt_file + ".old", resumeI_ck, restored_time, gl_checkpass_ck, gl_blocks_since_check_ck, gl_bits_in_block_ck, gl_current_block_len_ck, in_lot_ck, eacc_ck, wbits_ck, chunkIndex, startPrime, firstChunk_ck, processed_total_bits, bits_in_chunk_ck);
15291529
if (rr == 0) { restored = true; firstChunk = (firstChunk_ck != 0); }
15301530
auto start_sys = std::chrono::system_clock::now();
1531-
15321531
if (doExtend) {
15331532
mpz_class E_diff = buildE_incremental(B1_old, B1_new);
15341533
mp_bitcnt_t bits = mpz_sizeinbase(E_diff.get_mpz_t(), 2);
@@ -1543,13 +1542,8 @@ int App::runPM1Marin() {
15431542
if (bits == 0) {
15441543
std::cout << "Nothing to extend (E_diff = 1)\n";
15451544
} else {
1546-
// Si reprise depuis un checkpoint d’extension, on force bits à bits_in_chunk_ck
1547-
if (restored && bits_in_chunk_ck) {
1548-
bits = (mp_bitcnt_t)bits_in_chunk_ck;
1549-
}
1550-
1551-
auto ext_start_clock = std::chrono::high_resolution_clock::now();
1552-
auto ext_lastDisplay = ext_start_clock;
1545+
auto start_clock = std::chrono::high_resolution_clock::now();
1546+
auto lastDisplay = start_clock;
15531547

15541548
uint64_t B = std::max<uint64_t>(1, (uint64_t)std::sqrt((double)bits));
15551549
double desiredIntervalSeconds = 600.0;
@@ -1565,95 +1559,27 @@ int App::runPM1Marin() {
15651559
: checkpasslevel_auto;
15661560
if (checkpasslevel == 0) checkpasslevel = 1;
15671561

1568-
chunkIndex = std::max<uint64_t>(chunkIndex, 1);
1569-
1570-
uint64_t resumeI = restored ? (uint64_t)resumeI_ck : (uint64_t)bits;
1571-
uint64_t lastIter = resumeI;
1572-
1573-
uint64_t blocks_since_check = restored ? gl_blocks_since_check_ck : 0;
1574-
uint64_t bits_in_block = restored ? gl_bits_in_block_ck : 0;
1575-
uint64_t current_block_len = restored && gl_current_block_len_ck
1576-
? gl_current_block_len_ck
1577-
: (((uint64_t)((resumeI - 1) % B)) + 1);
1578-
mpz_class eacc = restored ? eacc_ck : 0;
1579-
mpz_class wbits = restored ? wbits_ck : 0;
1580-
uint64_t gl_checkpass = restored ? gl_checkpass_ck : 0;
1581-
bool in_lot = restored ? (in_lot_ck != 0) : false;
1582-
1583-
// Barre de progression similaire au Stage 1 normal
1584-
spinner.displayProgress2(
1585-
processed_total_bits + (restored ? (bits - resumeI) : 0),
1586-
processed_total_bits + bits,
1587-
timer.elapsed() + restored_time,
1588-
timer2.elapsed(),
1589-
options.exponent,
1590-
processed_total_bits + (restored ? (bits - resumeI) : 0),
1591-
processed_total_bits,
1592-
"",
1593-
guiServer_ ? guiServer_.get() : nullptr,
1594-
chunkIndex,
1595-
1, // une seule "chunk" pour E_diff
1596-
(restored ? (bits - resumeI) : 0),
1597-
bits,
1598-
true
1599-
);
1600-
1601-
for (mp_bitcnt_t i = (mp_bitcnt_t)resumeI; i > 0; --i) {
1602-
lastIter = i;
1562+
uint64_t blocks_since_check = 0;
1563+
uint64_t bits_in_block = 0;
1564+
uint64_t current_block_len = 0;
1565+
mpz_class eacc = 0;
1566+
mpz_class wbits = 0;
1567+
uint64_t gl_checkpass = 0;
1568+
bool in_lot = false;
1569+
bool errordone = false; // NEW: même comportement que branche normale
16031570

1571+
for (mp_bitcnt_t i = bits; i > 0; --i) {
16041572
if (interrupted) {
1605-
std::cout << "\nInterrupted during extension at iteration " << i << std::endl;
1573+
std::cout << "\nInterrupted during extension.\n";
16061574
if (guiServer_) {
16071575
std::ostringstream oss;
1608-
oss << "\nInterrupted during extension at iteration " << i << std::endl;
1576+
oss << "\nInterrupted during extension.\n";
16091577
guiServer_->appendLog(oss.str());
16101578
}
1611-
auto now = std::chrono::high_resolution_clock::now();
1612-
double et = std::chrono::duration<double>(now - ext_start_clock).count() + restored_time;
1613-
save_ckpt(
1614-
(uint32_t)lastIter,
1615-
et,
1616-
gl_checkpass,
1617-
blocks_since_check,
1618-
bits_in_block,
1619-
current_block_len,
1620-
in_lot ? 1 : 0,
1621-
eacc,
1622-
wbits,
1623-
chunkIndex,
1624-
0, // startPrime non utilisé en extension
1625-
1, // firstChunk = 1 pour cette extension
1626-
processed_total_bits + (bits - i),
1627-
(uint64_t)bits
1628-
);
16291579
delete eng;
16301580
return 0;
16311581
}
16321582

1633-
auto now = std::chrono::high_resolution_clock::now();
1634-
if (std::chrono::duration_cast<std::chrono::seconds>(now - lastBackup).count() >= options.backup_interval) {
1635-
std::cout << "\nBackup point done at i=" << i << " start...." << std::endl;
1636-
double et = std::chrono::duration<double>(now - ext_start_clock).count() + restored_time;
1637-
save_ckpt(
1638-
(uint32_t)lastIter,
1639-
et,
1640-
gl_checkpass,
1641-
blocks_since_check,
1642-
bits_in_block,
1643-
current_block_len,
1644-
in_lot ? 1 : 0,
1645-
eacc,
1646-
wbits,
1647-
chunkIndex,
1648-
0, // startPrime placeholder
1649-
1, // firstChunk
1650-
processed_total_bits + (bits - i),
1651-
(uint64_t)bits
1652-
);
1653-
std::cout << "\nBackup point done at i=" << i << " done...." << std::endl;
1654-
lastBackup = now;
1655-
}
1656-
16571583
if (bits_in_block == 0) {
16581584
current_block_len = ((uint64_t)((i - 1) % B)) + 1;
16591585
if (current_block_len == B) {
@@ -1692,10 +1618,26 @@ int App::runPM1Marin() {
16921618
eng->mul(RSTATE, RTMP);
16931619
}
16941620

1621+
// Injection d'erreur comme dans la branche normale
1622+
if (options.erroriter > 0 &&
1623+
(bits - i + 1) == options.erroriter &&
1624+
!errordone)
1625+
{
1626+
errordone = true;
1627+
eng->sub(RSTATE, 2);
1628+
std::cout << "Injected error at iteration " << (bits - i + 1) << std::endl;
1629+
if (guiServer_) {
1630+
std::ostringstream oss;
1631+
oss << "Injected error at iteration " << (bits - i + 1);
1632+
guiServer_->appendLog(oss.str());
1633+
}
1634+
}
1635+
16951636
wbits <<= 1;
16961637
if (b) wbits += 1;
16971638
bits_in_block += 1;
1698-
1639+
//if (options.erroriter > 0 && (resumeI - i + 1) == options.erroriter && !errordone) { errordone = true; eng->sub(RSTATE, 2); std::cout << "Injected error at iteration " << (resumeI - i + 1) << std::endl; if (guiServer_) { std::ostringstream oss; oss << "Injected error at iteration " << (resumeI - i + 1); guiServer_->appendLog(oss.str()); } }
1640+
16991641
bool end_block = (bits_in_block == current_block_len);
17001642
if (end_block) {
17011643
if (current_block_len == B) {
@@ -1833,11 +1775,11 @@ int App::runPM1Marin() {
18331775
wbits = 0;
18341776
}
18351777

1836-
auto now2 = std::chrono::high_resolution_clock::now();
1837-
if (std::chrono::duration_cast<std::chrono::seconds>(now2 - ext_lastDisplay).count() >= 10) {
1778+
auto now = std::chrono::high_resolution_clock::now();
1779+
if (std::chrono::duration_cast<std::chrono::seconds>(now - lastDisplay).count() >= 10) {
18381780
double done = (double)(bits - i + 1);
18391781
double total = (double)bits;
1840-
double elapsed = std::chrono::duration<double>(now2 - ext_start_clock).count();
1782+
double elapsed = std::chrono::duration<double>(now - start_clock).count();
18411783
double ips = done / std::max(1e-9, elapsed);
18421784
double eta = (total > done && ips > 0.0)
18431785
? (total - done) / ips
@@ -1848,7 +1790,7 @@ int App::runPM1Marin() {
18481790
<< (int(eta) / 3600) << "h "
18491791
<< (int(eta) % 3600) / 60 << "m\r"
18501792
<< std::flush;
1851-
ext_lastDisplay = now2;
1793+
lastDisplay = now;
18521794
}
18531795
}
18541796

@@ -1896,9 +1838,6 @@ int App::runPM1Marin() {
18961838
}
18971839
}
18981840

1899-
processed_total_bits += bits;
1900-
restored = false;
1901-
19021841
std::cout << "\nExtension exponentiation done.\n";
19031842
}
19041843

@@ -2253,7 +2192,7 @@ int App::runPM1Marin() {
22532192
auto fmt = [](const std::chrono::system_clock::time_point& tp){
22542193
using namespace std::chrono;
22552194
auto ms = duration_cast<milliseconds>(tp.time_since_epoch()) % 1000;
2256-
std::time_t tt = system_clock::to_time_t(tp);
2195+
std::time_t tt = std::chrono::system_clock::to_time_t(tp);
22572196
std::tm tmv{};
22582197
#if defined(_WIN32)
22592198
gmtime_s(&tmv, &tt);
@@ -2367,5 +2306,3 @@ int App::runPM1Marin() {
23672306
//delete eng;
23682307
return factorFound ? 0 : 1;
23692308
}
2370-
2371-

0 commit comments

Comments
 (0)