Guest User

Untitled

a guest
Sep 17th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. How to access MySQL from MPI program (use MPICH2)?
  2. #include <stdio.h>
  3. #include <windows.h>
  4. #include <mysql.h>
  5. #include <iostream>
  6. #include <winsock.h>
  7. #include <mpi.h>
  8. #include <stdlib.h>
  9.  
  10. using namespace std;
  11.  
  12. //namespace for error handling
  13. namespace ekception{
  14. struct error{
  15. const char *p;
  16. error(const char *q){
  17. p=q;
  18. }
  19. };
  20. }
  21.  
  22. int main(int argc, char *argv[]){
  23. MYSQL mysql,*sock;
  24. MYSQL_RES *res;
  25. int state;
  26. char *host="localhost";
  27. char *user="root";
  28. char *password="";
  29. char *dbName="sp";
  30. double start,finish,time;
  31. long j;
  32. char s[]="SELECT COUNT(kolom2) FROM coba WHERE kolom1<=";
  33. char query[BUFSIZ];
  34.  
  35. MPI_Init(&argc,&argv);
  36.  
  37. for(j=250000;j<=25000000;j+=250000){
  38. sprintf_s(query,"%s%d",s,j);
  39. start=MPI_Wtime();
  40. try{
  41. mysql_init(&mysql);
  42. if(!(sock=mysql_real_connect(&mysql,host,user,password,dbName,0,NULL,0))){
  43. throw ekception::error("Connection failedn");
  44. }
  45. mysql.reconnect=1;
  46.  
  47. state=mysql_query(sock,query);
  48.  
  49. if(state!=0){
  50. throw ekception::error("Query execution Failedn");
  51. }
  52.  
  53. res=mysql_store_result(sock);
  54. mysql_free_result(res);
  55. mysql_close(sock);
  56. }
  57.  
  58. catch(ekception::error e){
  59. printf("%sn",e.p);
  60. }
  61.  
  62. finish=MPI_Wtime();
  63. time=finish-start;
  64. printf("Data size = %d *** time = %fn",j,time);
  65. }
  66.  
  67. MPI_Finalize();
  68. getchar();
  69. return 0;
  70. }
  71.  
  72. int id, nprocs;
  73.  
  74. MPI_Comm_rank(MPI_COMM_WORLD, &id);
  75. MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
  76.  
  77. printf("Sql Init from proc %d out of %d!n", id, nprocs);
Add Comment
Please, Sign In to add comment