| 1 | /*BHEADER**********************************************************************
|
|---|
| 2 | * Copyright (c) 2008, Lawrence Livermore National Security, LLC.
|
|---|
| 3 | * Produced at the Lawrence Livermore National Laboratory.
|
|---|
| 4 | * This file is part of HYPRE. See file COPYRIGHT for details.
|
|---|
| 5 | *
|
|---|
| 6 | * HYPRE is free software; you can redistribute it and/or modify it under the
|
|---|
| 7 | * terms of the GNU Lesser General Public License (as published by the Free
|
|---|
| 8 | * Software Foundation) version 2.1 dated February 1999.
|
|---|
| 9 | *
|
|---|
| 10 | * $Revision: 2.4 $
|
|---|
| 11 | ***********************************************************************EHEADER*/
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 | #ifndef hypre_THREADING_HEADER
|
|---|
| 15 | #define hypre_THREADING_HEADER
|
|---|
| 16 |
|
|---|
| 17 | #if defined(HYPRE_USING_OPENMP) || defined (HYPRE_USING_PGCC_SMP)
|
|---|
| 18 |
|
|---|
| 19 | int hypre_NumThreads( void );
|
|---|
| 20 |
|
|---|
| 21 | #else
|
|---|
| 22 |
|
|---|
| 23 | #define hypre_NumThreads() 1
|
|---|
| 24 |
|
|---|
| 25 | #endif
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 29 | /* The pthreads stuff needs to be reworked */
|
|---|
| 30 |
|
|---|
| 31 | #ifdef HYPRE_USE_PTHREADS
|
|---|
| 32 |
|
|---|
| 33 | #ifndef MAX_QUEUE
|
|---|
| 34 | #define MAX_QUEUE 256
|
|---|
| 35 | #endif
|
|---|
| 36 |
|
|---|
| 37 | #include <pthread.h>
|
|---|
| 38 |
|
|---|
| 39 | /* hypre_work_proc_t typedef'd to be a pointer to a function with a void*
|
|---|
| 40 | argument and a void return type */
|
|---|
| 41 | typedef void (*hypre_work_proc_t)(void *);
|
|---|
| 42 |
|
|---|
| 43 | typedef struct hypre_workqueue_struct {
|
|---|
| 44 | pthread_mutex_t lock;
|
|---|
| 45 | pthread_cond_t work_wait;
|
|---|
| 46 | pthread_cond_t finish_wait;
|
|---|
| 47 | hypre_work_proc_t worker_proc_queue[MAX_QUEUE];
|
|---|
| 48 | int n_working;
|
|---|
| 49 | int n_waiting;
|
|---|
| 50 | int n_queue;
|
|---|
| 51 | int inp;
|
|---|
| 52 | int outp;
|
|---|
| 53 | void *argqueue[MAX_QUEUE];
|
|---|
| 54 | } *hypre_workqueue_t;
|
|---|
| 55 |
|
|---|
| 56 | void hypre_work_put( hypre_work_proc_t funcptr, void *argptr );
|
|---|
| 57 | void hypre_work_wait( void );
|
|---|
| 58 | int HYPRE_InitPthreads( int num_threads );
|
|---|
| 59 | void HYPRE_DestroyPthreads( void );
|
|---|
| 60 | void hypre_pthread_worker( int threadid );
|
|---|
| 61 | int ifetchadd( int *w, pthread_mutex_t *mutex_fetchadd );
|
|---|
| 62 | int hypre_fetch_and_add( int *w );
|
|---|
| 63 | void hypre_barrier(pthread_mutex_t *mpi_mtx, int unthreaded);
|
|---|
| 64 | int hypre_GetThreadID( void );
|
|---|
| 65 |
|
|---|
| 66 | pthread_t initial_thread;
|
|---|
| 67 | pthread_t hypre_thread[hypre_MAX_THREADS];
|
|---|
| 68 | pthread_mutex_t hypre_mutex_boxloops;
|
|---|
| 69 | pthread_mutex_t talloc_mtx;
|
|---|
| 70 | pthread_mutex_t worker_mtx;
|
|---|
| 71 | hypre_workqueue_t hypre_qptr;
|
|---|
| 72 | pthread_mutex_t mpi_mtx;
|
|---|
| 73 | pthread_mutex_t time_mtx;
|
|---|
| 74 | volatile int hypre_thread_release;
|
|---|
| 75 |
|
|---|
| 76 | #ifdef HYPRE_THREAD_GLOBALS
|
|---|
| 77 | int hypre_NumThreads = 4;
|
|---|
| 78 | #else
|
|---|
| 79 | extern int hypre_NumThreads;
|
|---|
| 80 | #endif
|
|---|
| 81 |
|
|---|
| 82 | #endif
|
|---|
| 83 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 84 |
|
|---|
| 85 | #endif
|
|---|