[mpich-discuss] No output from accessing database

Titianingrum - 08.5831 at stis.ac.id
Tue Jul 3 17:02:15 CDT 2012


Hello All,

I tray to access database (use MySQL) from MPI program.
It's run well from Visual Studio and have output. If use mpiexec, it's
run but no output.

*Before added by mysql_init and other MySQL code, there is output (use mpiexec).

Thanks in advance.

-- 
titia
-------------- next part --------------
#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);

	printf("Before MySQL initiation\n");

	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;
}


More information about the mpich-discuss mailing list