first commit
This commit is contained in:
8
HW2/.idea/HW2.iml
generated
Normal file
8
HW2/.idea/HW2.iml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="CPP_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
5
HW2/.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
HW2/.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default (1)" />
|
||||
</state>
|
||||
</component>
|
||||
6
HW2/.idea/misc.xml
generated
Normal file
6
HW2/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptSettings">
|
||||
<option name="languageLevel" value="ES6" />
|
||||
</component>
|
||||
</project>
|
||||
8
HW2/.idea/modules.xml
generated
Normal file
8
HW2/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/HW2.iml" filepath="$PROJECT_DIR$/.idea/HW2.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
73
HW2/.idea/workspace.xml
generated
Normal file
73
HW2/.idea/workspace.xml
generated
Normal file
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CMakeRunConfigurationManager" shouldGenerate="true" shouldDeleteObsolete="true">
|
||||
<generated />
|
||||
</component>
|
||||
<component name="CMakeSettings">
|
||||
<configurations>
|
||||
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
|
||||
</configurations>
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="db4b0ad8-3df1-4d57-99f9-c33ff653fa4d" name="Default Changelist" comment="" />
|
||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="MacroExpansionManager">
|
||||
<option name="directoryName" value="oCqQcuAS" />
|
||||
</component>
|
||||
<component name="ProjectId" id="1WrvLNA25MRJDiwrDMbW64GxgRQ" />
|
||||
<component name="PropertiesComponent">
|
||||
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||
<property name="cf.advertisement.text.overridden" value="true" />
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||
<property name="node.js.detected.package.eslint" value="true" />
|
||||
<property name="node.js.detected.package.tslint" value="true" />
|
||||
<property name="node.js.path.for.package.eslint" value="project" />
|
||||
<property name="node.js.path.for.package.tslint" value="project" />
|
||||
<property name="node.js.selected.package.eslint" value="(autodetect)" />
|
||||
<property name="node.js.selected.package.tslint" value="(autodetect)" />
|
||||
<property name="nodejs_package_manager_path" value="npm" />
|
||||
<property name="settings.editor.selected.configurable" value="configurable.group.editor" />
|
||||
</component>
|
||||
<component name="RunAnythingCache">
|
||||
<option name="myCommands">
|
||||
<command value="mpic++ Bomb.cpp" />
|
||||
</option>
|
||||
</component>
|
||||
<component name="RunDashboard">
|
||||
<option name="ruleStates">
|
||||
<list>
|
||||
<RuleState>
|
||||
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
|
||||
</RuleState>
|
||||
<RuleState>
|
||||
<option name="name" value="StatusDashboardGroupingRule" />
|
||||
</RuleState>
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="SvnConfiguration">
|
||||
<configuration />
|
||||
</component>
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="db4b0ad8-3df1-4d57-99f9-c33ff653fa4d" name="Default Changelist" comment="" />
|
||||
<created>1579920470301</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1579920470301</updated>
|
||||
<workItem from="1579920471772" duration="302000" />
|
||||
<workItem from="1581113415105" duration="1270000" />
|
||||
<workItem from="1582065771175" duration="599000" />
|
||||
<workItem from="1582942689064" duration="377000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="1" />
|
||||
</component>
|
||||
</project>
|
||||
54
HW2/Bomb.cpp
Normal file
54
HW2/Bomb.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include <iostream>
|
||||
#include <mpi.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
//#include "/usr/local/include/mpi.h"
|
||||
#define MCW MPI_COMM_WORLD
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
int rank, size;
|
||||
int data;
|
||||
int dest;
|
||||
MPI_Init(&argc, &argv);
|
||||
MPI_Comm_rank(MCW, &rank);
|
||||
MPI_Comm_size(MCW, &size);
|
||||
srand(rank);
|
||||
|
||||
if(rank == 0){
|
||||
data = rand % 20;
|
||||
cout << "Timer is set to " << data << endl;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
MPI_Recv(&data, 1, MPI_INT, MPI_ANY_SOURCE, 0, MCW, MPI_STATUS_IGNORE);
|
||||
dest = rank++;
|
||||
|
||||
if (!(rand() % 5)) {
|
||||
data = -1;
|
||||
for (int i = 0; i < size; ++i)
|
||||
MPI_Send(&data, 1, MPI_INT, i, 0, MCW);
|
||||
}
|
||||
|
||||
if (data != 0) {
|
||||
data--;
|
||||
} else {
|
||||
dest = rank - 1;
|
||||
if (dest < 0)
|
||||
dest = size - 1;
|
||||
}
|
||||
|
||||
MPI_Send(&data, 1, MPI_INT, dest, 0, MCW);
|
||||
|
||||
|
||||
cout<<"rank "<<rank<<" is done.\n";
|
||||
|
||||
MPI_Finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
63
HW2/pachinko.cpp
Normal file
63
HW2/pachinko.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <time.h>
|
||||
#include <iostream>
|
||||
#include <mpi.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
//#include "/usr/local/include/mpi.h"
|
||||
#define MCW MPI_COMM_WORLD
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
int rank, size;
|
||||
int data;
|
||||
int dest;
|
||||
MPI_Init(&argc, &argv);
|
||||
MPI_Comm_rank(MCW, &rank);
|
||||
MPI_Comm_size(MCW, &size);
|
||||
srand(time(NULL));
|
||||
|
||||
|
||||
if(rank==0){
|
||||
for(int i=0;i<size;++i)cout<<" "<<i<<" ";
|
||||
cout<<endl;
|
||||
|
||||
data=rand() % 20;
|
||||
MPI_Send(&data,1,MPI_INT,0,0,MCW);
|
||||
}
|
||||
|
||||
while(1){
|
||||
MPI_Recv(&data,1,MPI_INT,MPI_ANY_SOURCE,0,MCW,MPI_STATUS_IGNORE);
|
||||
if(data<0)break;
|
||||
sleep(1);
|
||||
for(int i=0;i<rank;++i)cout<<" ";
|
||||
cout<< data <<endl;
|
||||
|
||||
if(data != 0){
|
||||
data --;
|
||||
}else{
|
||||
cout << rank << " Is the Loser" << endl;
|
||||
cout << endl << endl;
|
||||
for(int i = 0; i < size; i++){
|
||||
data=-1;
|
||||
for(int i=0;i<size;++i) MPI_Send(&data,1,MPI_INT,i,0,MCW);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
dest = rand() % size;
|
||||
if(dest == rank){
|
||||
dest = dest -1;
|
||||
}
|
||||
|
||||
MPI_Send(&data,1,MPI_INT,dest,0,MCW);
|
||||
}
|
||||
cout<<"rank "<<rank<<" is done.\n";
|
||||
|
||||
MPI_Finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user