Browse Source

fixing the argc in main

avadapal 1 year ago
parent
commit
3d55534037
5 changed files with 29 additions and 23 deletions
  1. 19 13
      heap.cpp
  2. 1 1
      heap.hpp
  3. 2 2
      online.cpp
  4. 1 1
      online.hpp
  5. 6 6
      prac.cpp

+ 19 - 13
heap.cpp

@@ -649,38 +649,44 @@ RegAS MinHeap::extract_min(MPCIO & mpcio, MPCTIO tio, yield_t & yield, int is_op
 
 
 
-void Heap(MPCIO & mpcio,  const PRACOptions & opts, char ** args) {
+void Heap(MPCIO & mpcio,  const PRACOptions & opts, char ** args, int argc) {
+    
+    std::cout << "argc = " << argc << std::endl;
+    
+    MPCTIO tio(mpcio, 0, opts.num_threads);
+
+    int nargs = argc;
+    
+    if(tio.player() == 2) nargs -= 6;
+    if(tio.player() == 1) nargs -= 5;
+    if(tio.player() == 0) nargs -= 4;
     
-    int argc = 14;
     int maxdepth = 0;
     int heapdepth = 0;
     size_t n_inserts = 0;
     size_t n_extracts = 0;
     int is_optimized = 0;
     int run_sanity = 0;
-    //int itr = 0;
 
     // Process command line arguments
-    for (int i = 0; i < argc; i += 2) {
+    for (int i = 0; i < nargs; i += 2) {
         std::string option = args[i];
-        if (option == "-m" && i + 1 < argc) {
+        if (option == "-m" && i + 1 < nargs) {
             maxdepth = std::atoi(args[i + 1]);
-        } else if (option == "-d" && i + 1 < argc) {
+        } else if (option == "-d" && i + 1 < nargs) {
             heapdepth = std::atoi(args[i + 1]);
-        } else if (option == "-i" && i + 1 < argc) {
+        } else if (option == "-i" && i + 1 < nargs) {
             n_inserts = std::atoi(args[i + 1]);
-        } else if (option == "-e" && i + 1 < argc) {
+        } else if (option == "-e" && i + 1 < nargs) {
             n_extracts = std::atoi(args[i + 1]);
-        } else if (option == "-opt" && i + 1 < argc) {
+        } else if (option == "-opt" && i + 1 < nargs) {
             is_optimized = std::atoi(args[i + 1]);
-        } else if (option == "-s" && i + 1 < argc) {
+        } else if (option == "-s" && i + 1 < nargs) {
             run_sanity = std::atoi(args[i + 1]);
-        } else if (option == "-itr" && i + 1 < argc) {
-            //itr = std::atoi(args[i + 1]);
         }
     }
  
-    MPCTIO tio(mpcio, 0, opts.num_threads);
+    
     
     run_coroutines(tio, [ & tio, maxdepth, heapdepth, n_inserts, n_extracts, is_optimized, run_sanity, &mpcio](yield_t & yield) {
         size_t size = size_t(1) << maxdepth;

+ 1 - 1
heap.hpp

@@ -32,5 +32,5 @@ class MinHeap {
 };
 
 void Heap(MPCIO &mpcio,
-   const PRACOptions &opts, char **args);
+   const PRACOptions &opts, char **args, int argc);
 #endif

+ 2 - 2
online.cpp

@@ -1516,7 +1516,7 @@ static void path(MPCIO &mpcio,
     });
 }
 
-void online_main(MPCIO &mpcio, const PRACOptions &opts, char **args)
+void online_main(MPCIO &mpcio, const PRACOptions &opts, char **args, int argc)
 {
     MPCTIO tio(mpcio, 0);
     if (!*args) {
@@ -1621,7 +1621,7 @@ void online_main(MPCIO &mpcio, const PRACOptions &opts, char **args)
     } 
      else if (!strcmp(*args, "heap")) {
         ++args;
-        Heap(mpcio, opts, args);
+        Heap(mpcio, opts, args, argc);
     } else {
         std::cerr << "Unknown mode " << *args << "\n";
     }

+ 1 - 1
online.hpp

@@ -4,6 +4,6 @@
 #include "mpcio.hpp"
 #include "options.hpp"
 
-void online_main(MPCIO &mpcio, const PRACOptions &opts, char **args);
+void online_main(MPCIO &mpcio, const PRACOptions &opts, char **args, int argc);
 
 #endif

+ 6 - 6
prac.cpp

@@ -25,7 +25,7 @@ static void usage(const char *progname)
 
 static void comp_player_main(boost::asio::io_context &io_context,
     unsigned player, const PRACOptions &opts, const char *p0addr,
-    char **args)
+    char **args, int argc)
 {
     std::deque<tcp::socket> peersocks, serversocks;
     mpcio_setup_computational(player, io_context, p0addr,
@@ -37,7 +37,7 @@ static void comp_player_main(boost::asio::io_context &io_context,
         if (opts.mode == MODE_PREPROCESSING) {
             preprocessing_comp(mpcio, opts, args);
         } else {
-            online_main(mpcio, opts, args);
+            online_main(mpcio, opts, args, argc);
         }
     });
 
@@ -51,7 +51,7 @@ static void comp_player_main(boost::asio::io_context &io_context,
 
 static void server_player_main(boost::asio::io_context &io_context,
     const PRACOptions &opts, const char *p0addr,
-    const char *p1addr, char **args)
+    const char *p1addr, char **args, int argc)
 {
     std::deque<tcp::socket> p0socks, p1socks;
     mpcio_setup_server(io_context, p0addr, p1addr,
@@ -63,7 +63,7 @@ static void server_player_main(boost::asio::io_context &io_context,
         if (opts.mode == MODE_PREPROCESSING) {
             preprocessing_server(mpcserverio, opts, args);
         } else {
-            online_main(mpcserverio, opts, args);
+            online_main(mpcserverio, opts, args, argc);
         }
     });
 
@@ -164,9 +164,9 @@ int main(int argc, char **argv)
     boost::asio::io_context io_context;
 
     if (player < 2) {
-        comp_player_main(io_context, player, opts, p0addr, args);
+        comp_player_main(io_context, player, opts, p0addr, args, argc);
     } else {
-        server_player_main(io_context, opts, p0addr, p1addr, args);
+        server_player_main(io_context, opts, p0addr, p1addr, args, argc);
     }
 
     return 0;