Hello all,
i am programming using MPICH + C++ and Gtk. I using Gtk to create the interactive interface (frontend), by which users can specify afile to be processed by the parallelized program coded in MPICH and C++ (backend).
My problem arised with the combination of the three programming languages.
On the GUI, there is a button to bring up a File Open dialog for user selecting a file from the file system. The path of the selected filewill be displayed in a text box. Once users have selected a file Users can pass the file name to the parallelized program by click another button (Execution Button).
In current design, the GUI is only used with one processor 'processor-0'. That is, 'processor-0' is responsible to accept users' input of the selected fileThen, it MPI_Bcast() the file path to other processors. As soon as ALL processors receive the file path, the parallelized process starts.
I can sucessfully bring up the GUI and select a file, showing the file path on the text box. However, when I press the Execution button, the parallelized process cannot continue unless I close the GUI. It seems that the execution control held by the Gtk program failed to be shifted to the parallelized program.
the code is as follows:
GtkWidget *QueryWord;char Query_FileName[300] = "";
// ###### button2_click for assign the content of QueryWord to the global variable Query_FileNamegint button2_click(GtkWidget *widget,gpointer gdata){ printf("I am here %d %s %s!\n", sizeof(gdata), gdata, (char *)gtk_entry_get_text(GTK_ENTRY(QueryWord))); strcpy(Query_FileName , (char *)gtk_entry_get_text(GTK_ENTRY(QueryWord))); return(FALSE);}// button_click for bring up the File Open dialog for selecting a file to be processedgint button_click(GtkWidget *widget,gpointer gdata){ GtkWidget *dialog; dialog = gtk_file_chooser_dialog_new ("Open File", GTK_WINDOW(gdata), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { char *filename; filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); gtk_entry_set_text(GTK_ENTRY(QueryWord), g_locale_to_utf8(filename,-1,NULL,NULL,NULL)); printf("%s\n", filename); g_free (filename); } gtk_widget_destroy (dialog
); return(FALSE);}
int main(int argc, char *argv[]){
int i; int myid, numprocs; char Query_FileName[1000]=""; double startwtime = 0.0, endwtime; int namelen; char processor_name[MPI_MAX_PROCESSOR_NAME]; MPI_Init(&argc,&argv); //MPI MPI_Comm_size(MPI_COMM_WORLD,&numprocs); //MPI MPI_Comm_rank(MPI_COMM_WORLD,&myid); //MPI MPI_Get_processor_name(processor_name,&namelen); //MPI
if (myid ==0) { GtkWidget *window; GtkWidget *table; /*Table*/ GtkWidget *button, *button2; /*Button */ GtkWidget *label; gtk_init(&argc, &argv);//<============================================================ window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_set_size_request(window,1000,800); g_signal_connect(GTK_OBJECT(window),"destroy",G_CALLBACK(gtk_main_quit),NULL); table=gtk_table_new(8,8,TRUE); /*create a new table*/ QueryWord=gtk_entry_new();/*create a text box*/ gtk_table_attach(GTK_TABLE(table), QueryWord,1,7,1,2,GTK_FILL,GTK_FILL,0,0);/*add label*/ gtk_widget_show(QueryWord);; /*show label*/ button=gtk_button_new_with_label(g_locale_to_utf8("SEAsea",-1,NULL,NULL,NULL)); gtk_table_attach(GTK_TABLE(table),button,2,4,2,3,GTK_FILL,GTK_FILL,0,0); gtk_widget_show(button); gtk_signal_connect(GTK_OBJECT(button),"clicked",GTK_SIGNAL_FUNC(button_click),window); button2=gtk_button_new_with_label(g_locale_to_utf8("Ocean",-1,NULL,NULL,NULL)); gtk_table_attach
(GTK_TABLE(table),button2,5,7,2,3,GTK_FILL,GTK_FILL,0,0); gtk_widget_show(button2); gtk_signal_connect(GTK_OBJECT(button2),"clicked",GTK_SIGNAL_FUNC(button2_click),(void*)gtk_entry_get_text(GTK_ENTRY(QueryWord))); gtk_container_add(GTK_CONTAINER(window),table); /*add table to window*/ gtk_widget_show(table); /*show table*/ gtk_widget_show(window); gtk_main();// it seems that the solution to this question is to find a way of how to shift between gtk_main() and main(int argc, char *argv[])
} if(myid == 0) { while(1)// wait Query_FileName is assigned by the user on GUI { if(strlen(Query_FileName) > 0) { MPI_Bcast( Query_FileName, strlen(Query_FileName), MPI_CHAR, 0, MPI_COMM_WORLD );/*processor-0 broadcast*/ break; } } } else {
while(1) //wait processor-0 broadcast Query_FileName { if(strlen(Query_FileName) == 0) { MPI_Bcast( Query_FileName, strlen(Query_FileName), MPI_CHAR, 0, MPI_COMM_WORLD );/*processor-xxx receive data*/
} else { break; } } }
_________________________________________________________________
ÖйúÊ®´óÈÈÃÅÂÃÓξ°µã
http://search.msn.com/results.aspx?q=%E4%B8%AD%E5%9B%BD%E5%8D%81%E5%A4%A7%E9%A3%8E%E6%99%AF&mkt=zh-CN&form=QBRE
|