Re: Concurrent processes
- From: Valery Avaux <vavaux ulb ac be>
- To: Joshua Horvath <Josh_Horvath-AJH051 email mot com>
- Cc: gtk-list gnome org
- Subject: Re: Concurrent processes
- Date: Wed, 04 Apr 2001 00:29:05 +0200
I don't really need to have totally threaded functions but I would like
to be able to change the values of two parameters while the main part of
the simulation runs. Here follows parts of the code I currently use:
int
main (int argc, char *argv[])
{
GtkWidget *temper;
GtkWidget *magnfield;
GtkWidget *kind;
#ifdef ENABLE_NLS
bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
textdomain (PACKAGE);
#endif
gtk_set_locale ();
gtk_init (&argc, &argv);
add_pixmap_directory (PACKAGE_DATA_DIR "/pixmaps");
add_pixmap_directory (PACKAGE_SOURCE_DIR "/pixmaps");
/*
* The following code was added by Glade to create one of each
component
* (except popup menus), just so that you see something after building
* the project. Delete any components that you don't want shown
initially.
*/
initmat();
finitesize();
window1 = create_window1 ();
gtk_widget_show (window1);
temper = lookup_widget (window1, "tempsc");
magnfield = lookup_widget (window1, "hscale2");
kind = lookup_widget (window1, "combo1");
gtk_signal_connect (GTK_OBJECT (GTK_RANGE(temper) -> adjustment),
"value_changed", GTK_SIGNAL_FUNC ( on_tempsc_value_changed), temper);
gtk_signal_connect (GTK_OBJECT (GTK_RANGE(magnfield) -> adjustment),
"value_changed", GTK_SIGNAL_FUNC (on_hscale2_value_changed),magnfield);
gtk_signal_connect (GTK_OBJECT (GTK_COMBO(kind)-> entry),"activate",
GTK_SIGNAL_FUNC
(on_combo_entry1_changed),NULL);
gtk_main ();
return 0;
}
void
on_tempsc_value_changed (GtkAdjustment *adj,
GtkRange *scrollbar)
{
temp = gtk_range_get_adjustment (scrollbar) -> value;
printf("temp changed %f\n", temp);
}
void
on_hscale2_value_changed (GtkAdjustment *adj,
GtkRange *scrollbar)
{
field = gtk_range_get_adjustment (scrollbar) -> value;
printf("field changed %f\n",field);
}
void
on_run_clicked (GtkButton *button,
gpointer user_data)
{
/* variables locales */
int i,j;
FILE *ifp;
float s;
ifp = fopen("result.dat","w");
s=magnet();
if (genre == 1)
for (i=0; i<nbsweep; ++i)
{
for (j=0; j<nbflip; ++j)
{
isingflip1();
}
s=magnet();
fprintf(ifp, "%d %f\n",i,s);
}
if (genre == 2)
for (i=0; i<nbsweep; ++i)
{
for (j=0; j<nbflip; ++j)
{
isingflip1();
}
s=magnet();
fprintf(ifp, "%d %f\n",i,s);
}
if (genre == 3)
for (i=0; i<nbsweep; ++i)
{
for (j=0; j<nbflip; ++j)
{
isingflip2();
}
s=magnet();
fprintf(ifp, "%d %f\n",i,s);
}
if (genre == 4)
for (i=0; i<nbsweep; ++i)
{
for (j=0; j<nbflip; ++j)
{
isingflip2();
}
s=magnet();
fprintf(ifp, "%d %f\n",i,s);
}
fclose(ifp);
}
void isingflip1()
{
/* variables locales */
unsigned int locx,locy,locz;
float value1, value2,choice,compar;
int deltae;
/* determination des ccordonees */
value1 = rand() / 2147483647.0;
value2 = value1 * tx;
locx = 1+floor(value2);
value1 =rand() /2147483647.0;
value2 = value1 *ty;
locy = 1+floor(value2);
value1= rand() / 2147483647.0;
value2= value1 * tz;
locz = 1+floor(value2);
/* calcul du changement d'energie */
deltae =
2.*matrice[locx][locy][locz]*(matrice[locx+1][locy][locz]+matrice[locx-1][locy][locz]+
matrice[locx][locy+1][locz]+matrice[locx][locy-1][locz]+matrice[locx][locy][locz+1]+matrice[locx][locy][locz-1])
+ 2.*field*matrice[locx][locy][locz];
/* calcul de probabilité */
if (deltae <0)
{
matrice[locx][locy][locz]=-matrice[locx][locy][locz];
}
else
{
choice = exp(-deltae/temp);
compar = rand() / 2147483647.0;
if (compar < choice)
{
matrice[locx][locy][locz]=-matrice[locx][locy][locz];
}
}
}
with nbsweep between 1000 and 1000000, nbflip between 1 and 50, temp
between 0 and 500, field between -20.0 et 20.0 (these two should change
while running) and matrice is define like this matrice[102][102][102]
So when run is clicked, it makes a lot of calculations...... and I can't
change any parameters until calculations are done.....
I could try your suggestion: while(gtk_events_pending())
gtk_main_interation(), but I don't see where and who to do this... If
you could tell me....
Thanks a lot
Valery Avaux
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]