Changeset 3200

Show
Ignore:
Timestamp:
09/28/08 14:30:23 (18 months ago)
Author:
gropp
Message:

Added initial steps toward fine grain threading in the ch3 device

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • mpich2/trunk/src/mpid/ch3/include/mpidimpl.h

    r3065 r3200  
    230230{                                                               \ 
    231231    int incomplete__;                                           \ 
     232    MPIU_THREAD_CS_ENTER(MPIDCOMM,);                            \ 
    232233                                                                \ 
    233234    MPIDI_CH3U_Request_decrement_cc((req_), &incomplete__);     \ 
     
    237238        MPIDI_CH3_Progress_signal_completion();                 \ 
    238239    }                                                           \ 
     240    MPIU_THREAD_CS_EXIT(MPIDCOMM,);                             \ 
    239241} 
    240242 
     
    637639    int (* sendNoncontig_fn)( struct MPIDI_VC *vc, struct MPID_Request *sreq, 
    638640                              void *header, MPIDI_msg_sz_t hdr_sz ); 
    639      
     641 
     642#ifdef MPICH_IS_THREADED     
     643#if MPIU_THREAD_GRANULARITY == MPIU_THREAD_GRANULARITY_PER_OBJECT 
     644    MPID_Thread_mutex_t pobj_mutex; 
     645#endif 
     646#endif 
    640647    /* Rather than have each channel define its own fields for the  
    641648       channel-specific data, we provide a fixed-sized scratchpad.  Currently, 
     
    10821089#endif 
    10831090 
     1091/* The following is part of an implementation of a control of a  
     1092   resource shared among threads - it needs to be managed more  
     1093   explicitly as such as shared resource */ 
    10841094#ifndef MPICH_IS_THREADED 
    10851095#   define MPIDI_CH3_Progress_signal_completion()       \ 
     
    16931703int MPIDI_CH3_ReqHandler_GetSendRespComplete( MPIDI_VC_t *, MPID_Request *, 
    16941704                                              int * ); 
     1705/* Thread Support */ 
     1706#ifdef MPICH_IS_THREADED 
     1707#if MPIU_THREAD_GRANULARITY == MPIU_THREAD_GRANULARITY_GLOBAL 
     1708/* There is a single, global lock, held for the duration of an MPI call */ 
     1709#define MPIU_THREAD_CS_ENTER_CH3COMM(_context) 
     1710#define MPIU_THREAD_CS_EXIT_CH3COMM(_context) 
     1711 
     1712/* FIXME: Currently forcing the PER_OBJECT case to do a global 
     1713 * lock. We need a better way of fixing this. */ 
     1714#elif MPIU_THREAD_GRANULARITY == MPIU_THREAD_GRANULARITY_BRIEF_GLOBAL 
     1715/* There is a single, global lock, held only when needed */ 
     1716#define MPIU_THREAD_CS_ENTER_CH3COMM(_context) \ 
     1717   MPIU_THREAD_CHECK_BEGIN MPIU_THREAD_CS_ENTER_LOCKNAME(global_mutex) MPIU_THREAD_CHECK_END 
     1718#define MPIU_THREAD_CS_EXIT_CH3COMM(_context) \ 
     1719   MPIU_THREAD_CHECK_BEGIN MPIU_THREAD_CS_EXIT_LOCKNAME(global_mutex) MPIU_THREAD_CHECK_END 
     1720 
     1721#elif MPIU_THREAD_GRANULARITY == MPIU_THREAD_GRANULARITY_PER_OBJECT 
     1722#if 1 
     1723/* There is a per object lock */ 
     1724#define dprintf(...) 
     1725#define MPIU_THREAD_CS_ENTER_CH3COMM(_context) {\ 
     1726   dprintf("Entering lock in %s\n", __FUNCTION__); \ 
     1727   MPIU_THREAD_CHECK_BEGIN MPIU_THREAD_CS_ENTER_POBJ_LOCKNAME(_context->pobj_mutex) MPIU_THREAD_CHECK_END \ 
     1728} 
     1729#define MPIU_THREAD_CS_EXIT_CH3COMM(_context) \ 
     1730   MPIU_THREAD_CHECK_BEGIN MPIU_THREAD_CS_EXIT_POBJ_LOCKNAME(_context->pobj_mutex) MPIU_THREAD_CHECK_END 
     1731 
     1732#if 1 
     1733static void foofunc() { } 
     1734#define MPIU_THREAD_CS_TRYLOCK(_context) {\ 
     1735   MPIU_THREAD_CHECK_BEGIN \ 
     1736   int ret; \ 
     1737   ret = pthread_mutex_trylock(&_context->pobj_mutex); \ 
     1738   if (!ret) { \ 
     1739       printf("Trylock successful for pobj mutex\n"); \ 
     1740       pthread_mutex_unlock(&_context->pobj_mutex); \ 
     1741   } \ 
     1742   else if (ret != EBUSY) { \ 
     1743       printf("Error in pobj_mutex: %d\n", ret); \ 
     1744   } \ 
     1745   ret = pthread_mutex_trylock(&MPIR_ThreadInfo.global_mutex); \ 
     1746   if (ret) { \ 
     1747       foofunc(); \ 
     1748       printf("Trylock not successful for global mutex\n"); \ 
     1749   } \ 
     1750   else if (!ret) { \ 
     1751       pthread_mutex_unlock(&MPIR_ThreadInfo.global_mutex); \ 
     1752   } \ 
     1753   else if (ret != EBUSY) { \ 
     1754       printf("Error in global mutex: %d\n", ret); \ 
     1755   } \ 
     1756   ret = pthread_mutex_trylock(&MPIR_ThreadInfo.handle_mutex); \ 
     1757   if (ret) { \ 
     1758       printf("Trylock not successful for handle mutex\n"); \ 
     1759       pthread_mutex_unlock(&MPIR_ThreadInfo.handle_mutex); \ 
     1760   } \ 
     1761   else if (!ret) { \ 
     1762       pthread_mutex_unlock(&MPIR_ThreadInfo.handle_mutex); \ 
     1763   } \ 
     1764   else if (ret != EBUSY) { \ 
     1765       printf("Error in global mutex: %d\n", ret); \ 
     1766   } \ 
     1767   MPIU_THREAD_CHECK_END \ 
     1768} 
     1769#else 
     1770#define MPIU_THREAD_CS_TRYLOCK(_context) 
     1771#endif 
     1772 
     1773#else 
     1774/* There is a single, global lock, held only when needed */ 
     1775#define MPIU_THREAD_CS_ENTER_CH3COMM(_context) \ 
     1776   MPIU_THREAD_CHECK_BEGIN MPIU_THREAD_CS_ENTER_LOCKNAME(global_mutex) MPIU_THREAD_CHECK_END 
     1777#define MPIU_THREAD_CS_EXIT_CH3COMM(_context) \ 
     1778   MPIU_THREAD_CHECK_BEGIN MPIU_THREAD_CS_EXIT_LOCKNAME(global_mutex) MPIU_THREAD_CHECK_END 
     1779#endif 
     1780 
     1781#elif MPIU_THREAD_GRANULARITY == MPIU_THREAD_GRANULARITY_LOCK_FREE 
     1782/* Updates to shared data and access to shared services is handled without  
     1783   locks where ever possible. */ 
     1784#error lock-free not yet implemented 
     1785 
     1786#elif MPIU_THREAD_GRANULARITY == MPIU_THREAD_GRANULARITY_SINGLE 
     1787/* No thread support, make all operations a no-op */ 
     1788 
     1789#else 
     1790#error Unrecognized thread granularity 
     1791#endif 
     1792#else 
     1793 
     1794#endif /* MPICH_IS_THREADED */ 
    16951795 
    16961796#endif /* !defined(MPICH_MPIDIMPL_H_INCLUDED) */