2

我有从 MPI 程序(使用 MPICH2)访问的巨大数据库(DBMS = MySQL)。在这个程序中,我只想知道执行 sql 查询的时间。这是对我的其他并行程序的参考。

当代码从 Visual Studio C++ 运行时,它运行良好(我得到了输出)。但是当它 runed use 时mpiexec,没有输出,也没有错误消息。否则,当我尝试一个简单的程序(没有mysql代码,使用mpiexec)时,它运行良好(有输出)。我不应该同时使用 mysql 和 mpi 库吗?

像这样的代码:

#include <stdio.h>
#include <windows.h>
#include <mysql.h>
#include <iostream>
#include <winsock.h>
#include <mpi.h>
#include <stdlib.h>

using namespace std;

//namespace for error handling
namespace ekception{
        struct error{
        const char *p;
        error(const char *q){
        p=q;
        }
    };
}

int main(int argc, char *argv[]){
    MYSQL mysql,*sock;
    MYSQL_RES *res;
    int state;
    char *host="localhost";
    char *user="root";
    char *password="";
    char *dbName="sp";
    double start,finish,time;
    long j;
    char s[]="SELECT COUNT(kolom2) FROM coba WHERE kolom1<=";
    char query[BUFSIZ];

    MPI_Init(&argc,&argv);

    for(j=250000;j<=25000000;j+=250000){
    sprintf_s(query,"%s%d",s,j);
    start=MPI_Wtime();
    try{
        mysql_init(&mysql); 
        if(!(sock=mysql_real_connect(&mysql,host,user,password,dbName,0,NULL,0))){
            throw ekception::error("Connection failed\n");
        }
        mysql.reconnect=1;

        state=mysql_query(sock,query);

        if(state!=0){
            throw ekception::error("Query execution Failed\n");
        }

        res=mysql_store_result(sock);
        mysql_free_result(res);
        mysql_close(sock);
    }

    catch(ekception::error e){
        printf("%s\n",e.p);
    }

    finish=MPI_Wtime();
    time=finish-start;
    printf("Data size = %d *** time = %f\n",j,time);
}

MPI_Finalize();
getchar();
return 0;
}

提前致谢

4

2 回答 2

0

我建议如下:

  1. 添加以下内容以查看您是否really在 MPI 框架中运行:

    int id, nprocs;
    
    MPI_Comm_rank(MPI_COMM_WORLD, &id);
    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
    
    printf("Sql Init from proc %d out of %d!\n", id, nprocs);
    

我将打印排名 ID 作为所有日志语句的一部分,以便识别打印语句从哪个 MPI 子进程开始。

2. 可以肯定的是,我宁愿检查返回类型mysql_init(&mysql);

3. 出于调试目的,您可以getchar()在调用之后添加一个,MPI_Init()以便启动两个进程(假设mpirun/mpiexec进程数参数为 2)。然后,您可以在 MVSattach debugger窗口中看到两个进程的 processid。然后,您可以将调试器附加到其中一个 MPI 子进程,并查看sql给定 mpi 子进程的查询执行失败的原因。

4. 不知道为什么需要打开/关闭sql socketfor 循环内部。? 它可以在for循环之外。

5. 交叉检查您的程序是否真的与适当的 mpi lib 链接。

于 2012-07-04T00:56:30.623 回答
0
  1. 我们可以同时使用 mysql 和 mpi 库,这是真的。
  2. 在这个问题上,可能会导致大量数据(但我不确定)。也许用于保存来自 mysql 查询的数据的 MYSQL_RES 的大小不够。
于 2012-09-19T20:45:06.570 回答