Skip to content

Commit

Permalink
added outputfilename and server buffer size option
Browse files Browse the repository at this point in the history
  • Loading branch information
xLPMG committed Jan 17, 2024
1 parent 2636a45 commit bf674e6
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 43 deletions.
1 change: 1 addition & 0 deletions lib/xlpmg/Communicator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <ctime>
#include <iomanip>
#include <sstream>
#include <iostream>

namespace xlpmg
{
Expand Down
28 changes: 17 additions & 11 deletions lib/xlpmg/communicator_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
* @author Luca-Philipp Grumbach
*
* # Description
* Communicator api.
* Communicator API.
* This file provides an interface with pre-defined
* messages to enable a correct transmission of
* information between client and server.
**/
#ifndef XLPMG_COMMUNICATOR_API_H
#define XLPMG_COMMUNICATOR_API_H
Expand All @@ -23,13 +26,13 @@ namespace xlpmg

enum MessageType
{
SERVER__CALL,
SERVER_CALL,
FUNCTION_CALL,
OTHER,
SERVER_RESPONSE
};

NLOHMANN_JSON_SERIALIZE_ENUM(MessageType, {{SERVER__CALL, "server_call"},
NLOHMANN_JSON_SERIALIZE_ENUM(MessageType, {{SERVER_CALL, "server_call"},
{FUNCTION_CALL, "function_call"},
{OTHER, "other"},
{SERVER_RESPONSE, "server_response"}});
Expand Down Expand Up @@ -83,25 +86,25 @@ namespace xlpmg
}

//! should not not induce any functionality and is only used to check if the other side responds
inline const Message CHECK_MESSAGE = {MessageType::SERVER__CALL, "XCHECKX"};
inline const Message CHECK_MESSAGE = {MessageType::SERVER_CALL, "XCHECKX"};

//! Tells the server to shutdown.
inline const Message SHUTDOWN_SERVER_MESSAGE = {MessageType::SERVER__CALL, "shutdown_server"};
inline const Message SHUTDOWN_SERVER_MESSAGE = {MessageType::SERVER_CALL, "shutdown_server"};

//! Tells the server to restart.
inline const Message START_SIMULATION_MESSAGE = {MessageType::SERVER__CALL, "start_simulation"};
inline const Message START_SIMULATION_MESSAGE = {MessageType::SERVER_CALL, "start_simulation"};

//! Server will stop the running simulation.
inline const Message KILL_SIMULATION_MESSAGE = {MessageType::SERVER__CALL, "kill_simulation"};
inline const Message KILL_SIMULATION_MESSAGE = {MessageType::SERVER_CALL, "kill_simulation"};

//! Server will recompile with provided arguments.
inline const Message COMPILE_MESSAGE = {MessageType::SERVER__CALL, "compile", ""};
//! Server will recompile with provided arguments.
inline const Message COMPILE_MESSAGE = {MessageType::SERVER_CALL, "compile", ""};

//! Server will recompile with provided arguments and run using a bash script.
inline const Message COMPILE_RUN_BASH_MESSAGE = {MessageType::SERVER__CALL, "compile_run_bash", ""};
inline const Message COMPILE_RUN_BASH_MESSAGE = {MessageType::SERVER_CALL, "compile_run_bash", ""};

//! Server will recompile with provided arguments and run using an sbatch script.
inline const Message COMPILE_RUN_SBATCH_MESSAGE = {MessageType::SERVER__CALL, "compile_run_sbatch", ""};
inline const Message COMPILE_RUN_SBATCH_MESSAGE = {MessageType::SERVER_CALL, "compile_run_sbatch", ""};

//! Simulator will write a checkpoint.
inline const Message WRITE_CHECKPOINT_MESSAGE = {MessageType::FUNCTION_CALL, "write_checkpoint"};
Expand All @@ -126,6 +129,9 @@ namespace xlpmg

//! Tells the client that a buffered sending operation has finished.
inline const Message BUFFERED_SEND_FINISHED = {MessageType::SERVER_RESPONSE, "buff_send_finished"};

//! Tells the server to change the buffer size.
inline const Message SET_BUFFER_SIZE = {MessageType::SERVER_CALL, "set_buffer_size"};
}

#endif
13 changes: 10 additions & 3 deletions src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ int main(int i_argc, char *i_argv[])
//------------------------------------------//
//---------------SERVER MODE----------------//
//------------------------------------------//
if (i_argc >= 3 && (strcmp(i_argv[1],"server")==0))
if (i_argc >= 2 && (strcmp(i_argv[1], "server") == 0))
{
m_PORT = atoi(i_argv[2]);
if (i_argc >= 3)
{
m_PORT = atoi(i_argv[2]);
}

xlpmg::Communicator l_communicator;
l_communicator.startServer(m_PORT);
Expand All @@ -68,7 +71,7 @@ int main(int i_argc, char *i_argv[])
std::string l_key = l_message.key;
json l_args = l_message.args;

if (l_type == xlpmg::SERVER__CALL)
if (l_type == xlpmg::SERVER_CALL)
{
if (l_key == xlpmg::SHUTDOWN_SERVER_MESSAGE.key)
{
Expand Down Expand Up @@ -148,6 +151,10 @@ int main(int i_argc, char *i_argv[])
exec("chmod +x run-sbatch.sh");
exec("sbatch run-sbatch.sh");
}
else if (l_key == xlpmg::SET_BUFFER_SIZE.key)
{
l_communicator.setReadBufferSize(l_args);
}
}
else if (l_type == xlpmg::FUNCTION_CALL)
{
Expand Down
69 changes: 43 additions & 26 deletions src/ui/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ json tsunami_lab::ui::GUI::createConfigJson()
{"endTime", m_endTime},
{"useFileIO", m_useFileIO},
{"writingFrequency", m_writingFrequency},
{"outputFileName", m_outputFileName},
{"checkpointFrequency", m_checkpointFrequency},
{"hasBoundaryL", m_boundaryL},
{"hasBoundaryR", m_boundaryR},
Expand All @@ -98,7 +99,8 @@ json tsunami_lab::ui::GUI::createConfigJson()
}

// stations
for(Station l_s : m_stations){
for (Station l_s : m_stations)
{
json l_stationData;
l_stationData["name"] = l_s.name;
l_stationData["locX"] = l_s.positionX;
Expand All @@ -109,8 +111,6 @@ json tsunami_lab::ui::GUI::createConfigJson()
return config;
}



// Main code
int tsunami_lab::ui::GUI::launch()
{
Expand Down Expand Up @@ -179,14 +179,11 @@ int tsunami_lab::ui::GUI::launch()

ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);


ImGui::FileBrowser fileDialog;

// (optional) set browser properties
fileDialog.SetTitle("Filesystem");
fileDialog.SetTypeFilters({ ".nc" });


fileDialog.SetTypeFilters({".nc"});

// Main loop
while (!glfwWindowShouldClose(window))
Expand Down Expand Up @@ -293,6 +290,7 @@ int tsunami_lab::ui::GUI::launch()
ImGui::PopStyleColor(3);
ImGui::EndDisabled();

ImGui::PushID(301);
ImGui::InputInt("", &m_clientReadBufferSize, 0);
ImGui::SetItemTooltip("%s", (std::string("in bytes. Default: ") + std::to_string(m_communicator.BUFF_SIZE_DEFAULT)).c_str());
ImGui::SameLine();
Expand All @@ -309,6 +307,28 @@ int tsunami_lab::ui::GUI::launch()
{
m_clientReadBufferSize = 256;
}
ImGui::PopID();

ImGui::PushID(302);
ImGui::InputInt("", &m_serverReadBufferSize, 0);
ImGui::SetItemTooltip("%s", (std::string("in bytes. Default: ") + std::to_string(m_communicator.BUFF_SIZE_DEFAULT)).c_str());
ImGui::SameLine();
if (ImGui::Button("Set"))
{
xlpmg::Message msg = xlpmg::SET_BUFFER_SIZE;
msg.args = m_serverReadBufferSize;
m_communicator.sendToServer(messageToJsonString(msg));
}
ImGui::SetItemTooltip("Sets the input.");
ImGui::SameLine();
ImGui::Text("Buffer size (server)");
ImGui::SameLine();
HelpMarker("Size of the TCP Receive Window: generally the amount of data that the recipient can accept without acknowledging the sender.");
if (m_serverReadBufferSize < 256)
{
m_serverReadBufferSize = 256;
}
ImGui::PopID();
ImGui::EndTabItem();
}

Expand Down Expand Up @@ -394,36 +414,30 @@ int tsunami_lab::ui::GUI::launch()
}
}



// open file dialog when user clicks this button
if(ImGui::Button("Select Bathymetry data file"))
fileDialog.Open();

// open file dialog when user clicks this button
if (ImGui::Button("Select Bathymetry data file"))
fileDialog.Open();

fileDialog.Display();
if(fileDialog.HasSelected())

if (fileDialog.HasSelected())
{
m_bathymetryFilePath = fileDialog.GetSelected().string();
std::cout << "Selected filename" << m_bathymetryFilePath << std::endl;
fileDialog.ClearSelected();
}

if(ImGui::Button("Select Displacement data file"))
fileDialog.Open();
if (ImGui::Button("Select Displacement data file"))
fileDialog.Open();

fileDialog.Display();
if(fileDialog.HasSelected())

if (fileDialog.HasSelected())
{
m_bathymetryFilePath = fileDialog.GetSelected().string();
std::cout << "Selected filename" << m_displacementFilePath << std::endl;
fileDialog.ClearSelected();
}





ImGui::EndTabItem();
}
Expand Down Expand Up @@ -703,6 +717,9 @@ int tsunami_lab::ui::GUI::launch()
HelpMarker("Sets the frequency of writing into a solution file.");
m_writingFrequency = abs(m_writingFrequency);

ImGui::SetNextItemWidth(ImGui::GetFontSize() * width);
ImGui::InputText("Output file name", m_outputFileName, IM_ARRAYSIZE(m_outputFileName));

ImGui::SetNextItemWidth(ImGui::GetFontSize() * width);
ImGui::InputInt("Station capture frequency", &m_stationFrequency, 0);
ImGui::SetItemTooltip("in simulated seconds");
Expand Down Expand Up @@ -836,6 +853,6 @@ int tsunami_lab::ui::GUI::launch()

glfwDestroyWindow(window);
glfwTerminate();

return 0;
}
7 changes: 4 additions & 3 deletions src/ui/GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class tsunami_lab::ui::GUI
std::chrono::time_point<std::chrono::system_clock> m_lastDataUpdate;
float m_dataUpdateFrequency = 1;
int m_clientReadBufferSize = m_communicator.BUFF_SIZE_DEFAULT;
int m_serverReadBufferSize = m_communicator.BUFF_SIZE_DEFAULT;

// compiler options
const char *m_compileModes[5] = {"release", "debug", "release+san", "debug+san", "benchmark"};
Expand Down Expand Up @@ -75,12 +76,12 @@ class tsunami_lab::ui::GUI
const char *m_outputMethods[2] = {"netcdf", "csv"};
int m_outputMethod = 0;
int m_writingFrequency = 100;
char m_outputFileName[256] = "solution.nc";
int m_stationFrequency = 0;
int m_checkpointFrequency = 10;

std::string m_bathymetryFilePath ="";
std::string m_displacementFilePath ="";

std::string m_bathymetryFilePath = "";
std::string m_displacementFilePath = "";

// outflow conditions
bool m_boundaryL = false;
Expand Down

0 comments on commit bf674e6

Please sign in to comment.