static void *call_startfn(void *vindex) { size_t index = (size_t)vindex; #if CMK_HAS_TLS_VARIABLES && !CMK_NOT_USE_TLS_THREAD if (index<_Cmi_mynodesize) CmiStateInit(index+Cmi_nodestart, index, &Cmi_mystate); else CmiStateInit(_Cmi_mynode+CmiNumPes(),_Cmi_mynodesize,&Cmi_mystate); Cmi_state_vector[index] = &Cmi_mystate; #else CmiState state = Cmi_state_vector + index; pthread_setspecific(Cmi_state_key, state); #endif ConverseRunPE(0); #if 0 if (index<_Cmi_mynodesize) ConverseRunPE(0); /*Regular worker thread*/ else { /*Communication thread*/ CommunicationServerInit(); if (Cmi_charmrun_fd!=-1) while (1) CommunicationServer(5,COM_SERVER_FROM_SMP); } #endif return 0; }
static void *call_startfn(void *vindex) { size_t index = (size_t)vindex; #if CMK_HAS_TLS_VARIABLES && !CMK_NOT_USE_TLS_THREAD if (index<_Cmi_mynodesize) CmiStateInit(index+Cmi_nodestart, index, &Cmi_mystate); else CmiStateInit(_Cmi_mynode+CmiNumPes(),_Cmi_mynodesize,&Cmi_mystate); Cmi_state_vector[index] = &Cmi_mystate; #else CmiState state = Cmi_state_vector + index; pthread_setspecific(Cmi_state_key, state); #endif ConverseRunPE(0); if(CharmLibInterOperate) { while(1) { if(!_cleanUp) { StartInteropScheduler(); CmiNodeAllBarrier(); } else { if (CmiMyRank() == CmiMyNodeSize()) { while (1) { CommunicationServerThread(5); } } else { CsdScheduler(-1); } break; } } } #if 0 if (index<_Cmi_mynodesize) ConverseRunPE(0); /*Regular worker thread*/ else { /*Communication thread*/ CommunicationServerInit(); if (Cmi_charmrun_fd!=-1) while (1) CommunicationServer(5,COM_SERVER_FROM_SMP); } #endif return 0; }
static void CmiStartThreads(char **argv) { int i,tocreate; DWORD threadID; HANDLE thr; CmiMemLock_lock=CmiCreateLock(); comm_mutex = CmiCreateLock(); barrier_mutex = CmiCreateLock(); #ifdef CMK_NO_ASM_AVAILABLE cmiMemoryLock = CmiCreateLock(); if (CmiMyNode()==0) printf("Charm++ warning> fences and atomic operations not available in native assembly\n"); #endif Cmi_state_key = TlsAlloc(); if(Cmi_state_key == 0xFFFFFFFF) PerrorExit("TlsAlloc main"); Cmi_state_vector = (CmiState)calloc(_Cmi_mynodesize+1, sizeof(struct CmiStateStruct)); for (i=0; i<_Cmi_mynodesize; i++) CmiStateInit(i+Cmi_nodestart, i, CmiGetStateN(i)); /*Create a fake state structure for the comm. thread*/ /* CmiStateInit(-1,_Cmi_mynodesize,CmiGetStateN(_Cmi_mynodesize)); */ CmiStateInit(_Cmi_mynode+CmiNumPes(),_Cmi_mynodesize,CmiGetStateN(_Cmi_mynodesize)); #if CMK_MULTICORE || CMK_SMP_NO_COMMTHD if (!Cmi_commthread) tocreate = _Cmi_mynodesize-1; else #endif tocreate = _Cmi_mynodesize; for (i=1; i<=tocreate; i++) { if((thr = CreateThread(NULL, 0, call_startfn, (LPVOID)i, 0, &threadID)) == NULL) PerrorExit("CreateThread"); CloseHandle(thr); } if(TlsSetValue(Cmi_state_key, (LPVOID)Cmi_state_vector) == 0) PerrorExit("TlsSetValue"); }
static void CmiStartThreads(char **argv) { pthread_t pid; size_t i; int ok, tocreate; pthread_attr_t attr; int start, end; MACHSTATE(4,"CmiStartThreads") CmiMemLock_lock=CmiCreateLock(); comm_mutex=CmiCreateLock(); _smp_mutex = CmiCreateLock(); #if defined(CMK_NO_ASM_AVAILABLE) && CMK_PCQUEUE_LOCK cmiMemoryLock = CmiCreateLock(); if (CmiMyNode()==0) printf("Charm++ warning> fences and atomic operations not available in native assembly\n"); #endif #if ! (CMK_HAS_TLS_VARIABLES && !CMK_NOT_USE_TLS_THREAD) pthread_key_create(&Cmi_state_key, 0); Cmi_state_vector = (CmiState)calloc(_Cmi_mynodesize+1, sizeof(struct CmiStateStruct)); for (i=0; i<_Cmi_mynodesize; i++) CmiStateInit(i+Cmi_nodestart, i, CmiGetStateN(i)); /*Create a fake state structure for the comm. thread*/ /* CmiStateInit(-1,_Cmi_mynodesize,CmiGetStateN(_Cmi_mynodesize)); */ CmiStateInit(_Cmi_mynode+CmiNumPes(),_Cmi_mynodesize,CmiGetStateN(_Cmi_mynodesize)); #else /* for main thread */ Cmi_state_vector = (CmiState *)calloc(_Cmi_mynodesize+1, sizeof(CmiState)); #if CMK_CONVERSE_MPI /* main thread is communication thread */ if(!CharmLibInterOperate) { CmiStateInit(_Cmi_mynode+CmiNumPes(), _Cmi_mynodesize, &Cmi_mystate); Cmi_state_vector[_Cmi_mynodesize] = &Cmi_mystate; } else #endif { /* main thread is of rank 0 */ CmiStateInit(Cmi_nodestart, 0, &Cmi_mystate); Cmi_state_vector[0] = &Cmi_mystate; } #endif #if CMK_MULTICORE || CMK_SMP_NO_COMMTHD if (!Cmi_commthread) tocreate = _Cmi_mynodesize-1; else #endif tocreate = _Cmi_mynodesize; #if CMK_CONVERSE_MPI if(!CharmLibInterOperate) { start = 0; end = tocreate - 1; /* skip comm thread */ } else #endif { start = 1; end = tocreate; /* skip rank 0 main thread */ } for (i=start; i<=end; i++) { pthread_attr_init(&attr); pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); ok = pthread_create(&pid, &attr, call_startfn, (void *)i); if (ok<0) PerrorExit("pthread_create"); pthread_attr_destroy(&attr); } #if ! (CMK_HAS_TLS_VARIABLES && !CMK_NOT_USE_TLS_THREAD) #if CMK_CONVERSE_MPI if(!CharmLibInterOperate) pthread_setspecific(Cmi_state_key, Cmi_state_vector+_Cmi_mynodesize); else #endif pthread_setspecific(Cmi_state_key, Cmi_state_vector); #endif MACHSTATE(4,"CmiStartThreads done") }