[mpich-discuss] problem of calling .dll in mpich

Jayesh Krishna jayesh at mcs.anl.gov
Mon Dec 8 14:48:44 CST 2008


Hi,
 Looks to me to be some issue with permissions for the user registered to
run the MPI job (mpiexec -register). What does the script do (Note that
you cannot access network drives when you run your program using mpiexec,
unless you use the "-map" option of mpiexec to explicitly map the network
drive)?
 I just tried running a program that loads a dll and executes a procedure
from the dll using mpiexec (mpiexec -n 2 foo.exe) and it worked fine. 
 
Regards,
Jayesh

  _____  

From: Vivian [mailto:viviantj at gmail.com] 
Sent: Friday, December 05, 2008 6:11 PM
To: Jayesh Krishna
Cc: mpich-discuss at mcs.anl.gov
Subject: Re: [mpich-discuss] problem of calling .dll in mpich


Hi, 
      It runs fine with the "-localonly" and "-localroot" option. 
      Really don't understand why it cannot call dll using "-n 1" option.
(This program should be run in multiple computers).
Regards,
Vivian


On Fri, Dec 5, 2008 at 6:01 PM, Jayesh Krishna <jayesh at mcs.anl.gov> wrote:


Hi,
 Can you also try whether the program runs fine with the "-localroot"
option ?
 
Regards,
Jayesh

  _____  

From: Vivian [mailto:viviantj at gmail.com] 
Sent: Friday, December 05, 2008 11:30 AM
To: Jayesh Krishna
Cc: mpich-discuss at mcs.anl.gov
Subject: Re: [mpich-discuss] problem of calling .dll in mpich


Hi,   
      I attached the sample test program which fails to call dll when it
is run by "mpiexec -n 1 application name". 
     (Btw, when using "mpiexec -localonly application name", dll can be
called.)
       
The DLL called in the program is a Dynamic Link Library (DLL) provided by
ArcView ( a GIS software) for use with WinHelp that lets you run a script.
The DLL contains two functions that you can use as WinHelp macros. 

AVRun -- this macro sends an Avenue statement from Help to ArcView. For
example, you might send a statement to make a particular view the active
document or run a script contained in the current project.



AVScript -- this macro runs a given script regardless of what ArcView
project is open. The script, in this case, is stored as part of the Help
file and not in an ArcView project.




Here's how you could run a script in the current ArcView project file and
pass an argument to it. In this case, the number 5 is passed as an
argument to a script, named script1, in the project:
AVRun(`av.Run("script1", 5)') 






      Here is the sample test code


--------------------------------------------------------------------------
--------------------------------------------------------------------------
--------------
#include<iostream>
#include <windows.h> 

/*Some users may get error messages such as
        SEEK_SET is #defined but must not be for the C++ binding of MPI
   The problem is that both stdio.h and the MPI C++ interface use
SEEK_SET, SEEK_CUR, and SEEK_END. 
   This is really a bug in the MPI-2 standard. You can try adding the
following three lines before mpi.h is included
*/
#undef SEEK_SET
#undef SEEK_END
#undef SEEK_CUR
#include "mpi.h"

typedef char (__stdcall *AVRUN) (char[100]); 
HINSTANCE ArcviewDLL;
AVRUN AVRun;

int main(int argc,char **argv)
{

    //load avhelp.dll 
    ArcviewDLL= LoadLibraryA("Avhelp.dll");    //It needs a Unicode
string. Therefore, we use LoadLibraryA() instead of LoadLibrary()  
    if (ArcviewDLL==NULL)
    {
        printf("cannot load the Avhelp.dll.\n");
        printf("Make sure that the Avhelp.dll is in your \\windows\\system
"
               "directory or in the program's directory.\n");
    }

    //get the adress of the AVRun function 
    AVRun = (AVRUN) GetProcAddress(ArcviewDLL, "AVRun");

    //================================== Start MPI
=======================================//
    //MPI : Declar Variables
    int my_rank;                                // Rank of process 
    int num_proc;                                // Number of processers
                                
    //MPI : Initialize
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
    MPI_Comm_size(MPI_COMM_WORLD, &num_proc);


    // -------- master Program ----------------//
    if (my_rank==0)     // Master processor
    {
        //-------------Start call dll --------------//      
        ArcviewDLL= LoadLibraryA("Avhelp.dll");   
        AVRun = (AVRUN) GetProcAddress(ArcviewDLL, "AVRun");
        std::cout<<"Start Calling DLL"<<std::endl;
        AVRun("av.run(\"HAO_script3\",\"\")");
        std::cout<<"End Calling DLL"<<std::endl;

        //MasterWork_MPI();
        //-------------End call dll---------------//
    }

    // --------slave Program ------------------//
    else
    {        
        //SlaveWork_MPI();
    }

    MPI_Finalize(); 

    //================================ End MPI
====================================//
    return 0;
}

    
Vivian
12/05/2008




On Fri, Dec 5, 2008 at 10:03 AM, Jayesh Krishna <jayesh at mcs.anl.gov>
wrote:


Hi,
 Can you send us a sample test program that fails ?
 
Regards,
Jayesh


  _____  

From: mpich-discuss-bounces at mcs.anl.gov
[mailto:mpich-discuss-bounces at mcs.anl.gov] On Behalf Of Vivian
Sent: Friday, December 05, 2008 12:05 AM
To: mpich-discuss at mcs.anl.gov
Subject: [mpich-discuss] problem of calling .dll in mpich


Hi,
      I met some problems when I was trying to call a dll in a mpich
program (Language:VS 2005).
      (1) MPICH seems to only support calling convention  _cdecl. 
          When I change the project setting to _stdcall, the code cannot
be successfully built.
          So I set the project setting back to _cdecl and force the
calling convention of the function pointer to my function on the DLL to be
"_stdcall". This time the program is built. 
          Under debugging mode or directly run in command window (
c:>test.ext), there is no problem to call dll in the code.
          Here is the code:
 
--------------------------------------------------------------------------
------ 
     typedef char (__stdcall *AVRUN) (char[100]);  
     HINSTANCE ArcviewDLL;  
     AVRUN AVRun;
     ArcviewDLL= LoadLibraryA("Avhelp.dll");    
     AVRun = (AVRUN) GetProcAddress(ArcviewDLL, "AVRun");

    AVRun("av.run(\"HAO_script3\",\"\")");
 
--------------------------------------------------------------------------
-----

      (2) However, the program fails to call dll when I use "mpiexec" to
run it. (c:>mpiexec -n 1 test.exe).
           It seems to "stop" right before this line
  -------------------------------------------------------------
    AVRun("av.run(\"HAO_script3\",\"\")");
  -------------------------------------------------------------
          Is there anyone having any idea why this happens?

--
Vivian



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20081208/78b8128a/attachment.htm>


More information about the mpich-discuss mailing list