Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to access MySQL from MPI program (use MPICH2)?
- #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 failedn");
- }
- mysql.reconnect=1;
- state=mysql_query(sock,query);
- if(state!=0){
- throw ekception::error("Query execution Failedn");
- }
- res=mysql_store_result(sock);
- mysql_free_result(res);
- mysql_close(sock);
- }
- catch(ekception::error e){
- printf("%sn",e.p);
- }
- finish=MPI_Wtime();
- time=finish-start;
- printf("Data size = %d *** time = %fn",j,time);
- }
- MPI_Finalize();
- getchar();
- return 0;
- }
- 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);
Add Comment
Please, Sign In to add comment