void Msg::Exit(int level) { // delete the temp file if(!_commRank) UnlinkFile(CTX::instance()->homeDir + CTX::instance()->tmpFileName); // exit directly on abnormal program termination (level != 0). We // used to call abort() to flush open streams, but on modern OSes // this calls the annoying "report this crash to the mothership" // window... so just exit! if(level){ #if defined(HAVE_SLEPC) SlepcFinalize(); #endif #if defined(HAVE_PETSC) PetscFinalize(); #endif #if defined(HAVE_MPI) // force general abort (wven if the fatal error occurred on 1 cpu only) MPI_Abort(MPI_COMM_WORLD, level); MPI_Finalize(); #endif FinalizeOnelab(); exit(level); } #if defined(HAVE_FLTK) // if we exit cleanly (level==0) and we are in full GUI mode, save // the persistent info to disk if(FlGui::available() && !_commRank) { if(CTX::instance()->sessionSave) PrintOptions(0, GMSH_SESSIONRC, 0, 0, (CTX::instance()->homeDir + CTX::instance()->sessionFileName).c_str()); if(CTX::instance()->optionsSave == 1) PrintOptions(0, GMSH_OPTIONSRC, 1, 0, (CTX::instance()->homeDir + CTX::instance()->optionsFileName).c_str()); else if(CTX::instance()->optionsSave == 2){ std::string fileName = GModel::current()->getFileName() + ".opt"; PrintOptions(0, GMSH_FULLRC, 1, 0, fileName.c_str()); } } #endif #if defined(HAVE_SLEPC) SlepcFinalize(); #endif #if defined(HAVE_PETSC) PetscFinalize(); #endif #if defined(HAVE_MPI) MPI_Finalize(); #endif FinalizeOnelab(); exit(_errorCount); }
void help_options_cb(Fl_Widget *w, void *data) { std::vector<std::string> s0; int diff = FlGui::instance()->help->modified->value(); int help = FlGui::instance()->help->showhelp->value(); std::string search = FlGui::instance()->help->search->value(); std::transform(search.begin(), search.end(), search.begin(), ::tolower); PrintOptions(0, GMSH_FULLRC, diff, help, 0, &s0); PrintParserSymbols(help, s0); int top = FlGui::instance()->help->browser->topline(); FlGui::instance()->help->browser->clear(); for(unsigned int i = 0; i < s0.size(); i++){ std::string::size_type sep = s0[i].rfind('\0'); void *d = 0; if(sep != std::string::npos){ std::string tmp = s0[i].substr(sep + 1); if(tmp == "number") d = (void*)"number"; else if(tmp == "string") d = (void*)"string"; else if(tmp == "color") d = (void*)"color"; } if(search.empty()){ FlGui::instance()->help->browser->add(s0[i].c_str(), d); } else{ std::string tmp(s0[i]); std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower); if(tmp.find(search) != std::string::npos) FlGui::instance()->help->browser->add(s0[i].c_str(), d); } } FlGui::instance()->help->browser->topline(top); }
int main(int argc,char *argv[]) { BM mainBM; OPTIONS options; LOCATIONHISTORY locationHistory; int error; //set vars to zero memset(&options, 0, sizeof(options)); //set all the option results to 0 memset(&mainBM, 0, sizeof(mainBM)); //Display introductory text PrintIntro(argv[0]); //locationHistory.jsonfilename="LocationHistory.json"; //default if (argc == 1) PrintUsage(argv[0]); //print usage instructions HandleCLIOptions(argc, argv, &options); PrintOptions(&options); RationaliseOptions(&options); //Initialise the bitmap bitmapInit(&mainBM, &options, &locationHistory); DrawGrid(&mainBM); //ColourWheel(mainBM, 100, 100, 100, 5); //Color wheel test of lines and antialiasing fprintf(stdout, "Loading locations from %s.\r\n", mainBM.options->jsonfilenamefinal); LoadLocations(&locationHistory, &mainBM.options->jsonfilenamefinal[0]); fprintf(stdout, "Plotting paths.\r\n"); PlotPaths(&mainBM, &locationHistory, &options); // HeatmapPlot(&mainBM, &locationHistory); fprintf(stdout, "Ploted lines between: %i points\r\n", mainBM.countPoints); printf("From:\t%s\r\n", asctime(localtime(&locationHistory.earliesttimestamp))); printf("To:\t%s\r\n", asctime(localtime(&locationHistory.latesttimestamp))); FreeLocations(&locationHistory); //Write the PNG file fprintf(stdout, "Writing to %s.\r\n", mainBM.options->pngfilenamefinal); error = lodepng_encode32_file(mainBM.options->pngfilenamefinal, mainBM.bitmap, mainBM.width, mainBM.height); if(error) fprintf(stderr, "LodePNG error %u: %s\n", error, lodepng_error_text(error)); //Write KML file fprintf(stdout, "Writing to %s.\r\n", mainBM.options->kmlfilenamefinal); WriteKMLFile(&mainBM); bitmapDestroy(&mainBM); fprintf(stdout, "Program finished."); return 0; }
int main(int ac, char* av[]) { OptionsHeirarchy options; try { options.ParseOptions(ac, av); PrintOptions(options); } catch (OptionsExitsProgram){} return 0; }
static void PrintHelpFor(const CommandLineCommand* commands) { // Print usage const char* usageString = "usage: openrct2 "; const size_t usageStringLength = String::LengthOf(usageString); Console::Write(usageString); // Get the largest command name length and parameter length size_t maxNameLength = 0; size_t maxParamsLength = 0; const CommandLineCommand* command; for (command = commands; command->Name != nullptr; command++) { maxNameLength = std::max(maxNameLength, String::LengthOf(command->Name)); maxParamsLength = std::max(maxParamsLength, String::LengthOf(command->Parameters)); } for (command = commands; command->Name != nullptr; command++) { if (command != commands) { Console::WriteSpace(usageStringLength); } Console::Write(command->Name); Console::WriteSpace(maxNameLength - String::LengthOf(command->Name) + 1); if (command->SubCommands == nullptr) { Console::Write(command->Parameters); Console::WriteSpace(maxParamsLength - String::LengthOf(command->Parameters)); if (command->Options != nullptr) { Console::Write(" [options]"); } } else { Console::Write("..."); } Console::WriteLine(); } Console::WriteLine(); if (commands->Options != nullptr) { PrintOptions(commands->Options); } }
bool NZBGet::ProcessDirect() { #ifdef DEBUG if (m_commandLineParser->GetTestBacktrace()) { TestSegFault(); } #endif if (m_commandLineParser->GetWebGet()) { ProcessWebGet(); return true; } if (m_commandLineParser->GetSigVerify()) { ProcessSigVerify(); return true; } // client request if (m_commandLineParser->GetClientOperation() != CommandLineParser::opClientNoOperation) { ProcessClientRequest(); return true; } if (m_commandLineParser->GetPrintOptions()) { PrintOptions(); return true; } return false; }
std::ostream& ParameterList::print(std::ostream& os, int indent, bool showTypes, bool showFlags) const { return this->print(os,PrintOptions().indent(indent).showTypes(showTypes).showFlags(showFlags)); }
static int Lwm2mServer_Start(Options * options) { int xmlFd; int result = 0; if (options->Daemonise) { Daemonise(options->Verbose); } else { signal(SIGINT, Lwm2m_CtrlCSignalHandler); } signal(SIGTERM, Lwm2m_CtrlCSignalHandler); // open log files here if (options->LogFile != NULL) { errno = 0; logFile = fopen(options->LogFile, "at"); if (logFile != NULL) { Lwm2m_SetOutput(logFile); // redirect stdout dup2(fileno(logFile), STDOUT_FILENO); } else { Lwm2m_Error("Failed to open log file %s: %s\n", options->LogFile, strerror(errno)); } } if (options->Version) { Lwm2m_Printf(0, "%s\n", version); goto error_close_log; } Lwm2m_SetLogLevel((options->Verbose) ? DebugLevel_Debug : DebugLevel_Info); Lwm2m_PrintBanner(); if (options->Verbose) { PrintOptions(options); } Lwm2m_Info("Awa LWM2M Server, version %s\n", version); Lwm2m_Info(" Process ID : %d\n", getpid()); Lwm2m_Info(" DTLS library : %s\n", DTLS_LibraryName); Lwm2m_Info(" CoAP library : %s\n", coap_LibraryName); Lwm2m_Info(" CoAP port : %d\n", options->CoapPort); Lwm2m_Info(" Secure : %s\n", options->Secure ? "true": "false"); Lwm2m_Info(" IPC port : %d\n", options->IpcPort); Lwm2m_Info(" Address family : IPv%d\n", options->AddressFamily == AF_INET ? 4 : 6); if (options->InterfaceName != NULL) { Lwm2m_Info("LWM2M server - Using interface %s [IPv%d]\n", options->InterfaceName, options->AddressFamily == AF_INET? 4 : 6); } else if (strcmp(DEFAULT_IP_ADDRESS, options->IPAddress) != 0) { Lwm2m_Info("LWM2M server - IP Address %s\n", options->IPAddress); } char ipAddress[NI_MAXHOST]; if (options->InterfaceName != NULL) { if (Lwm2mCore_GetIPAddressFromInterface(options->InterfaceName, options->AddressFamily, ipAddress, sizeof(ipAddress)) != 0) { result = 1; goto error_close_log; } Lwm2m_Info("LWM2M server - Interface Address %s\n", ipAddress); } else { strncpy(ipAddress, options->IPAddress, NI_MAXHOST); ipAddress[NI_MAXHOST - 1] = '\0'; // Defensive } CoapInfo * coap = coap_Init(ipAddress, options->CoapPort, options->Secure, (options->Verbose) ? DebugLevel_Debug : DebugLevel_Info); if (coap == NULL) { printf("Unable to map address to network interface\n"); result = 1; goto error_close_log; } if (options->Secure) { coap_SetCertificate(serverCert, sizeof(serverCert), CertificateFormat_PEM); coap_SetPSK(pskIdentity, pskKey, sizeof(pskKey)); } Lwm2mContextType * context = Lwm2mCore_Init(NULL, options->ContentType); // NULL, don't map coap with objectStore // must happen after coap_Init() Lwm2m_RegisterObjectTypes(context); // listen for UDP packets on port 12345 for now. xmlFd = xmlif_init(context, options->IpcPort); if (xmlFd < 0) { result = 1; goto error_destroy; } xmlif_RegisterHandlers(); // wait for messages on both the "IPC" and coap interfaces while (!quit) { int loop_result; struct pollfd fds[2]; int nfds = 2; int timeout; fds[0].fd = coap->fd; fds[0].events = POLLIN; fds[1].fd = xmlFd; fds[1].events = POLLIN; timeout = Lwm2mCore_Process(context); loop_result = poll(fds, nfds, timeout); if (loop_result < 0) { if (errno == EINTR) { continue; } perror("poll:"); break; } else if (loop_result > 0) { if (fds[0].revents == POLLIN) { coap_HandleMessage(); } if (fds[1].revents == POLLIN) { xmlif_process(fds[1].fd); } } coap_Process(); } Lwm2m_Debug("Exit triggered\n"); error_destroy: xmlif_destroy(xmlFd); Lwm2mCore_Destroy(context); coap_Destroy(); error_close_log: Lwm2m_Info("Server exiting\n"); if (logFile != NULL) { fclose(logFile); } return result; }
static int Lwm2mClient_Start(Options * options) { FILE * logFile = NULL; uint8_t * loadedClientCert = NULL; int result = 0; uint8_t * key = NULL; if (options->Daemonise) { Daemonise(options->Verbose); } else { signal(SIGINT, Lwm2m_CtrlCSignalHandler); } signal(SIGTERM, Lwm2m_CtrlCSignalHandler); if (options->LogFile) { errno = 0; logFile = fopen(options->LogFile, "at"); if (logFile != NULL) { Lwm2m_SetOutput(logFile); // redirect stdout dup2(fileno(logFile), STDOUT_FILENO); } else { Lwm2m_Error("Failed to open log file %s: %s\n", options->LogFile, strerror(errno)); } } if (options->Version) { Lwm2m_Printf(0, "%s\n", version); goto error_close_log; } srandom((int)time(NULL)*getpid()); if (options->CoapPort == 0) { options->CoapPort = 6000 + (rand() % 32768); } Lwm2m_SetLogLevel((options->Verbose) ? DebugLevel_Debug : DebugLevel_Info); Lwm2m_PrintBanner(); if (options->Verbose) { PrintOptions(options); } Lwm2m_Info("Awa LWM2M Client, version %s\n", version); Lwm2m_Info(" Process ID : %d\n", getpid()); Lwm2m_Info(" Endpoint name : \'%s\'\n", options->EndPointName); Lwm2m_Info(" DTLS library : %s\n", DTLS_LibraryName); Lwm2m_Info(" CoAP library : %s\n", coap_LibraryName); Lwm2m_Info(" CoAP port : %d\n", options->CoapPort); Lwm2m_Info(" IPC port : %d\n", options->IpcPort); Lwm2m_Info(" Address family : IPv%d\n", options->AddressFamily == AF_INET ? 4 : 6); Lwm2mCore_SetDefaultContentType(options->DefaultContentType); CoapInfo * coap = coap_Init((options->AddressFamily == AF_INET) ? "0.0.0.0" : "::", options->CoapPort, false /* not a server */, (options->Verbose) ? DebugLevel_Debug : DebugLevel_Info); if (coap == NULL) { Lwm2m_Error("Failed to initialise CoAP on port %d\n", options->CoapPort); result = 1; goto error_close_log; } // always set key if (options->CertificateFile) { loadedClientCert = LoadCertificateFile(options->CertificateFile); } else coap_SetCertificate(clientCert, sizeof(clientCert), AwaCertificateFormat_PEM); if (options->PskIdentity && options->PskKey) { int hexKeyLength = strlen(options->PskKey); int keyLength = hexKeyLength / 2; key = (uint8_t *)malloc(keyLength); if (key) { char * value = options->PskKey; int index; for (index = 0; index < keyLength; index++) { key[index] = HexToByte(value); value += 2; } coap_SetPSK(options->PskIdentity, key, keyLength); } else coap_SetPSK(pskIdentity, pskKey, sizeof(pskKey)); } else coap_SetPSK(pskIdentity, pskKey, sizeof(pskKey)); // if required read the bootstrap information from a file const BootstrapInfo * factoryBootstrapInfo; if (options->FactoryBootstrapFile != NULL) { factoryBootstrapInfo = BootstrapInformation_ReadConfigFile(options->FactoryBootstrapFile); if (factoryBootstrapInfo == NULL) { Lwm2m_Error("Factory Bootstrap configuration file load failed\n"); result = 1; goto error_coap; } else { Lwm2m_Info("Factory Bootstrap:\n"); Lwm2m_Info("Server Configuration\n"); Lwm2m_Info("====================\n"); BootstrapInformation_Dump(factoryBootstrapInfo); } } else { factoryBootstrapInfo = NULL; } Lwm2mContextType * context = Lwm2mCore_Init(coap, options->EndPointName); // Must happen after coap_Init(). RegisterObjects(context, options); if (factoryBootstrapInfo != NULL) { Lwm2mCore_SetFactoryBootstrap(context, factoryBootstrapInfo); } // bootstrap information has been loaded, no need to hang onto this anymore BootstrapInformation_DeleteBootstrapInfo(factoryBootstrapInfo); // load any specified objDef files if (LoadObjectDefinitionsFromFiles(context, options->ObjDefsFiles, options->NumObjDefsFiles) != 0) { goto error_core; } // Listen for UDP packets on IPC port int xmlFd = xmlif_init(context, options->IpcPort); if (xmlFd < 0) { Lwm2m_Error("Failed to initialise XML interface on port %d\n", options->IpcPort); result = 1; goto error_core; } xmlif_RegisterHandlers(); // Wait for messages on both the IPC and CoAP interfaces while (!quit) { int loop_result; struct pollfd fds[2]; int nfds = 2; int timeout; fds[0].fd = coap->fd; fds[0].events = POLLIN; fds[1].fd = xmlFd; fds[1].events = POLLIN; timeout = Lwm2mCore_Process(context); loop_result = poll(fds, nfds, timeout); if (loop_result < 0) { if (errno == EINTR) { continue; } perror("poll:"); break; } else if (loop_result > 0) { if (fds[0].revents == POLLIN) { coap_HandleMessage(); } if (fds[1].revents == POLLIN) { xmlif_process(fds[1].fd); } } coap_Process(); } Lwm2m_Debug("Exit triggered\n"); xmlif_DestroyExecuteHandlers(); xmlif_destroy(xmlFd); error_core: Lwm2mCore_Destroy(context); error_coap: coap_Destroy(); error_close_log: free(loadedClientCert); free(key); Lwm2m_Info("Client exiting\n"); if (logFile) { fclose(logFile); } return result; }
static int Bootstrap_Start(Options * options) { int result = 0; if (options->Daemonise) { Daemonise(options->Verbose); } else { signal(SIGINT, CtrlCSignalHandler); } signal(SIGTERM, CtrlCSignalHandler); // open log files here if (options->LogFile) { errno = 0; logFile = fopen(options->LogFile, "at"); if (logFile != NULL) { Lwm2m_SetOutput(logFile); // redirect stdout dup2(fileno(logFile), STDOUT_FILENO); } else { Lwm2m_Error("Failed to open log file %s: %s\n", options->LogFile, strerror(errno)); } } if (options->Version) { Lwm2m_Printf(0, "%s\n", version); goto error_close_log; } Lwm2m_SetLogLevel((options->Verbose) ? DebugLevel_Debug : DebugLevel_Info); Lwm2m_PrintBanner(); if (options->Verbose) { PrintOptions(options); } Lwm2m_Info("Awa LWM2M Bootstrap Server, version %s\n", version); Lwm2m_Info(" Process ID : %d\n", getpid()); Lwm2m_Info(" CoAP port : %d\n", options->Port); if (options->InterfaceName != NULL) { Lwm2m_Info(" Interface : %s [IPv%d]\n", options->InterfaceName, options->AddressFamily == AF_INET? 4 : 6); } else if (strcmp(DEFAULT_IP_ADDRESS, options->IPAddress) != 0) { Lwm2m_Info(" IP Address : %s\n", options->IPAddress); } char ipAddress[NI_MAXHOST]; if (options->InterfaceName != NULL) { if (Lwm2mCore_GetIPAddressFromInterface(options->InterfaceName, options->AddressFamily, ipAddress, sizeof(ipAddress)) != 0) { result = 1; goto error_close_log; } Lwm2m_Info(" Interface Addr : %s\n", ipAddress); } else { strncpy(ipAddress, options->IPAddress, NI_MAXHOST); ipAddress[NI_MAXHOST - 1] = '\0'; // Defensive } CoapInfo * coap = coap_Init(ipAddress, options->Port, (options->Verbose) ? DebugLevel_Debug : DebugLevel_Info); if (coap == NULL) { printf("Unable to map address to network interface\n"); result = 1; goto error_close_log; } Lwm2mContextType * context = Lwm2mCore_Init(coap); // must happen after coap_Init() Lwm2m_RegisterObjectTypes(context); if (!Lwm2mBootstrap_BootStrapInit(context, options->Config, options->ConfigCount)) { printf("Failed to initialise boostrap\n"); result = 1; goto error_destroy; } // wait for messages on both the "IPC" and coap interfaces while (!quit) { int loop_result; struct pollfd fds[1]; int nfds = 1; int timeout; fds[0].fd = coap->fd; fds[0].events = POLLIN; timeout = Lwm2mCore_Process(context); loop_result = poll(fds, nfds, timeout); if (loop_result < 0) { if (errno == EINTR) { continue; } perror("poll:"); break; } else if (loop_result > 0) { if (fds[0].revents == POLLIN) { coap_HandleMessage(); } } coap_Process(); } Lwm2m_Debug("Exit triggered\n"); error_destroy: Lwm2mBootstrap_Destroy(); Lwm2mCore_Destroy(context); coap_Destroy(); error_close_log: Lwm2m_Info("Bootstrap Server exiting\n"); if (logFile != NULL) { fclose(logFile); } return result; }
int main(void) { char str[256]; bool keyLoaded; // Does D,E,N have values? // RSACrypt is a class that handles RSA encryption/decryption internally big::RSACrypt<RSA_BIT_SIZE> rsacrypt; // These are the sizes necessary for e,n,p,q // e,n is the public key // p,q is the private key big::u32 e; RSA_BIT_SIZE n; BIGHALFSIZE(RSA_BIT_SIZE, p); BIGHALFSIZE(RSA_BIT_SIZE, q); FILE *fp; RakNetTime time; rakPeer1=RakNetworkFactory::GetRakPeerInterface(); rakPeer2=RakNetworkFactory::GetRakPeerInterface(); Packet *packet; bool peer1GotMessage, peer2GotMessage; keyLoaded=false; printf("Demonstrates how to setup RakNet to use secure connections\n"); printf("Also shows how to read and write RSA keys to and from disk\n"); printf("Difficulty: Intermediate\n\n"); printf("Select option:\n"); PrintOptions(); while (1) { gets(str); if (str[0]=='1') { printf("Generating %i byte key. This will take a while...\n", sizeof(RSA_BIT_SIZE)); rsacrypt.generateKeys(); rsacrypt.getPublicKey(e,n); rsacrypt.getPrivateKey(p,q); keyLoaded=true; printf("Key generated. Save to disk? (y/n)\n"); gets(str); if (str[0]=='y' || str[0]=='Y') { printf("Enter filename to save public keys to: "); gets(str); if (str[0]) { printf("Writing public key... "); fp=fopen(str, "wb"); fwrite((char*)&e, sizeof(e), 1, fp); fwrite((char*)n, sizeof(n), 1, fp); fclose(fp); printf("Done.\n"); } else printf("\nKey not written.\n"); printf("Enter filename to save private key to: "); gets(str); if (str[0]) { printf("Writing private key... "); fp=fopen(str, "wb"); fwrite(p, sizeof(RSA_BIT_SIZE)/2,1,fp); fwrite(q, sizeof(RSA_BIT_SIZE)/2, 1, fp); fclose(fp); printf("Done.\n"); } else printf("\nKey not written.\n"); } PrintOptions(); } else if (str[0]=='2') { printf("Enter filename to load public keys from: "); gets(str); if (str[0]) { fp=fopen(str, "rb"); if (fp) { printf("Loading public keys... "); fread((char*)(&e), sizeof(e), 1, fp); fread((char*)(n), sizeof(n), 1, fp); fclose(fp); printf("Done.\n"); printf("Enter filename to load private key from: "); gets(str); if (str[0]) { fp=fopen(str, "rb"); if (fp) { printf("Loading private key... "); fread(p, sizeof(RSA_BIT_SIZE)/2, 1, fp); fread(q, sizeof(RSA_BIT_SIZE)/2, 1, fp); fclose(fp); printf("Done.\n"); keyLoaded=true; } else { printf("Failed to open %s.\n", str); } } else printf("Not loading private key.\n"); } else { printf("Failed to open %s.\n", str); } } else printf("Not loading public keys.\n"); PrintOptions(); } else if (str[0]=='3') { if (keyLoaded) { printf("(G)enerate new keys automatically or use (e)xisting?\n"); gets(str); if (str[0]=='g' || str[0]=='G') { printf("Generating 32 byte keys. Please wait.\n"); rakPeer1->InitializeSecurity(0,0,0,0); printf("Keys generated.\n"); } else { rakPeer1->InitializeSecurity(0,0,(char*)p, (char*)q); printf("Tell the connecting system the public keys in advance?\n(Y)es, better security.\n(N)o, worse security but everything works automatically.\n"); gets(str); if (str[0]=='y' || str[0]=='Y') { printf("Using preloaded keys for the connecting system.\n"); rakPeer2->InitializeSecurity((char*)&e, (char*)n, 0, 0); } else { printf("Relying on server to transmit public keys to the connecting system.\n"); // Clear out any old saved public keys rakPeer2->DisableSecurity(); } } } else { printf("Generating key automatically on host. Please wait.\n"); rakPeer1->InitializeSecurity(0, 0, 0, 0); // Clear out any old saved public keys rakPeer2->DisableSecurity(); printf("Key generation complete.\n"); } printf("Initializing peers.\n"); SocketDescriptor socketDescriptor(1234,0); rakPeer1->Startup(8,0,&socketDescriptor, 1); rakPeer1->SetMaximumIncomingConnections(8); socketDescriptor.port=0; rakPeer2->Startup(1,0,&socketDescriptor, 1); rakPeer2->Connect("127.0.0.1", 1234, 0, 0); printf("Running connection for 5 seconds.\n"); peer1GotMessage=false; peer2GotMessage=false; time = RakNet::GetTime() + 5000; while (RakNet::GetTime() < time) { packet=rakPeer1->Receive(); if (packet) { peer1GotMessage=true; printf("Host got: "); PrintPacketHeader(packet); rakPeer1->DeallocatePacket(packet); } packet=rakPeer2->Receive(); if (packet) { peer2GotMessage=true; printf("Connecting system got: "); PrintPacketHeader(packet); rakPeer2->DeallocatePacket(packet); } #ifdef WIN32 Sleep(30); #else usleep(30*1000); #endif } if (peer1GotMessage==false) printf("Error, host got no packets.\n"); if (peer2GotMessage==false) printf("Error, connecting system got no packets.\n"); if (peer1GotMessage && peer2GotMessage) printf("Test successful as long as you got no error messages.\n"); rakPeer2->Shutdown(0); rakPeer1->Shutdown(0); PrintOptions(); } else if (str[0]=='h' || str[0]=='H') { PrintOptions(); } else if (str[0]=='q' || str[0]=='Q') break; str[0]=0; } RakNetworkFactory::DestroyRakPeerInterface(rakPeer1); RakNetworkFactory::DestroyRakPeerInterface(rakPeer2); }
int main(int argc, char *argv[]) { FILE *out=0; /* Output data file */ char s[255]; /* Generic string */ char *memtmp; char *memtmp1; MPI_Status status; int ii, i, j, k, n, nq, /* Loop indices */ bufoffset = 0, /* Align buffer to this */ bufalign = 16*1024, /* Boundary to align buffer to */ nrepeat01, nrepeat12, /* Number of time to do the transmission*/ nrepeat012, len, /* Number of bytes to be transmitted */ inc = 1, /* Increment value */ pert, /* Perturbation value */ ipert, /* index of the perturbation loop */ start = 0, /* Starting value for signature curve */ end = MAXINT, /* Ending value for signature curve */ printopt = 1, /* Debug print statements flag */ middle_rank = 0, /* rank 0, 1 or 2 where 2-0-1 or 0-1-2 or 1-2-0 */ tint; ArgStruct args01, args12, args012;/* Argumentsfor all the calls */ double t, t0, t1, /* Time variables */ tlast01, tlast12, tlast012,/* Time for the last transmission */ latency01, latency12, /* Network message latency */ latency012, tdouble; /* Network message latency to go from 0 -> 1 -> 2 */ #ifdef CREATE_DIFFERENCE_CURVES int itrial, ntrials; double *dtrials; #endif Data *bwdata01, *bwdata12, *bwdata012;/* Bandwidth curve data */ BOOL bNoCache = FALSE; BOOL bSavePert = FALSE; BOOL bUseMegaBytes = FALSE; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &g_nNproc); MPI_Comm_rank(MPI_COMM_WORLD, &g_nIproc); if (g_nNproc != 3) { if (g_nIproc == 0) PrintOptions(); MPI_Finalize(); exit(0); } GetOptDouble(&argc, &argv, "-time", &g_STOPTM); GetOptInt(&argc, &argv, "-reps", &g_NSAMP); GetOptInt(&argc, &argv, "-start", &start); GetOptInt(&argc, &argv, "-end", &end); bNoCache = GetOpt(&argc, &argv, "-nocache"); bUseMegaBytes = GetOpt(&argc, &argv, "-mb"); if (GetOpt(&argc, &argv, "-noprint")) printopt = 0; bSavePert = GetOpt(&argc, &argv, "-pert"); GetOptInt(&argc, &argv, "-middle", &middle_rank); if (middle_rank < 0 || middle_rank > 2) middle_rank = 0; bwdata01 = malloc((g_NSAMP+1) * sizeof(Data)); bwdata12 = malloc((g_NSAMP+1) * sizeof(Data)); bwdata012 = malloc((g_NSAMP+1) * sizeof(Data)); if (g_nIproc == 0) strcpy(s, "adapt.out"); GetOptString(&argc, &argv, "-out", s); if (start > end) { fprintf(stdout, "Start MUST be LESS than end\n"); exit(420132); } Setup(middle_rank, &args01, &args12, &args012); if (g_nIproc == 0) { if ((out = fopen(s, "w")) == NULL) { fprintf(stdout,"Can't open %s for output\n", s); exit(1); } } /* Calculate latency */ switch (g_proc_loc) { case LEFT_PROCESS: latency01 = TestLatency(&args01); /*printf("[0] latency01 = %0.9f\n", latency01);fflush(stdout);*/ RecvTime(&args01, &latency12); /*printf("[0] latency12 = %0.9f\n", latency12);fflush(stdout);*/ break; case MIDDLE_PROCESS: latency01 = TestLatency(&args01); /*printf("[1] latency01 = %0.9f\n", latency01);fflush(stdout);*/ SendTime(&args12, &latency01); latency12 = TestLatency(&args12); /*printf("[1] latency12 = %0.9f\n", latency12);fflush(stdout);*/ SendTime(&args01, &latency12); break; case RIGHT_PROCESS: RecvTime(&args12, &latency01); /*printf("[2] latency01 = %0.9f\n", latency01);fflush(stdout);*/ latency12 = TestLatency(&args12); /*printf("[2] latency12 = %0.9f\n", latency12);fflush(stdout);*/ break; } latency012 = TestLatency012(&args012); if ((g_nIproc == 0) && printopt) { printf("Latency%d%d_ : %0.9f\n", g_left_rank, g_middle_rank, latency01); printf("Latency_%d%d : %0.9f\n", g_middle_rank, g_right_rank, latency12); printf("Latency%d%d%d : %0.9f\n", g_left_rank, g_middle_rank, g_right_rank, latency012); fflush(stdout); printf("Now starting main loop\n"); fflush(stdout); } tlast01 = latency01; tlast12 = latency12; tlast012 = latency012; inc = (start > 1) ? start/2: inc; args01.bufflen = start; args12.bufflen = start; args012.bufflen = start; #ifdef CREATE_DIFFERENCE_CURVES /* print the header line of the output file */ if (g_nIproc == 0) { fprintf(out, "bytes\tMbits/s\ttime\tMbits/s\ttime"); for (ii=1, itrial=0; itrial<MAX_NUM_O12_TRIALS; ii <<= 1, itrial++) fprintf(out, "\t%d", ii); fprintf(out, "\n"); fflush(out); } ntrials = MAX_NUM_O12_TRIALS; dtrials = malloc(sizeof(double)*ntrials); #endif /* Main loop of benchmark */ for (nq = n = 0, len = start; n < g_NSAMP && tlast012 < g_STOPTM && len <= end; len = len + inc, nq++) { if (nq > 2) inc = (nq % 2) ? inc + inc : inc; /* clear the old values */ for (itrial = 0; itrial < ntrials; itrial++) { dtrials[itrial] = LONGTIME; } /* This is a perturbation loop to test nearby values */ for (ipert = 0, pert = (inc > PERT + 1) ? -PERT : 0; pert <= PERT; ipert++, n++, pert += (inc > PERT + 1) ? PERT : PERT + 1) { /*****************************************************/ /* Run a trial between rank 0 and 1 */ /*****************************************************/ MPI_Barrier(MPI_COMM_WORLD); if (g_proc_loc == RIGHT_PROCESS) goto skip_01_trial; /* Calculate howmany times to repeat the experiment. */ if (args01.tr) { if (args01.bufflen == 0) nrepeat01 = args01.latency_reps; else nrepeat01 = (int)(MAX((RUNTM / ((double)args01.bufflen / (args01.bufflen - inc + 1.0) * tlast01)), TRIALS)); SendReps(&args01, &nrepeat01); } else { RecvReps(&args01, &nrepeat01); } /* Allocate the buffer */ args01.bufflen = len + pert; /* printf("allocating %d bytes\n", args01.bufflen * nrepeat01 + bufalign); */ if (bNoCache) { if ((args01.sbuff = (char *)malloc(args01.bufflen * nrepeat01 + bufalign)) == (char *)NULL) { fprintf(stdout,"Couldn't allocate memory\n"); fflush(stdout); break; } } else { if ((args01.sbuff = (char *)malloc(args01.bufflen + bufalign)) == (char *)NULL) { fprintf(stdout,"Couldn't allocate memory\n"); fflush(stdout); break; } } /* if ((args01.rbuff = (char *)malloc(args01.bufflen * nrepeat01 + bufalign)) == (char *)NULL) */ if ((args01.rbuff = (char *)malloc(args01.bufflen + bufalign)) == (char *)NULL) { fprintf(stdout,"Couldn't allocate memory\n"); fflush(stdout); break; } /* save the original pointers in case alignment moves them */ memtmp = args01.sbuff; memtmp1 = args01.rbuff; /* Possibly align the data buffer */ if (!bNoCache) { if (bufalign != 0) { args01.sbuff += (bufalign - (POINTER_TO_INT(args01.sbuff) % bufalign) + bufoffset) % bufalign; /* args01.rbuff += (bufalign - ((MPI_Aint)args01.rbuff % bufalign) + bufoffset) % bufalign; */ } } args01.rbuff += (bufalign - (POINTER_TO_INT(args01.rbuff) % bufalign) + bufoffset) % bufalign; if (args01.tr && printopt) { fprintf(stdout,"%3d: %9d bytes %4d times --> ", n, args01.bufflen, nrepeat01); fflush(stdout); } /* Finally, we get to transmit or receive and time */ if (args01.tr) { bwdata01[n].t = LONGTIME; t1 = 0; for (i = 0; i < TRIALS; i++) { if (bNoCache) { if (bufalign != 0) { args01.sbuff = memtmp + ((bufalign - (POINTER_TO_INT(args01.sbuff) % bufalign) + bufoffset) % bufalign); /* args01.rbuff = memtmp1 + ((bufalign - ((MPI_Aint)args01.rbuff % bufalign) + bufoffset) % bufalign); */ } else { args01.sbuff = memtmp; /* args01.rbuff = memtmp1; */ } } Sync(&args01); t0 = MPI_Wtime(); for (j = 0; j < nrepeat01; j++) { MPI_Send(args01.sbuff, args01.bufflen, MPI_BYTE, args01.nbor, MSG_TAG_01, MPI_COMM_WORLD); MPI_Recv(args01.rbuff, args01.bufflen, MPI_BYTE, args01.nbor, MSG_TAG_01, MPI_COMM_WORLD, &status); if (bNoCache) { args01.sbuff += args01.bufflen; /* args01.rbuff += args01.bufflen; */ } } t = (MPI_Wtime() - t0)/(2 * nrepeat01); t1 += t; bwdata01[n].t = MIN(bwdata01[n].t, t); } SendTime(&args01, &bwdata01[n].t); } else { bwdata01[n].t = LONGTIME; t1 = 0; for (i = 0; i < TRIALS; i++) { if (bNoCache) { if (bufalign != 0) { args01.sbuff = memtmp + ((bufalign - (POINTER_TO_INT(args01.sbuff) % bufalign) + bufoffset) % bufalign); /* args01.rbuff = memtmp1 + ((bufalign - ((MPI_Aint)args01.rbuff % bufalign) + bufoffset) % bufalign); */ } else { args01.sbuff = memtmp; /* args01.rbuff = memtmp1; */ } } Sync(&args01); t0 = MPI_Wtime(); for (j = 0; j < nrepeat01; j++) { MPI_Recv(args01.rbuff, args01.bufflen, MPI_BYTE, args01.nbor, MSG_TAG_01, MPI_COMM_WORLD, &status); MPI_Send(args01.sbuff, args01.bufflen, MPI_BYTE, args01.nbor, MSG_TAG_01, MPI_COMM_WORLD); if (bNoCache) { args01.sbuff += args01.bufflen; /* args01.rbuff += args01.bufflen; */ } } t = (MPI_Wtime() - t0)/(2 * nrepeat01); } RecvTime(&args01, &bwdata01[n].t); } tlast01 = bwdata01[n].t; bwdata01[n].bits = args01.bufflen * CHARSIZE; bwdata01[n].bps = bwdata01[n].bits / (bwdata01[n].t * 1024 * 1024); bwdata01[n].repeat = nrepeat01; if (args01.tr) { if (bSavePert) { if (args01.iproc == 0) { if (bUseMegaBytes) fprintf(out, "%d\t%f\t%0.9f\t", bwdata01[n].bits / 8, bwdata01[n].bps / 8, bwdata01[n].t); else fprintf(out, "%d\t%f\t%0.9f\t", bwdata01[n].bits / 8, bwdata01[n].bps, bwdata01[n].t); fflush(out); } else { MPI_Send(&bwdata01[n].bits, 1, MPI_INT, 0, 1, MPI_COMM_WORLD); MPI_Send(&bwdata01[n].bps, 1, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD); MPI_Send(&bwdata01[n].t, 1, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD); } } } free(memtmp); free(memtmp1); if (args01.tr && printopt) { if (bUseMegaBytes) printf(" %6.2f MBps in %0.9f sec\n", bwdata01[n].bps / 8, tlast01); else printf(" %6.2f Mbps in %0.9f sec\n", bwdata01[n].bps, tlast01); fflush(stdout); } skip_01_trial: if (g_proc_loc == RIGHT_PROCESS && g_nIproc == 0 && bSavePert) { MPI_Recv(&tint, 1, MPI_INT, g_left_rank, 1, MPI_COMM_WORLD, &status); fprintf(out, "%d\t", tint/8); MPI_Recv(&tdouble, 1, MPI_DOUBLE, g_left_rank, 1, MPI_COMM_WORLD, &status); if (bUseMegaBytes) tdouble = tdouble / 8.0; fprintf(out, "%f\t", tdouble); MPI_Recv(&tdouble, 1, MPI_DOUBLE, g_left_rank, 1, MPI_COMM_WORLD, &status); fprintf(out, "%0.9f\t", tdouble); fflush(out); } /*****************************************************/ /* Run a trial between rank 1 and 2 */ /*****************************************************/ MPI_Barrier(MPI_COMM_WORLD); if (g_proc_loc == LEFT_PROCESS) goto skip_12_trial; /* Calculate howmany times to repeat the experiment. */ if (args12.tr) { if (args12.bufflen == 0) nrepeat12 = args12.latency_reps; else nrepeat12 = (int)(MAX((RUNTM / ((double)args12.bufflen / (args12.bufflen - inc + 1.0) * tlast12)), TRIALS)); SendReps(&args12, &nrepeat12); } else { RecvReps(&args12, &nrepeat12); } /* Allocate the buffer */ args12.bufflen = len + pert; /* printf("allocating %d bytes\n", args12.bufflen * nrepeat12 + bufalign); */ if (bNoCache) { if ((args12.sbuff = (char *)malloc(args12.bufflen * nrepeat12 + bufalign)) == (char *)NULL) { fprintf(stdout,"Couldn't allocate memory\n"); fflush(stdout); break; } } else { if ((args12.sbuff = (char *)malloc(args12.bufflen + bufalign)) == (char *)NULL) { fprintf(stdout,"Couldn't allocate memory\n"); fflush(stdout); break; } } /* if ((args12.rbuff = (char *)malloc(args12.bufflen * nrepeat12 + bufalign)) == (char *)NULL) */ if ((args12.rbuff = (char *)malloc(args12.bufflen + bufalign)) == (char *)NULL) { fprintf(stdout,"Couldn't allocate memory\n"); fflush(stdout); break; } /* save the original pointers in case alignment moves them */ memtmp = args12.sbuff; memtmp1 = args12.rbuff; /* Possibly align the data buffer */ if (!bNoCache) { if (bufalign != 0) { args12.sbuff += (bufalign - (POINTER_TO_INT(args12.sbuff) % bufalign) + bufoffset) % bufalign; /* args12.rbuff += (bufalign - ((MPI_Aint)args12.rbuff % bufalign) + bufoffset) % bufalign; */ } } args12.rbuff += (bufalign - (POINTER_TO_INT(args12.rbuff) % bufalign) + bufoffset) % bufalign; if (args12.tr && printopt) { printf("%3d: %9d bytes %4d times --> ", n, args12.bufflen, nrepeat12); fflush(stdout); } /* Finally, we get to transmit or receive and time */ if (args12.tr) { bwdata12[n].t = LONGTIME; t1 = 0; for (i = 0; i < TRIALS; i++) { if (bNoCache) { if (bufalign != 0) { args12.sbuff = memtmp + ((bufalign - (POINTER_TO_INT(args12.sbuff) % bufalign) + bufoffset) % bufalign); /* args12.rbuff = memtmp1 + ((bufalign - ((MPI_Aint)args12.rbuff % bufalign) + bufoffset) % bufalign); */ } else { args12.sbuff = memtmp; /* args12.rbuff = memtmp1; */ } } Sync(&args12); t0 = MPI_Wtime(); for (j = 0; j < nrepeat12; j++) { MPI_Send(args12.sbuff, args12.bufflen, MPI_BYTE, args12.nbor, MSG_TAG_12, MPI_COMM_WORLD); MPI_Recv(args12.rbuff, args12.bufflen, MPI_BYTE, args12.nbor, MSG_TAG_12, MPI_COMM_WORLD, &status); if (bNoCache) { args12.sbuff += args12.bufflen; /* args12.rbuff += args12.bufflen; */ } } t = (MPI_Wtime() - t0)/(2 * nrepeat12); t1 += t; bwdata12[n].t = MIN(bwdata12[n].t, t); } SendTime(&args12, &bwdata12[n].t); } else { bwdata12[n].t = LONGTIME; t1 = 0; for (i = 0; i < TRIALS; i++) { if (bNoCache) { if (bufalign != 0) { args12.sbuff = memtmp + ((bufalign - (POINTER_TO_INT(args12.sbuff) % bufalign) + bufoffset) % bufalign); /* args12.rbuff = memtmp1 + ((bufalign - ((MPI_Aint)args12.rbuff % bufalign) + bufoffset) % bufalign); */ } else { args12.sbuff = memtmp; /* args12.rbuff = memtmp1; */ } } Sync(&args12); t0 = MPI_Wtime(); for (j = 0; j < nrepeat12; j++) { MPI_Recv(args12.rbuff, args12.bufflen, MPI_BYTE, args12.nbor, MSG_TAG_12, MPI_COMM_WORLD, &status); MPI_Send(args12.sbuff, args12.bufflen, MPI_BYTE, args12.nbor, MSG_TAG_12, MPI_COMM_WORLD); if (bNoCache) { args12.sbuff += args12.bufflen; /* args12.rbuff += args12.bufflen; */ } } t = (MPI_Wtime() - t0)/(2 * nrepeat12); } RecvTime(&args12, &bwdata12[n].t); } tlast12 = bwdata12[n].t; bwdata12[n].bits = args12.bufflen * CHARSIZE; bwdata12[n].bps = bwdata12[n].bits / (bwdata12[n].t * 1024 * 1024); bwdata12[n].repeat = nrepeat12; if (args12.tr) { if (bSavePert) { if (g_nIproc == 0) { if (bUseMegaBytes) fprintf(out,"%f\t%0.9f\t", bwdata12[n].bps / 8, bwdata12[n].t); else fprintf(out,"%f\t%0.9f\t", bwdata12[n].bps, bwdata12[n].t); fflush(out); } else { MPI_Send(&bwdata12[n].bps, 1, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD); MPI_Send(&bwdata12[n].t, 1, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD); } } } free(memtmp); free(memtmp1); if (args12.tr && printopt) { if (bUseMegaBytes) printf(" %6.2f MBps in %0.9f sec\n", bwdata12[n].bps / 8, tlast12); else printf(" %6.2f Mbps in %0.9f sec\n", bwdata12[n].bps, tlast12); fflush(stdout); } skip_12_trial: if (g_proc_loc == LEFT_PROCESS && g_nIproc == 0 && bSavePert) { MPI_Recv(&tdouble, 1, MPI_DOUBLE, g_middle_rank, 1, MPI_COMM_WORLD, &status); if (bUseMegaBytes) tdouble = tdouble / 8.0; fprintf(out, "%f\t", tdouble); MPI_Recv(&tdouble, 1, MPI_DOUBLE, g_middle_rank, 1, MPI_COMM_WORLD, &status); fprintf(out, "%0.9f\t", tdouble); fflush(out); } #ifdef CREATE_DIFFERENCE_CURVES /*****************************************************/ /* Run a trial between rank 0, 1 and 2 */ /*****************************************************/ MPI_Barrier(MPI_COMM_WORLD); /* Calculate howmany times to repeat the experiment. */ if (g_nIproc == 0) { if (args012.bufflen == 0) nrepeat012 = g_latency012_reps; else nrepeat012 = (int)(MAX((RUNTM / ((double)args012.bufflen / (args012.bufflen - inc + 1.0) * tlast012)), TRIALS)); MPI_Bcast(&nrepeat012, 1, MPI_INT, 0, MPI_COMM_WORLD); } else { MPI_Bcast(&nrepeat012, 1, MPI_INT, 0, MPI_COMM_WORLD); } /* Allocate the buffer */ args012.bufflen = len + pert; /* printf("allocating %d bytes\n", args12.bufflen * nrepeat012 + bufalign); */ if (bNoCache) { if ((args012.sbuff = (char *)malloc(args012.bufflen * nrepeat012 + bufalign)) == (char *)NULL) { fprintf(stdout,"Couldn't allocate memory\n"); fflush(stdout); break; } } else { if ((args012.sbuff = (char *)malloc(args012.bufflen + bufalign)) == (char *)NULL) { fprintf(stdout,"Couldn't allocate memory\n"); fflush(stdout); break; } } /* if ((args012.rbuff = (char *)malloc(args012.bufflen * nrepeat012 + bufalign)) == (char *)NULL) */ if ((args012.rbuff = (char *)malloc(args012.bufflen + bufalign)) == (char *)NULL) { fprintf(stdout,"Couldn't allocate memory\n"); fflush(stdout); break; } /* save the original pointers in case alignment moves them */ memtmp = args012.sbuff; memtmp1 = args012.rbuff; /* Possibly align the data buffer */ if (!bNoCache) { if (bufalign != 0) { args012.sbuff += (bufalign - (POINTER_TO_INT(args012.sbuff) % bufalign) + bufoffset) % bufalign; /* args12.rbuff += (bufalign - ((MPI_Aint)args12.rbuff % bufalign) + bufoffset) % bufalign; */ } } args012.rbuff += (bufalign - (POINTER_TO_INT(args012.rbuff) % bufalign) + bufoffset) % bufalign; if (g_nIproc == 0 && printopt) { printf("%3d: %9d bytes %4d times --> ", n, args012.bufflen, nrepeat012); fflush(stdout); } for (itrial=0, ii=1; ii <= nrepeat012 && itrial < ntrials; ii <<= 1, itrial++) { /* Finally, we get to transmit or receive and time */ switch (g_proc_loc) { case LEFT_PROCESS: bwdata012[n].t = LONGTIME; t1 = 0; for (i = 0; i < TRIALS; i++) { if (bNoCache) { if (bufalign != 0) { args012.sbuff = memtmp + ((bufalign - (POINTER_TO_INT(args012.sbuff) % bufalign) + bufoffset) % bufalign); /* args012.rbuff = memtmp1 + ((bufalign - ((MPI_Aint)args012.rbuff % bufalign) + bufoffset) % bufalign); */ } else { args012.sbuff = memtmp; /* args012.rbuff = memtmp1; */ } } Sync012(&args012); t0 = MPI_Wtime(); for (j = 0; j < nrepeat012; j++) { MPI_Send(args012.sbuff, args012.bufflen, MPI_BYTE, args012.nbor, MSG_TAG_012, MPI_COMM_WORLD); MPI_Recv(args012.rbuff, args012.bufflen, MPI_BYTE, args012.nbor, MSG_TAG_012, MPI_COMM_WORLD, &status); if (bNoCache) { args012.sbuff += args012.bufflen; /* args012.rbuff += args012.bufflen; */ } } t = (MPI_Wtime() - t0)/(2 * nrepeat012); t1 += t; bwdata012[n].t = MIN(bwdata012[n].t, t); } MPI_Bcast(&bwdata012[n].t, 1, MPI_DOUBLE, g_left_rank, MPI_COMM_WORLD); break; case MIDDLE_PROCESS: bwdata012[n].t = LONGTIME; t1 = 0; for (i = 0; i < TRIALS; i++) { if (bNoCache) { if (bufalign != 0) { args012.sbuff = memtmp + ((bufalign - (POINTER_TO_INT(args012.sbuff) % bufalign) + bufoffset) % bufalign); /* args012.rbuff = memtmp1 + ((bufalign - ((MPI_Aint)args012.rbuff % bufalign) + bufoffset) % bufalign); */ } else { args012.sbuff = memtmp; /* args012.rbuff = memtmp1; */ } } Sync012(&args012); t0 = MPI_Wtime(); /******* use the ii variable here !!! ******/ for (j = 0; j <= nrepeat012-ii; j+=ii) { for (k=0; k<ii; k++) { MPI_Send(args012.sbuff, args012.bufflen, MPI_BYTE, args012.nbor2, MSG_TAG_012, MPI_COMM_WORLD); MPI_Recv(args012.rbuff, args012.bufflen, MPI_BYTE, args012.nbor2, MSG_TAG_012, MPI_COMM_WORLD, &status); } /* do the left process second because it does the timing and needs to include time to send to the right process. */ for (k=0; k<ii; k++) { MPI_Recv(args012.rbuff, args012.bufflen, MPI_BYTE, args012.nbor, MSG_TAG_012, MPI_COMM_WORLD, &status); MPI_Send(args012.sbuff, args012.bufflen, MPI_BYTE, args012.nbor, MSG_TAG_012, MPI_COMM_WORLD); } if (bNoCache) { args012.sbuff += args012.bufflen; /* args012.rbuff += args012.bufflen; */ } } j = nrepeat012 % ii; for (k=0; k < j; k++) { MPI_Send(args012.sbuff, args012.bufflen, MPI_BYTE, args012.nbor2, MSG_TAG_012, MPI_COMM_WORLD); MPI_Recv(args012.rbuff, args012.bufflen, MPI_BYTE, args012.nbor2, MSG_TAG_012, MPI_COMM_WORLD, &status); } /* do the left process second because it does the timing and needs to include time to send to the right process. */ for (k=0; k < j; k++) { MPI_Recv(args012.rbuff, args012.bufflen, MPI_BYTE, args012.nbor, MSG_TAG_012, MPI_COMM_WORLD, &status); MPI_Send(args012.sbuff, args012.bufflen, MPI_BYTE, args012.nbor, MSG_TAG_012, MPI_COMM_WORLD); } t = (MPI_Wtime() - t0)/(2 * nrepeat012); } MPI_Bcast(&bwdata012[n].t, 1, MPI_DOUBLE, g_left_rank, MPI_COMM_WORLD); break; case RIGHT_PROCESS: bwdata012[n].t = LONGTIME; t1 = 0; for (i = 0; i < TRIALS; i++) { if (bNoCache) { if (bufalign != 0) { args012.sbuff = memtmp + ((bufalign - (POINTER_TO_INT(args012.sbuff) % bufalign) + bufoffset) % bufalign); /* args012.rbuff = memtmp1 + ((bufalign - ((MPI_Aint)args012.rbuff % bufalign) + bufoffset) % bufalign); */ } else { args012.sbuff = memtmp; /* args012.rbuff = memtmp1; */ } } Sync012(&args012); t0 = MPI_Wtime(); for (j = 0; j < nrepeat012; j++) { MPI_Recv(args012.rbuff, args012.bufflen, MPI_BYTE, args012.nbor, MSG_TAG_012, MPI_COMM_WORLD, &status); MPI_Send(args012.sbuff, args012.bufflen, MPI_BYTE, args012.nbor, MSG_TAG_012, MPI_COMM_WORLD); if (bNoCache) { args012.sbuff += args012.bufflen; /* args012.rbuff += args012.bufflen; */ } } t = (MPI_Wtime() - t0)/(2 * nrepeat012); } MPI_Bcast(&bwdata012[n].t, 1, MPI_DOUBLE, g_left_rank, MPI_COMM_WORLD); break; } tlast012 = bwdata012[n].t; bwdata012[n].bits = args012.bufflen * CHARSIZE; bwdata012[n].bps = bwdata012[n].bits / (bwdata012[n].t * 1024 * 1024); bwdata012[n].repeat = nrepeat012; if (itrial < ntrials) { dtrials[itrial] = MIN(dtrials[itrial], bwdata012[n].t); } if (g_nIproc == 0) { if (bSavePert) { fprintf(out, "\t%0.9f", bwdata012[n].t); fflush(out); } if (printopt) { printf(" %0.9f", tlast012); fflush(stdout); } } } if (g_nIproc == 0) { if (bSavePert) { fprintf(out, "\n"); fflush(out); } if (printopt) { printf("\n"); fflush(stdout); } } free(memtmp); free(memtmp1); #endif #ifdef CREATE_SINGLE_CURVE /*****************************************************/ /* Run a trial between rank 0, 1 and 2 */ /*****************************************************/ MPI_Barrier(MPI_COMM_WORLD); /* Calculate howmany times to repeat the experiment. */ if (g_nIproc == 0) { if (args012.bufflen == 0) nrepeat012 = g_latency012_reps; else nrepeat012 = (int)(MAX((RUNTM / ((double)args012.bufflen / (args012.bufflen - inc + 1.0) * tlast012)), TRIALS)); MPI_Bcast(&nrepeat012, 1, MPI_INT, 0, MPI_COMM_WORLD); } else { MPI_Bcast(&nrepeat012, 1, MPI_INT, 0, MPI_COMM_WORLD); } /* Allocate the buffer */ args012.bufflen = len + pert; /* printf("allocating %d bytes\n", args12.bufflen * nrepeat012 + bufalign); */ if (bNoCache) { if ((args012.sbuff = (char *)malloc(args012.bufflen * nrepeat012 + bufalign)) == (char *)NULL) { fprintf(stdout,"Couldn't allocate memory\n"); fflush(stdout); break; } } else { if ((args012.sbuff = (char *)malloc(args012.bufflen + bufalign)) == (char *)NULL) { fprintf(stdout,"Couldn't allocate memory\n"); fflush(stdout); break; } } /* if ((args012.rbuff = (char *)malloc(args012.bufflen * nrepeat012 + bufalign)) == (char *)NULL) */ if ((args012.rbuff = (char *)malloc(args012.bufflen + bufalign)) == (char *)NULL) { fprintf(stdout,"Couldn't allocate memory\n"); fflush(stdout); break; } /* save the original pointers in case alignment moves them */ memtmp = args012.sbuff; memtmp1 = args012.rbuff; /* Possibly align the data buffer */ if (!bNoCache) { if (bufalign != 0) { args012.sbuff += (bufalign - (POINTER_TO_INT(args012.sbuff) % bufalign) + bufoffset) % bufalign; /* args12.rbuff += (bufalign - ((MPI_Aint)args12.rbuff % bufalign) + bufoffset) % bufalign; */ } } args012.rbuff += (bufalign - (POINTER_TO_INT(args012.rbuff) % bufalign) + bufoffset) % bufalign; if (g_nIproc == 0 && printopt) { printf("%3d: %9d bytes %4d times --> ", n, args012.bufflen, nrepeat012); fflush(stdout); } /* Finally, we get to transmit or receive and time */ switch (g_proc_loc) { case LEFT_PROCESS: bwdata012[n].t = LONGTIME; t1 = 0; for (i = 0; i < TRIALS; i++) { if (bNoCache) { if (bufalign != 0) { args012.sbuff = memtmp + ((bufalign - (POINTER_TO_INT(args012.sbuff) % bufalign) + bufoffset) % bufalign); /* args012.rbuff = memtmp1 + ((bufalign - ((MPI_Aint)args012.rbuff % bufalign) + bufoffset) % bufalign); */ } else { args012.sbuff = memtmp; /* args012.rbuff = memtmp1; */ } } Sync012(&args012); t0 = MPI_Wtime(); for (j = 0; j < nrepeat012; j++) { MPI_Send(args012.sbuff, args012.bufflen, MPI_BYTE, args012.nbor, MSG_TAG_012, MPI_COMM_WORLD); MPI_Recv(args012.rbuff, args012.bufflen, MPI_BYTE, args012.nbor, MSG_TAG_012, MPI_COMM_WORLD, &status); if (bNoCache) { args012.sbuff += args012.bufflen; /* args012.rbuff += args012.bufflen; */ } } t = (MPI_Wtime() - t0)/(2 * nrepeat012); t1 += t; bwdata012[n].t = MIN(bwdata012[n].t, t); } MPI_Bcast(&bwdata012[n].t, 1, MPI_DOUBLE, g_left_rank, MPI_COMM_WORLD); break; case MIDDLE_PROCESS: bwdata012[n].t = LONGTIME; t1 = 0; for (i = 0; i < TRIALS; i++) { if (bNoCache) { if (bufalign != 0) { args012.sbuff = memtmp + ((bufalign - (POINTER_TO_INT(args012.sbuff) % bufalign) + bufoffset) % bufalign); /* args012.rbuff = memtmp1 + ((bufalign - ((MPI_Aint)args012.rbuff % bufalign) + bufoffset) % bufalign); */ } else { args012.sbuff = memtmp; /* args012.rbuff = memtmp1; */ } } Sync012(&args012); t0 = MPI_Wtime(); for (j = 0; j < nrepeat012; j++) { MPI_Recv(args012.rbuff, args012.bufflen, MPI_BYTE, args012.nbor, MSG_TAG_012, MPI_COMM_WORLD, &status); MPI_Send(args012.sbuff, args012.bufflen, MPI_BYTE, args012.nbor2, MSG_TAG_012, MPI_COMM_WORLD); MPI_Recv(args012.rbuff, args012.bufflen, MPI_BYTE, args012.nbor2, MSG_TAG_012, MPI_COMM_WORLD, &status); MPI_Send(args012.sbuff, args012.bufflen, MPI_BYTE, args012.nbor, MSG_TAG_012, MPI_COMM_WORLD); if (bNoCache) { args012.sbuff += args012.bufflen; /* args012.rbuff += args012.bufflen; */ } } t = (MPI_Wtime() - t0)/(2 * nrepeat012); } MPI_Bcast(&bwdata012[n].t, 1, MPI_DOUBLE, g_left_rank, MPI_COMM_WORLD); break; case RIGHT_PROCESS: bwdata012[n].t = LONGTIME; t1 = 0; for (i = 0; i < TRIALS; i++) { if (bNoCache) { if (bufalign != 0) { args012.sbuff = memtmp + ((bufalign - (POINTER_TO_INT(args012.sbuff) % bufalign) + bufoffset) % bufalign); /* args012.rbuff = memtmp1 + ((bufalign - ((MPI_Aint)args012.rbuff % bufalign) + bufoffset) % bufalign); */ } else { args012.sbuff = memtmp; /* args012.rbuff = memtmp1; */ } } Sync012(&args012); t0 = MPI_Wtime(); for (j = 0; j < nrepeat012; j++) { MPI_Recv(args012.rbuff, args012.bufflen, MPI_BYTE, args012.nbor, MSG_TAG_012, MPI_COMM_WORLD, &status); MPI_Send(args012.sbuff, args012.bufflen, MPI_BYTE, args012.nbor, MSG_TAG_012, MPI_COMM_WORLD); if (bNoCache) { args012.sbuff += args012.bufflen; /* args012.rbuff += args012.bufflen; */ } } t = (MPI_Wtime() - t0)/(2 * nrepeat012); } MPI_Bcast(&bwdata012[n].t, 1, MPI_DOUBLE, g_left_rank, MPI_COMM_WORLD); break; } tlast012 = bwdata012[n].t; bwdata012[n].bits = args012.bufflen * CHARSIZE; bwdata012[n].bps = bwdata012[n].bits / (bwdata012[n].t * 1024 * 1024); bwdata012[n].repeat = nrepeat012; if (g_nIproc == 0) { if (bSavePert) { if (bUseMegaBytes) fprintf(out, "%f\t%0.9f\n", bwdata012[n].bps / 8, bwdata012[n].t); else fprintf(out, "%f\t%0.9f\n", bwdata012[n].bps, bwdata012[n].t); fflush(out); } } free(memtmp); free(memtmp1); if (g_nIproc == 0 && printopt) { if (bUseMegaBytes) printf(" %6.2f MBps in %0.9f sec\n", bwdata012[n].bps / 8, tlast012); else printf(" %6.2f Mbps in %0.9f sec\n", bwdata012[n].bps, tlast012); fflush(stdout); } #endif } /* End of perturbation loop */ if (!bSavePert)/* && g_nIproc == 0)*/ { /* if we didn't save all of the perturbation loops, find the max and save it */ int index01 = 1, index12 = 1; double dmax01 = bwdata01[n-1].bps; double dmax12 = bwdata12[n-1].bps; #ifdef CREATE_SINGLE_CURVE int index012 = 1; double dmax012 = bwdata012[n-1].bps; #endif for (; ipert > 1; ipert--) { if (bwdata01[n-ipert].bps > dmax01) { index01 = ipert; dmax01 = bwdata01[n-ipert].bps; } if (bwdata12[n-ipert].bps > dmax12) { index12 = ipert; dmax12 = bwdata12[n-ipert].bps; } #ifdef CREATE_SINGLE_CURVE if (bwdata012[n-ipert].bps > dmax012) { index012 = ipert; dmax012 = bwdata012[n-ipert].bps; } #endif } /* get the left stuff out */ MPI_Bcast(&index01, 1, MPI_INT, g_left_rank, MPI_COMM_WORLD); MPI_Bcast(&bwdata01[n-index01].bits, 1, MPI_INT, g_left_rank, MPI_COMM_WORLD); MPI_Bcast(&bwdata01[n-index01].bps, 1, MPI_DOUBLE, g_left_rank, MPI_COMM_WORLD); MPI_Bcast(&bwdata01[n-index01].t, 1, MPI_DOUBLE, g_left_rank, MPI_COMM_WORLD); /* get the right stuff out */ MPI_Bcast(&index12, 1, MPI_INT, g_middle_rank, MPI_COMM_WORLD); MPI_Bcast(&bwdata12[n-index12].bps, 1, MPI_DOUBLE, g_middle_rank, MPI_COMM_WORLD); MPI_Bcast(&bwdata12[n-index12].t, 1, MPI_DOUBLE, g_middle_rank, MPI_COMM_WORLD); if (g_nIproc == 0) { if (bUseMegaBytes) { fprintf(out, "%d\t%f\t%0.9f\t", bwdata01[n-index01].bits / 8, bwdata01[n-index01].bps / 8, bwdata01[n-index01].t); fprintf(out, "%f\t%0.9f\t", bwdata12[n-index12].bps / 8, bwdata12[n-index12].t); #ifdef CREATE_SINGLE_CURVE fprintf(out, "%f\t%0.9f\n", bwdata012[n-index012].bps / 8, bwdata012[n-index012].t); #endif } else { fprintf(out, "%d\t%f\t%0.9f\t", bwdata01[n-index01].bits / 8, bwdata01[n-index01].bps, bwdata01[n-index01].t); fprintf(out, "%f\t%0.9f\t", bwdata12[n-index12].bps, bwdata12[n-index12].t); #ifdef CREATE_SINGLE_CURVE fprintf(out, "%f\t%0.9f\n", bwdata012[n-index012].bps, bwdata012[n-index012].t); #endif } #ifdef CREATE_DIFFERENCE_CURVES for (itrial = 0; itrial < ntrials && dtrials[itrial] != LONGTIME; itrial++) { fprintf(out, "%0.9f\t", dtrials[itrial]); } fprintf(out, "\n"); #endif fflush(out); } } } /* End of main loop */ if (g_nIproc == 0) fclose(out); /* THE_END: */ MPI_Finalize(); free(bwdata01); free(bwdata12); free(bwdata012); return 0; }
/* ======== main light modelfile ======== */ int main (int argc, char **argv) { int i, ModeCnt = 0, Val; char source[1024], *Option, *NextOption; float FVal; qboolean NoGlobRange = false; logfile = fopen (LOGFILENAME, "w"); logprintf ("----- Light 1.43 ---- Modified by Bengt Jardrup\n"); logprintf ("----- Release 2 ---- Coloured light and LIT support by MH\n\n"); for (i = 1; i < argc; i++) { Option = argv[i]; NextOption = i + 1 < argc ? argv[i + 1] : NULL; if (Option[0] != '-') break; ++Option; if (!stricmp (Option, "fast")) { FastLight = 2; if (NextOption != NULL && isdigit (NextOption[0]) && i + 2 < argc) { Val = atoi (NextOption); i++; if (Val > 2) FastLight = Val; } logprintf ("Fast light %d enabled\n", FastLight); } else if (!stricmp (Option, "soft")) { SoftLight = 0; if (NextOption != NULL && isdigit (NextOption[0]) && i + 2 < argc) { SoftLight = atoi (NextOption); i++; } } else if (!stricmp (Option, "softdist")) { SoftDist = GetArgument (Option, NextOption); i++; } else if (!stricmp (Option, "extra") || !stricmp (Option, "extra4")) { OverSample = Option[5] == '4' ? 4 : 2; logprintf ("Extra %dx%d sampling enabled\n", OverSample, OverSample); } else if (!stricmp (Option, "threads")) { numthreads = GetFloatArgument (Option, NextOption); i++; } else if (!stricmp (Option, "dist")) { scaledist = GetFloatArgument (Option, NextOption); i++; } else if (!stricmp (Option, "range")) { rangescale = GetFloatArgument (Option, NextOption); i++; } else if (!stricmp (Option, "globrange")) { GlobRange = true; logprintf ("Global range enabled\n"); } else if (!stricmp (Option, "noglobrange")) NoGlobRange = true; else if (!stricmp (Option, "light")) { worldminlight = GetArgument (Option, NextOption); i++; } else if (!stricmp (Option, "maxlight")) { worldmaxlight = GetArgument (Option, NextOption); i++; } else if (!stricmp (Option, "nolight")) { NoLight = true; logprintf ("Light entities disabled\n"); } else if (!stricmp (Option, "srclight")) { SrcLight = true; logprintf ("Unsourced light entities disabled\n"); } else if (!stricmp (Option, "sunlight")) { SunLight[0] = GetArgument (Option, NextOption); i++; } else if (!stricmp (Option, "sunlight2")) { SunLight[1] = GetArgument (Option, NextOption); i++; } else if (!stricmp (Option, "sunlight3")) { SunLight[1] = GetArgument (Option, NextOption); if (ShadowSense == -1) ShadowSense = SHADOWSENSE; i++; } else if (!stricmp (Option, "sunmangle")) { ChkArgument (Option, NextOption); if (sscanf (NextOption, "%d,%d", &SunMangleVal[0], &SunMangleVal[1]) != 2) Error ("Missing arguments for '%s'", Option); SunMangleVal[2] = 0; i++; } else if (!stricmp (Option, "nowarnings")) NoWarnings = true; else if (!stricmp (Option, "rate")) { ChkArgument (Option, NextOption); if (sscanf (NextOption, "%d,%f,%d,%d", &SecRate, &FVal, &NewLine, &TotTime) > 1) PercRate = (FVal + 0.05) * 10; // Fix roundoff AutoRate = false; i++; } else if (!stricmp (Option, "barpercent")) { SimpPercent = true; NumPercent = false; } else if (!stricmp (Option, "numpercent")) { SimpPercent = true; NumPercent = true; } else if (!stricmp (Option, "oldlight")) { OldLight = NoAnti = true; logprintf ("Oldlight mode enabled\n"); ++ModeCnt; } else if (!stricmp (Option, "tyrlite")) { TyrLiteMode = GlobRange = true; logprintf ("TyrLite mode enabled\n"); ++ModeCnt; } else if (!stricmp (Option, "tyrlite95")) { TyrLite95Mode = TyrLiteMode = GlobRange = true; logprintf ("TyrLite95 mode enabled\n"); ++ModeCnt; } else if (!stricmp (Option, "arghlite")) { ArghLiteMode = GlobRange = AddMinLight = true; logprintf ("ArghLite mode enabled\n"); ++ModeCnt; } else if (!stricmp (Option, "addmin")) { AddMinLight = true; logprintf ("Additive minlight enabled\n"); } else if (!stricmp (Option, "iklite")) { IKLiteMode = IKAngle = OldLight = NoAnti = true; logprintf ("IKLite mode enabled\n"); ++ModeCnt; } else if (!stricmp (Option, "ikangle")) { IKAngle = true; logprintf ("IKLite angle sensitivity enabled\n"); } else if (!stricmp (Option, "anglesense")) { FVal = GetFloatArgument (Option, NextOption); i++; if (FVal >= 0 && FVal <= 1 && FVal != scalecos) logprintf ("Angle sensitivity %g set\n", scalecos = FVal); } else if (!stricmp (Option, "shadowsense")) { FVal = GetFloatArgument (Option, NextOption); i++; if (FVal >= 0 && FVal <= 1) ShadowSense = FVal; } else if (!stricmp (Option, "gate")) { FVal = GetFloatArgument (Option, NextOption); i++; if (FVal >= 0 && FVal != GateVal) logprintf ("Fade Gate %g set\n", GateVal = FVal); } else if (!stricmp (Option, "dlx")) { LightDLXMode = OldLight = true; logprintf ("LightDLX mode enabled\n"); ++ModeCnt; } else if (!stricmp (Option, "kinn")) { KinnDelay = true; logprintf ("Kinn translation enabled\n"); } else if (!stricmp (Option, "solidsky")) { SolidSky = true; logprintf ("Solid sky brushes enabled\n"); } else if (!stricmp (Option, "unsup")) UnsupDetails = DetectKeys = true; else if (!stricmp (Option, "detect")) DetectKeys = true; else if (!stricmp (Option, "noskill")) NoSkillChk = true; else if (!stricmp (Option, "noflash")) NoFlash = true; else if (!stricmp (Option, "noanti")) NoAnti = NoAntiOption = true; else if (!stricmp (Option, "lightcap")) { Val = GetArgument (Option, NextOption); i++; if (Val >= 0 && Val != LightCap) logprintf ("LightCap %d enabled\n", LightCap = Val); } else if (!stricmp (Option, "onlyents")) OnlyEnts = true; else if (!stricmp (Option, "nowrite")) NoWrite = true; else if (!stricmp (Option, "norev")) NoReverse = true; else if (!stricmp (Option, "etp")) { EnhancedTP = true; logprintf ("Enhanced Texture Positioning enabled\n"); } else if (!stricmp (Option, "priority")) { SetQPriority (GetArgument (Option, NextOption)); i++; } else if (!stricmp (Option, "oldhformat")) OldHFormat = true; else if (!stricmp (Option, "?") || !stricmp (Option, "help")) PrintOptions (); else if (!stricmp (Option, "fakeGISun2")) { FakeGISunlight2 = true; logprintf ("Additive sunlight2 enabled\n"); } else if (!stricmp (Option, "fakeGIMode")) { FakeGIMode = true; logprintf ("FakeGI mode enabled\n"); } else Error ("Unknown option '%s'", Option); } if (i != argc - 1) PrintOptions (); if (GlobRange && NoGlobRange) { GlobRange = false; logprintf ("Global range disabled\n"); } if (ModeCnt > 1) Error ("Only one emulation mode allowed"); if (SoftLight >= 0) { if (SoftLight == 0) SoftLight = OverSample / 2 + 1; // Auto mode logprintf ("Soft light %d enabled\n", SoftLight); if (SoftDist != SOFTDIST) logprintf ("Soft distance %d set\n", SoftDist); } if (SoftLight > 0) { // Soft option is in charge SingleDist = -SoftDist; SkyDist = -SOFTDIST; } else { if (TyrLite95Mode) { SingleDist = 0; SkyDist = -ANGLE_EPSILON; } else SingleDist = SkyDist = 1; // Classic (no) soft distance } if (OverSample <= 2) { // Set compatibility modes GenCompatible = OldLight || TyrLiteMode || ArghLiteMode || IKLiteMode || LightDLXMode; ATCompatible = TyrLiteMode || ArghLiteMode; TyrCompatible = TyrLiteMode; } InitThreads (); if (!OnlyEnts && !NoWrite) start = I_FloatTime (); strcpy (source, argv[i]); StripExtension (source); DefaultExtension (source, ".bsp"); if (!NoWrite) WriteChk (source); logprintf ("File: %s\n", source); LoadBSPFile (source); LoadEntities (); if (OnlyEnts) logprintf ("Updating entities lump...\n"); else if (!NoWrite) { MakeTnodes (&dmodels[0]); FindFaceOffsets (); LightWorld (); } if (!NoWrite) { WriteEntitiesToString (); WriteBSPFile (source); } PrintFinish (); return 0; }