diff --git a/INCLUDE/counter.h b/INCLUDE/counter.h index 92719a1..103ba94 100644 --- a/INCLUDE/counter.h +++ b/INCLUDE/counter.h @@ -51,7 +51,11 @@ typedef struct { int value; +#ifdef NOSPINLOCKS + pthread_mutex_t lock; +#else pthread_spinlock_t lock; +#endif } counter_t; counter_t *PMR_create_counter(int init_value); diff --git a/INCLUDE/queue.h b/INCLUDE/queue.h index 54ad939..b4da63b 100644 --- a/INCLUDE/queue.h +++ b/INCLUDE/queue.h @@ -62,7 +62,11 @@ typedef struct { int num_tasks; task_t *head; task_t *back; +#ifdef NOSPINLOCKS + pthread_mutex_t lock; +#else pthread_spinlock_t lock; +#endif } queue_t; diff --git a/INSTALL/make.inc.gnu b/INSTALL/make.inc.gnu index 7359e14..73a6b39 100644 --- a/INSTALL/make.inc.gnu +++ b/INSTALL/make.inc.gnu @@ -16,6 +16,10 @@ ARFLAGS = rcs # to 0 by default COMPLEX_SUPPORT = 0 -# Compile routines without adding necessary LAPACK routines -# to 'libmrrr.a'; default = 0 -NOLAPACK = 0 \ No newline at end of file +# To build 'libmrrr.a' without adding necessary LAPACK routines +# for the to the archive set value to 0; default value is 1 +INCLAPACK = 1 + +# On some systems 'spinlocks' are not supported, therefore +# here the flag to use 'mutexes' instead; default value is 1 +SPINLOCK_SUPPORT = 1 \ No newline at end of file diff --git a/INSTALL/make.inc.ibm b/INSTALL/make.inc.ibm index adeacaa..0adbd39 100644 --- a/INSTALL/make.inc.ibm +++ b/INSTALL/make.inc.ibm @@ -16,6 +16,10 @@ ARFLAGS = rcs # to 0 by default COMPLEX_SUPPORT = 0 -# Compile routines without adding necessary LAPACK routines -# to 'libmrrr.a'; default = 0 -NOLAPACK = 0 +# To build 'libmrrr.a' without adding necessary LAPACK routines +# for the to the archive set value to 0; default value is 1 +INCLAPACK = 1 + +# On some systems 'spinlocks' are not supported, therefore +# here the flag to use 'mutexes' instead; default value is 1 +SPINLOCK_SUPPORT = 1 \ No newline at end of file diff --git a/INSTALL/make.inc.intel b/INSTALL/make.inc.intel index 79bbd1c..d6a699d 100644 --- a/INSTALL/make.inc.intel +++ b/INSTALL/make.inc.intel @@ -4,7 +4,7 @@ FC = ifort # Compiler flags CFLAGS = -pthread -O3 -restrict -FFLAGS = -nofor-main -O3 +FFLAGS = -nofor-main -O3 -assume underscore # Archiver and flags used when building the archive AR = /usr/bin/ar @@ -16,6 +16,10 @@ ARFLAGS = rcs # to 0 by default COMPLEX_SUPPORT = 0 -# Compile routines without adding necessary LAPACK routines -# to 'libmrrr.a'; default = 0 -NOLAPACK = 0 +# To build 'libmrrr.a' without adding necessary LAPACK routines +# for the to the archive set value to 0; default value is 1 +INCLAPACK = 1 + +# On some systems 'spinlocks' are not supported, therefore +# here the flag to use 'mutexes' instead; default value is 1 +SPINLOCK_SUPPORT = 1 \ No newline at end of file diff --git a/Makefile b/Makefile index 37dabb3..8f70b89 100644 --- a/Makefile +++ b/Makefile @@ -9,12 +9,16 @@ ifeq ($(COMPLEX_SUPPORT),1) CFLAGS += -DCOMPLEX_SUPPORTED endif +ifeq ($(SPINLOCK_SUPPORT),0) + CFLAGS += -DNOSPINLOCKS +endif + # Source files HEADERS := $(foreach DIR,$(DIRS),$(wildcard $(DIR)/*.h)) CSRCS := $(foreach DIR,$(DIRS),$(wildcard $(DIR)/*.c)) COBJS = $(CSRCS:.c=.o) -ifeq ($(NOLAPACK),1) +ifeq ($(INCLAPACK),0) FSRCS := $(foreach DIR,$(DIRS),$(wildcard $(DIR)/odscal.f)) FOBJS = $(FSRCS:.f=.o) else diff --git a/SRC/counter.c b/SRC/counter.c index 5327383..f59c58d 100644 --- a/SRC/counter.c +++ b/SRC/counter.c @@ -59,7 +59,11 @@ counter_t *PMR_create_counter(int init_value) counter = (counter_t *) malloc( sizeof(counter_t) ); counter->value = init_value; +#ifdef NOSPINLOCKS + info = pthread_mutex_init(&counter->lock, NULL); +#else info = pthread_spin_init(&counter->lock, PTHREAD_PROCESS_PRIVATE); +#endif assert(info == 0); return(counter); @@ -69,7 +73,11 @@ counter_t *PMR_create_counter(int init_value) inline void PMR_destroy_counter(counter_t *counter) { +#ifdef NOSPINLOCKS + pthread_mutex_destroy(&counter->lock); +#else pthread_spin_destroy(&counter->lock); +#endif free(counter); } @@ -79,12 +87,20 @@ inline int PMR_get_counter_value(counter_t *counter) { int value, info; +#ifdef NOSPINLOCKS + info = pthread_mutex_lock(&counter->lock); +#else info = pthread_spin_lock(&counter->lock); +#endif assert(info == 0); value = counter->value; +#ifdef NOSPINLOCKS + info = pthread_mutex_unlock(&counter->lock); +#else info = pthread_spin_unlock(&counter->lock); +#endif assert(info == 0); return(value); @@ -96,12 +112,20 @@ inline int PMR_set_counter_value(counter_t *counter, int value) { int info; +#ifdef NOSPINLOCKS + info = pthread_mutex_lock(&counter->lock); +#else info = pthread_spin_lock(&counter->lock); +#endif assert(info == 0); counter->value = value; +#ifdef NOSPINLOCKS + info = pthread_mutex_unlock(&counter->lock); +#else info = pthread_spin_unlock(&counter->lock); +#endif assert(info == 0); return(value); @@ -113,13 +137,21 @@ inline int PMR_decrement_counter(counter_t *counter, int amount) { int value, info; +#ifdef NOSPINLOCKS + info = pthread_mutex_lock(&counter->lock); +#else info = pthread_spin_lock(&counter->lock); +#endif assert(info == 0); counter->value -= amount; value = counter->value; +#ifdef NOSPINLOCKS + info = pthread_mutex_unlock(&counter->lock); +#else info = pthread_spin_unlock(&counter->lock); +#endif assert(info == 0); return(value); diff --git a/SRC/queue.c b/SRC/queue.c index 521c76d..73a5a97 100644 --- a/SRC/queue.c +++ b/SRC/queue.c @@ -65,7 +65,11 @@ queue_t *PMR_create_empty_queue(void) queue->head = NULL; queue->back = NULL; +#ifdef NOSPINLOCKS + info = pthread_mutex_init(&queue->lock, NULL); +#else info = pthread_spin_init(&queue->lock, PTHREAD_PROCESS_PRIVATE); +#endif assert(info == 0); return(queue); @@ -75,7 +79,11 @@ queue_t *PMR_create_empty_queue(void) void PMR_destroy_queue(queue_t *queue) { +#ifdef NOSPINLOCKS + pthread_mutex_destroy(&queue->lock); +#else pthread_spin_destroy(&queue->lock); +#endif free(queue); } @@ -85,12 +93,20 @@ int PMR_get_num_tasks(queue_t *queue) { int info, num_tasks; +#ifdef NOSPINLOCKS + info = pthread_mutex_lock(&queue->lock); +#else info = pthread_spin_lock(&queue->lock); +#endif assert(info == 0); num_tasks = queue->num_tasks; +#ifdef NOSPINLOCKS + info = pthread_mutex_unlock(&queue->lock); +#else info = pthread_spin_unlock(&queue->lock); +#endif assert(info == 0); return(num_tasks); @@ -126,7 +142,11 @@ int PMR_insert_task_at_back(queue_t *queue, task_t *task) { int info; +#ifdef NOSPINLOCKS + info = pthread_mutex_lock(&queue->lock); +#else info = pthread_spin_lock(&queue->lock); +#endif assert(info == 0); queue->num_tasks++; @@ -139,7 +159,11 @@ int PMR_insert_task_at_back(queue_t *queue, task_t *task) queue->back->next = task; queue->back = task; +#ifdef NOSPINLOCKS + info = pthread_mutex_unlock(&queue->lock); +#else info = pthread_spin_unlock(&queue->lock); +#endif assert(info == 0); return(info); @@ -152,7 +176,11 @@ task_t *PMR_remove_task_at_front(queue_t *queue) int info; task_t *task; +#ifdef NOSPINLOCKS + info = pthread_mutex_lock(&queue->lock); +#else info = pthread_spin_lock(&queue->lock); +#endif assert(info == 0); task = queue->head; @@ -171,7 +199,11 @@ task_t *PMR_remove_task_at_front(queue_t *queue) } } +#ifdef NOSPINLOCKS + info = pthread_mutex_unlock(&queue->lock); +#else info = pthread_spin_unlock(&queue->lock); +#endif assert(info == 0); return(task); @@ -185,7 +217,11 @@ task_t *PMR_remove_task_at_back (queue_t *queue) int info; task_t *task; +#ifdef NOSPINLOCKS + info = pthread_mutex_lock(&queue->lock); +#else info = pthread_spin_lock(&queue->lock); +#endif assert(info == 0); task = queue->back; @@ -204,7 +240,11 @@ task_t *PMR_remove_task_at_back (queue_t *queue) } } +#ifdef NOSPINLOCKS + info = pthread_mutex_unlock(&queue->lock); +#else info = pthread_spin_unlock(&queue->lock); +#endif assert(info == 0); return(task); diff --git a/make.inc b/make.inc index 7359e14..73a6b39 100644 --- a/make.inc +++ b/make.inc @@ -16,6 +16,10 @@ ARFLAGS = rcs # to 0 by default COMPLEX_SUPPORT = 0 -# Compile routines without adding necessary LAPACK routines -# to 'libmrrr.a'; default = 0 -NOLAPACK = 0 \ No newline at end of file +# To build 'libmrrr.a' without adding necessary LAPACK routines +# for the to the archive set value to 0; default value is 1 +INCLAPACK = 1 + +# On some systems 'spinlocks' are not supported, therefore +# here the flag to use 'mutexes' instead; default value is 1 +SPINLOCK_SUPPORT = 1 \ No newline at end of file