projects
/
physik
/
posic.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
pthreads implemented (fucking slow!)
[physik/posic.git]
/
moldyn.c
diff --git
a/moldyn.c
b/moldyn.c
index
d7d89bc
..
c27fc62
100644
(file)
--- a/
moldyn.c
+++ b/
moldyn.c
@@
-47,6
+47,12
@@
#undef PSE_NAME
#undef PSE_COL
#undef PSE_NAME
#undef PSE_COL
+#ifdef PTHREADS
+/* global mutexes */
+pthread_mutex_t *amutex;
+pthread_mutex_t emutex;
+#endif
+
/*
* the moldyn functions
*/
/*
* the moldyn functions
*/
@@
-66,13
+72,27
@@
int moldyn_init(t_moldyn *moldyn,int argc,char **argv) {
rand_init(&(moldyn->random),NULL,1);
moldyn->random.status|=RAND_STAT_VERBOSE;
rand_init(&(moldyn->random),NULL,1);
moldyn->random.status|=RAND_STAT_VERBOSE;
+#ifdef PTHREADS
+ pthread_mutex_init(&emutex,NULL);
+#endif
+
return 0;
}
int moldyn_shutdown(t_moldyn *moldyn) {
return 0;
}
int moldyn_shutdown(t_moldyn *moldyn) {
+#ifdef PTHREADS
+ int i;
+#endif
+
printf("[moldyn] shutdown\n");
printf("[moldyn] shutdown\n");
+#ifdef PTHREADS
+ for(i=0;i<moldyn->count;i++)
+ pthread_mutex_destroy(&(amutex[i]));
+ pthread_mutex_destroy(&emutex);
+#endif
+
moldyn_log_shutdown(moldyn);
link_cell_shutdown(moldyn);
rand_close(&(moldyn->random));
moldyn_log_shutdown(moldyn);
link_cell_shutdown(moldyn);
rand_close(&(moldyn->random));
@@
-500,6
+520,9
@@
int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass,
void *ptr;
t_atom *atom;
char name[16];
void *ptr;
t_atom *atom;
char name[16];
+#ifdef PTHREADS
+ pthread_mutex_t *mutex;
+#endif
new=a*b*c;
count=moldyn->count;
new=a*b*c;
count=moldyn->count;
@@
-522,6
+545,16
@@
int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass,
moldyn->atom=ptr;
atom=&(moldyn->atom[count]);
moldyn->atom=ptr;
atom=&(moldyn->atom[count]);
+#ifdef PTHREADS
+ ptr=realloc(amutex,(count+new)*sizeof(pthread_mutex_t));
+ if(!ptr) {
+ perror("[moldyn] mutex realloc (add atom)");
+ return -1;
+ }
+ amutex=ptr;
+ mutex=&(amutex[count]);
+#endif
+
/* no atoms on the boundaries (only reason: it looks better!) */
if(!origin) {
orig.x=0.5*lc;
/* no atoms on the boundaries (only reason: it looks better!) */
if(!origin) {
orig.x=0.5*lc;
@@
-579,6
+612,9
@@
int create_lattice(t_moldyn *moldyn,u8 type,double lc,int element,double mass,
atom[ret].tag=count+ret;
check_per_bound(moldyn,&(atom[ret].r));
atom[ret].r_0=atom[ret].r;
atom[ret].tag=count+ret;
check_per_bound(moldyn,&(atom[ret].r));
atom[ret].r_0=atom[ret].r;
+#ifdef PTHREADS
+ pthread_mutex_init(&(mutex[ret]),NULL);
+#endif
}
/* update total system mass */
}
/* update total system mass */
@@
-613,6
+649,16
@@
int add_atom(t_moldyn *moldyn,int element,double mass,u8 brand,u8 attr,
moldyn->lc.subcell->list=ptr;
#endif
moldyn->lc.subcell->list=ptr;
#endif
+#ifdef PTHREADS
+ ptr=realloc(amutex,(count+1)*sizeof(pthread_mutex_t));
+ if(!ptr) {
+ perror("[moldyn] mutex realloc (add atom)");
+ return -1;
+ }
+ amutex=ptr;
+ pthread_mutex_init(&(amutex[count]),NULL);
+#endif
+
atom=moldyn->atom;
/* initialize new atom */
atom=moldyn->atom;
/* initialize new atom */