The tasks for today are:
General information about labs and grading.
Try a remote method invocation:
Try measuring the time it takes to do a remote call:
Check out a few code snippets:
First-Example
.bash make.sh
to comile the code.bash run-registry.sh
an keep it running.bash run-server.sh localhost
an keep it running.bash run-client.sh localhost
.u2-X.ms.mff.cuni.cz
, where X is a number between 0 an 25u-plX.ms.mff.cuni.cz
bash run-registry.sh
an keep it running.bash run-server.sh HOSTNAME
an keep it running.bash run-client.sh HOSTNAME
.In this part, you will run a program that makes multiple remote calls with increasingly large arguments. We should expect the call to take more time when larger arguments are used. Also, calls made over the network will be slower than on just localhost. We will use a Jupyter notebook to plot the data in a chart.
Measure-Remote-Call
.bash make.sh
to comile the code.bash run-registry.sh
an keep it running.bash run-server.sh localhost
an keep it running.bash run-client.sh localhost 10000 100 > data.csv
.
jupyter notebook
to start a jupyter notebook server.
pip install --user bokeh
measurement.ipynb
.In these labs, you will have to write programs in Java an C++. Basic knowledge of these languages is sufficient, but to make it easier, here are some small tasks that may remind you of how a few particular features work in those languages. You may encounter similar problems when solving the tasks in the following labs.
Identify the problem in the following code and fix it.
public static void main(String[] args){
if(args.length < 1){
System.out.printf("No command given%n");
return;
}
if(command == "generate")
generate();
else if(command == "analyze")
generate();
else
System.out.printf("Unknown command %s%n", command);
}
Fix the following code, so that it works correctly when the methods increment and read are called form different threads.
class Data {
private int counter;
public void inc(){
++counter;
}
public int read(){
return counter;
}
}
Identify the problem in the following code and fix it.
class Data{
string value;
}
class Component{
Data* data;
Component(Data* data): data(data){}
}
shared_ptr<Component> create_component(){
Data data;
return make_shared<Component>(&data);
}
Implement the following function which checks whether two map collection contain the same elements (the same key-value pairs). (Hint: it might be easier than you expect).
bool check_equal(
std::map<string, string> mapA,
std::map<string, string> mapB) {
}
Given the class hierarchy, implement the following function which prints the value from every object it receives.
(Hint:
Either add virtual
methods to the classes, or check the type using dynamic_cast
.
class Base {}
class A: public Base { public: int value; }
class B: public Base { public: string value; }
class C: public Base { public: bool value; }
void print(Base& object){
}