// ************************************************************************** // This file is property of and copyright by the ALICE HLT Project * // ALICE Experiment at CERN, All rights reserved. * // * // Primary Authors: Sergey Gorbunov * // Ivan Kisel * // for The ALICE HLT Project. * // * // Developed by: Igor Kulakov * // Maksym Zyzak * // * // Permission to use, copy, modify and distribute this software and its * // documentation strictly for non-commercial purposes is hereby granted * // without fee, provided that the above copyright notice appears in all * // copies and that both the copyright notice and this permission notice * // appear in the supporting documentation. The authors make no claims * // about the suitability of this software for any purpose. It is * // provided "as is" without express or implied warranty. * // * //*************************************************************************** #include #include "KFParticleTopoReconstructor.h" #include "KFParticle.h" #include "KFParticleSIMD.h" #include "KFPHistogram/KFPHistogram.h" #ifdef MAIN_DRAW #include "AliHLTTPCCADisplay.h" #endif #include #include #include #include #include using namespace std; #ifndef NVALGRIND #include #endif #include #ifndef HLTCA_STANDALONE #include "TStopwatch.h" typedef TStopwatch Stopwatch; #else #include "Stopwatch.h" #endif #include "pthread.h" #include #include "dirent.h" #include "omp.h" #include #define handle_error_en(en, msg) do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) #define PAGE_SIZE 0x1000 //4KB #ifndef _WIN32 #include #include #else #include #endif /* Returns last errno */ int get_curr_status() { #ifdef _WIN32 DWORD ecode; ecode = GetLastError(); if (ecode == ERROR_CONNECTION_REFUSED) _set_errno(ECONNREFUSED); else if (ecode == ERROR_DEVICE_NOT_CONNECTED) _set_errno(ENXIO); else if (ecode == ERROR_REQUEST_ABORTED) _set_errno(EAGAIN); else _set_errno(ecode); #endif return errno; } inline void SetAffinity(const int cpuId) { int s; cpu_set_t cpuset; pthread_t thread = pthread_self(); CPU_ZERO(&cpuset); CPU_SET(cpuId, &cpuset); s = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset); if (s != 0){ cout << " pthread_setaffinity_np " << endl; handle_error_en(s, "pthread_setaffinity_np");} } static bool SAVE = false; extern bool SINGLE_THREADED; extern bool DRAW_EVERY_LINK; static bool file_exists( const char *filename ) { FILE *f = 0; if ( ( f = std::fopen( filename, "r" ) ) != NULL ) { std::fclose( f ); return true; } return false; } int main(int argc, char **argv) { int nThreads = 1; int nThreadsServer = 11; int iHLT = 0; string filePrefix = "./Events/"; for( int i=1; i < argc; i++ ){ if ( !std::strcmp( argv[i], "-h" ) || !std::strcmp( argv[i], "--help" ) || !std::strcmp( argv[i], "-help" ) ) { std::cout << "Please look in readme.txt" << std::endl; return 0; } else if ( !std::strcmp( argv[i], "-dir" ) && ++i < argc ) { filePrefix = argv[i]; } else if ( !std::strcmp( argv[i], "-nThreadsServer" ) && ++i < argc ) { nThreadsServer = atoi( argv[i] ); } else if ( !std::strcmp( argv[i], "-nThreads" ) && ++i < argc ) { nThreads = atoi( argv[i] ); } else if ( !std::strcmp( argv[i], "-HLT" ) && ++i < argc ) { iHLT = atoi( argv[i] ); } } DIR* KFPDataDir = opendir(filePrefix.data()); if(!KFPDataDir) { std::cout << "Fatal error: directory with the input tracks does not exist." << std::endl; exit(0); } KFPInputData data[100]; int nTotalEvents = 0; const int nStopEvents = nThreadsServer *100; int iData = 0; dirent *ent; KFPDataDir = opendir(filePrefix.data()); while ((ent = readdir (KFPDataDir)) != NULL) { int nameLength = strlen(ent->d_name); if(nameLength > 5) { if(ent->d_name[nameLength-5] == '.' && ent->d_name[nameLength-4] == 'd' && ent->d_name[nameLength-3] == 'a' && ent->d_name[nameLength-2] == 't' && ent->d_name[nameLength-1] == 'a' ) { // printf ("%s\n", ent->d_name); std::string curFileName = filePrefix; curFileName += "/"; curFileName += ent->d_name; std::cout << curFileName << std::endl; data[iData].ReadDataFromFile(curFileName); iData++; if(iData>=100) break; } } } closedir(KFPDataDir); scif_epd_t endpoint; const uint16_t portSenderId = 2000 + iHLT; struct scif_portID portRecieverId; portRecieverId.node = 1; portRecieverId.port = 3000 + iHLT; endpoint = scif_open( ); if( endpoint == SCIF_OPEN_FAILED ) { std::cout << "Fail openning SCIF endpoint." << std::endl; return 0 ; } int ret = 0; ret = scif_bind(endpoint, portSenderId); if( ret == -1 ) { std::cout << "Fail binding SCIF. " << std::endl; return 0; } ret = -1; while( ret == -1 ) { std::cout << " Connecting to the Xeon Phi card. " << std::endl; sleep(1); ret = scif_connect(endpoint, &portRecieverId); } std::cout << "Connected!!!! " << std::endl; float Bz = data[0].GetBz(); scif_send(endpoint, &Bz, sizeof(Bz), SCIF_SEND_BLOCK); // synchronization off_t offsetServer; scif_recv(endpoint, &offsetServer, sizeof(offsetServer), 1); int maxEventSize = 0; scif_recv(endpoint, &maxEventSize, sizeof(maxEventSize), 1); void* buffer; posix_memalign(&buffer, 0x1000, maxEventSize); off_t offsetSender = scif_register(endpoint, buffer, maxEventSize, 0, SCIF_PROT_READ | SCIF_PROT_WRITE,0); if( offsetSender < -1 ) { std::cout << "Fail registerring SCIF." << std::endl; return 0; } int controlSignal = portSenderId; scif_send(endpoint, &controlSignal, sizeof(int), SCIF_SEND_BLOCK); // synchronization iData = 0; int nEvents = 0; const off_t offsetSenderControl = offsetSender + (maxEventSize-1); const off_t offsetServerControl = offsetServer + (maxEventSize-1); while(1) { for(int iii=0; iii(buffer), dataSize); int msgSize = sizeof(int) * dataSize;//1000 * sizeof(int); scif_send(endpoint, &msgSize, sizeof(int), SCIF_SEND_BLOCK); scif_recv(endpoint, &controlSignal, sizeof(controlSignal), 1); if(controlSignal != portSenderId) { std::cout << controlSignal << " " << portSenderId << std::endl; continue; } ret = scif_writeto(endpoint, offsetServer, msgSize, offsetSender, 0); if ( ret == -1 ) std::cout << "Fail sending array to the server. Error: " << get_curr_status() << std::endl; // ret = scif_fence_signal(endpoint, // offsetSenderControl, /* local offset */ // 0xabcd, /* value to be written to local offset */ // offsetServerControl, /* remote offset */ // 0xabcd, /* value to be written to remote offset */ // SCIF_FENCE_INIT_SELF | SCIF_SIGNAL_LOCAL); // if(ret != 0) std::cout << "SCIF fence signal failed. Error: " << get_curr_status() << std::endl; scif_send(endpoint, &controlSignal, sizeof(int), SCIF_SEND_BLOCK); // synchronization nEvents++; } iData++; if(iData == 100) iData = 0; if(nEvents >= nStopEvents) break; // sleep(5); } sleep(10); // while(1) {} scif_close(endpoint); return 0; }