Skip to content

Commit 57dfe34

Browse files
Release prmers
1 parent 17474fb commit 57dfe34

File tree

1 file changed

+80
-2
lines changed

1 file changed

+80
-2
lines changed

prmers.cpp

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
*
2525
* This code is released as free software.
2626
*/
27+
#include <cstdlib>
28+
#ifdef _WIN32
29+
#include <windows.h>
30+
#endif
2731
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
2832
#ifdef __APPLE__
2933
#include <OpenCL/opencl.h>
@@ -603,6 +607,49 @@ void executeFusionneNTT_Forward(cl_command_queue queue,cl_kernel kernel_ntt_mm_3
603607
}
604608
}
605609
}
610+
#ifdef _WIN32
611+
#include <windows.h>
612+
#endif
613+
614+
bool isLaunchedFromTerminal() {
615+
#ifdef _WIN32
616+
return GetConsoleWindow() != nullptr;
617+
#else
618+
return isatty(fileno(stdin)); // POSIX: Linux/macOS
619+
#endif
620+
}
621+
622+
int askExponentInteractively() {
623+
#ifdef _WIN32
624+
char buffer[32];
625+
MessageBoxA(
626+
nullptr,
627+
"PrMers: GPU-accelerated Mersenne primality tester\n\n"
628+
"You'll now be asked which exponent you'd like to test.",
629+
"PrMers - Select Exponent",
630+
MB_OK | MB_ICONINFORMATION
631+
);
632+
std::cout << "Enter the exponent to test (e.g. 21701): ";
633+
std::cin.getline(buffer, sizeof(buffer));
634+
return std::atoi(buffer);
635+
#else
636+
std::cout << "============================================\n";
637+
std::cout << " PrMers: GPU-accelerated Mersenne primality test\n";
638+
std::cout << " Powered by OpenCL | NTT | LL | PRP | IBDWT\n";
639+
std::cout << "============================================\n\n";
640+
641+
std::string input;
642+
std::cout << "Enter the exponent to test (e.g. 21701): ";
643+
std::getline(std::cin, input);
644+
try {
645+
return std::stoi(input);
646+
} catch (...) {
647+
std::cerr << "Invalid input. Aborting." << std::endl;
648+
std::exit(1);
649+
}
650+
#endif
651+
}
652+
606653

607654
void executeFusionneNTT_Inverse(cl_command_queue queue,cl_kernel kernel_ntt_inverse_mm_2_steps,
608655
cl_kernel kernel_inverse_ntt_mm, cl_kernel kernel_inverse_ntt_mm_last, cl_kernel kernel_inverse_ntt_m1,
@@ -738,8 +785,39 @@ void handleFinalCarry(std::vector<uint64_t>& x, const std::vector<int>& digit_wi
738785
// Main function
739786
// -----------------------------------------------------------------------------
740787
int main(int argc, char** argv) {
741-
// Set the signal handler for SIGINT (Ctrl-C)
742-
std::signal(SIGINT, signalHandler);
788+
if (argc < 2) {
789+
if (!isLaunchedFromTerminal()) {
790+
#ifdef _WIN32
791+
system("start cmd /k prmers.exe");
792+
#else
793+
#ifdef __APPLE__
794+
system("osascript -e 'tell application \"Terminal\" to do script \"cd \\\"$(pwd)\\\"; ./prmers\"'");
795+
#else
796+
int ret = system("x-terminal-emulator -e ./prmers");
797+
if (ret != 0) {
798+
std::cerr << "⚠️ Failed to launch terminal emulator." << std::endl;
799+
}
800+
801+
802+
#endif
803+
#endif
804+
return 0;
805+
}
806+
807+
int exponent = askExponentInteractively();
808+
809+
#ifdef _WIN32
810+
std::string cmd = "start cmd /k prmers.exe " + std::to_string(exponent);
811+
int ret2 = system(cmd.c_str());
812+
(void)ret2;
813+
814+
#else
815+
std::string cmd = "./prmers " + std::to_string(exponent);
816+
int ret2 = system(cmd.c_str());
817+
(void)ret2;
818+
#endif
819+
return 0;
820+
}
743821

744822
if (argc < 2) {
745823
std::cerr << "Error: Missing <p_min> argument.\n";

0 commit comments

Comments
 (0)