
[英]How to have a deadlock scenario with boost MPI (I use MPICH compiler)?
[英]How to access MySQL from MPI program (use MPICH2)?
我有一个庞大的数据库(DBMS = MySQL),可以从MPI程序(使用MPICH2)访问。 在此程序中,我只想了解执行sql查询的时间。 它引用了我的其他并行程序。
从Visual Studio C ++运行代码时,它运行良好(我得到了输出)。 但是使用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;
}
提前致谢
我建议以下内容:
添加以下内容以查看您是否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);
的返回类型mysql_init(&mysql);
3。 出于调试目的,您可以在MPI_Init()
调用之后立即添加getchar()
,以便启动两个进程(假设mpirun/mpiexec
的进程数参数为2)。 然后,您可以在MVS attach debugger
窗口中看到两个进程的processid。 然后,您可以将调试器附加到MPI子进程之一,并查看给定mpi子进程的sql
查询执行失败的原因。
4。 不知道为什么需要在for循环中打开/关闭sql socket
。 ? 它可以在for
循环之外。
5。 交叉检查您的程序是否真的与适当的mpi lib链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.