DeinoMPI Forum

Forum dedicated to discussing DeinoMPI
Welcome to DeinoMPI Forum Sign in | Join | Help

Re: Writing C# Programs with DeinoMPI

  •  10-18-2007, 11:19 PM

    Re: Writing C# Programs with DeinoMPI

    Hello!

    I decided to write a managed c++ class to wrap MPI function.
    I stumble into this weird Access violation when wrote this code:

    //void Init(int argc, char **argv)
    void
    Init()
    {
       array<String^>^ argv = System::Environment::GetCommandLineArgs
    ();
       int argc = argv->Length
    ;
       char ** pArgv = new char*[argc
    ];
       for (int i=0;i<argc;i
    ++)
       {
          std::string str = ToCppString(argv[i
    ]);
          int len = str.size
    ();
          pArgv[i] = new char[ len
    + 1];
          strcpy(pArgv[i], str.c_str
    ());
          std::cout << pArgv[i] << endl
    ;
       }
       MPI::Init(argc, pArgv
    ); // ACCESS VIOLATION exception is here!!!
       for (int i=0;i<argc;i
    ++)
          delete []pArgv[i
    ];
       delete pArgv
    ;
    }

    I had to do it that way because the C# program has no agrc&argv couple.
    Here is my client C# code:

    using MPI_for_cs;

    namespace Test_CS_MPI
    {
       class
    Program
      
    {
          static void Main(string[] args
    )
          {
             CS_MPI c1 = new CS_MPI
    ();
             c1.Init
    ();
             String name = c1.Get_processor_name
    ();
             Console.WriteLine(name
    );
          }
       }
    }

    I had to be sure what the cause of the crash, so I wrote another managed C++ client that uses the same class, but this time I pass it the original argc & agrv and the Init function implementation was simple: just call MPI::Init(argc, argv); the same parameters it gets it passes. It worked.
    Code:

    int main(int argc, char **argv)
    {
       Console::WriteLine(L"Hello World");
      
    Console::WriteLine(argc);
       CS_MPI mpi;
      
    mpi.Init(argc, argv);
      
    return 0;
    }

    What is wrong in the code I wrote by "manufacturing" my own argc & argv?
    If you want the projects themselves I'll send it by email.

    Thanks!

View Complete Thread
Powered by Community Server, by Telligent Systems