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;
|
||||
}
|
||||
|
||||
73
HW3/parallelSort.cpp
Normal file
73
HW3/parallelSort.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#include <iostream>
|
||||
#include <mpi.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
|
||||
//#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);
|
||||
int masterArray[size*20];
|
||||
|
||||
|
||||
//if master process create array and scatter:
|
||||
if(rank == 0){
|
||||
for(int i = 0; i < size * 20; i++){
|
||||
masterArray[i] = rand()%100 + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int subArray[20];
|
||||
MPI_Scatter(masterArray, 20, MPI_INT,subArray,20, MPI_INT,0,MCW);
|
||||
vector<int> subVector;
|
||||
for(int i = 0; i < 20; i++){
|
||||
subVector.push_back(subArray[i]);
|
||||
}
|
||||
sort(subVector.begin(), subVector.end());
|
||||
for(int i = 0; i < 20; i++){
|
||||
subArray[i] = subVector[i];
|
||||
}
|
||||
|
||||
int mainArray[20*size];
|
||||
MPI_Gather(&subArray, 20, MPI_INT, mainArray, 20, MPI_INT, 0, MCW);
|
||||
|
||||
if(rank == 0){
|
||||
vector<int> mainVector;
|
||||
for(int i = 0; i < 20*size; i++){
|
||||
mainVector.push_back(mainArray[i]);
|
||||
}
|
||||
inplace_merge(mainVector.begin(), mainVector.begin() + 20, mainVector.begin() + 40);
|
||||
inplace_merge(mainVector.begin() + 40, mainVector.begin() + 60, mainVector.end());
|
||||
inplace_merge(mainVector.begin(), mainVector.begin() + 40, mainVector.end());
|
||||
cout << "------Original Array------" << endl;
|
||||
for(int i = 0; i < 20*size; i++){
|
||||
cout << " " << masterArray[i];
|
||||
}
|
||||
cout << endl << endl<<"------Sorted Array-----" << endl << endl;
|
||||
for(int i = 0; i < 20*size; i++){
|
||||
cout <<" " << mainVector[i];
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
MPI_Finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
160
HW3/test.cpp
Normal file
160
HW3/test.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include "mpi.h"
|
||||
|
||||
void High(int bit);
|
||||
void Low(int bit);
|
||||
int Comparison(const void * x, const void * y);
|
||||
|
||||
#define MASTER 0
|
||||
#define NUMBER 10
|
||||
|
||||
int * array;
|
||||
int array_size;
|
||||
int process_rank;
|
||||
int num_processes;
|
||||
double start_time;
|
||||
double end_time;
|
||||
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
MPI_Init(&argc, &argv);
|
||||
MPI_Comm_size(MPI_COMM_WORLD, &num_processes);
|
||||
MPI_Comm_rank(MPI_COMM_WORLD, &process_rank);
|
||||
|
||||
array_size = atoi(argv[1]) / num_processes;
|
||||
array = (int *)malloc(array_size * sizeof(int));
|
||||
srand(time(NULL));
|
||||
int i, j;
|
||||
for (i = 0; i < array_size; i++) {
|
||||
array[i] = rand() % (atoi(argv[1]));
|
||||
}
|
||||
|
||||
MPI_Barrier(MPI_COMM_WORLD);
|
||||
int stages = (int)(log2(num_processes));
|
||||
if (process_rank == MASTER) {
|
||||
printf("Number of Processes is: %d\n", num_processes);
|
||||
timer_start = MPI_Wtime();
|
||||
}
|
||||
|
||||
qsort(array, array_size, sizeof(int), Comparison);
|
||||
for (i = 0; i < stages; i++) {
|
||||
for (j = i; j >= 0; j--) {
|
||||
|
||||
printf("%d ",process_rank>>(i+1));
|
||||
if (((process_rank >> (i + 1)) % 2 == 0 && (process_rank >> j) % 2 == 0) || ((process_rank >> (i + 1)) % 2 != 0 && (process_rank >> j) % 2 != 0)) {
|
||||
Low(j);
|
||||
}
|
||||
else {
|
||||
High(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MPI_Barrier(MPI_COMM_WORLD);
|
||||
|
||||
if (process_rank == MASTER) {
|
||||
end_time = MPI_Wtime();
|
||||
|
||||
printf("Sample sorted array for verification(10 elements)\n");
|
||||
|
||||
for (i = 0; i < array_size; i++) {
|
||||
if ((i % (array_size / NUMBER)) == 0) {
|
||||
printf("%d ", array[i]);
|
||||
}
|
||||
}
|
||||
printf("Time in seconds : %f\n", end_time - start_time);
|
||||
}
|
||||
|
||||
free(array);
|
||||
MPI_Finalize();
|
||||
return 0;
|
||||
}
|
||||
void High(int j) {
|
||||
int i, max;
|
||||
|
||||
|
||||
int counter_receive;
|
||||
int * buffer_recieve = (int *)malloc((array_size + 1) * sizeof(int));
|
||||
MPI_Recv(&max, 1, MPI_INT, process_rank ^ (1 << j), 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE );
|
||||
|
||||
|
||||
int counter_send = 0;
|
||||
int * buffer_send = (int *)malloc((array_size + 1) * sizeof(int));
|
||||
MPI_Send(&array[0], 1, MPI_INT, process_rank ^ (1 << j), 0, MPI_COMM_WORLD);
|
||||
|
||||
|
||||
for (i = 0; i < array_size; i++) {
|
||||
if (array[i] < max) {
|
||||
buffer_send[counter_send + 1] = array[i];
|
||||
counter_send++;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
MPI_Recv(buffer_recieve, array_size, MPI_INT, process_rank ^ (1 << j), 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE );
|
||||
counter_receive = buffer_recieve[0];
|
||||
buffer_send[0] = counter_send;
|
||||
MPI_Send(buffer_send, counter_send, MPI_INT, process_rank ^ (1 << j), 0, MPI_COMM_WORLD);
|
||||
|
||||
for (i = 1; i < counter_receive + 1; i++) {
|
||||
if (buffer_recieve[i] > array[0]) {
|
||||
array[0] = buffer_recieve[i];
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
qsort(array, array_size, sizeof(int), ComparisonFunc);
|
||||
free(buffer_send);
|
||||
free(buffer_recieve);
|
||||
}
|
||||
|
||||
void Low(int j) {
|
||||
int i, min;
|
||||
|
||||
|
||||
int counter_send = 0;
|
||||
int * buffer_send = (int *)malloc((array_size + 1) * sizeof(int));
|
||||
MPI_Send(&array[array_size - 1],1,MPI_INT,process_rank ^ (1 << j),0,MPI_COMM_WORLD);
|
||||
int counter_receive;
|
||||
int * buffer_recieve = (int *)malloc((array_size + 1) * sizeof(int));
|
||||
MPI_Recv(&min,1,MPI_INT,process_rank ^ (1 << j),0,MPI_COMM_WORLD,MPI_STATUS_IGNORE);
|
||||
|
||||
|
||||
for (i = 0; i < array_size; i++) {
|
||||
if (array[i] > min) {
|
||||
buffer_send[counter_send + 1] = array[i];
|
||||
counter_send++;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
buffer_send[0] = counter_send;
|
||||
MPI_Send(buffer_send,counter_send,MPI_INT,process_rank ^ (1 << j),0,MPI_COMM_WORLD);
|
||||
MPI_Recv(buffer_recieve,array_size,MPI_INT,process_rank ^ (1 << j),0,MPI_COMM_WORLD,MPI_STATUS_IGNORE);
|
||||
|
||||
for (i = 1; i < buffer_recieve[0] + 1; i++) {
|
||||
if (array[array_size - 1] < buffer_recieve[i]) {
|
||||
|
||||
array[array_size - 1] = buffer_recieve[i];
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
qsort(array, array_size, sizeof(int), ComparisonFunc);
|
||||
free(buffer_send);
|
||||
free(buffer_recieve);
|
||||
|
||||
}
|
||||
|
||||
int Comparison(const void * x, const void * y) {
|
||||
return (*(int *)x - *(int *)y);
|
||||
}
|
||||
33
HW4/bitonic.cpp
Normal file
33
HW4/bitonic.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
#include <mpi.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
|
||||
//#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 = [5, 10, 3, 6, 8, 34, 45, 23, 68, 79, 20, 27, 99];
|
||||
int arraySize;
|
||||
int dest;
|
||||
MPI_Init(&argc, &argv);
|
||||
MPI_Comm_rank(MCW, &rank);
|
||||
MPI_Comm_size(MCW, &size);
|
||||
srand(rank);
|
||||
|
||||
arraySize = i
|
||||
|
||||
MPI_Finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
127
HW5/main.cpp
Normal file
127
HW5/main.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
#include <mpi.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctime>
|
||||
#define MCW MPI_COMM_WORLD
|
||||
using namespace std;
|
||||
int main(int argc, char **argv){
|
||||
int rank, size;
|
||||
int data;
|
||||
int dest;
|
||||
int N = 6;
|
||||
MPI_Init(&argc, &argv); MPI_Comm_rank(MCW, &rank);
|
||||
MPI_Comm_size(MCW, &size);
|
||||
|
||||
int slice= N/size;
|
||||
int* C=(int*)malloc(sizeof(int) *(N/size));
|
||||
bool finished;
|
||||
//random number generator
|
||||
std::random_device dev;
|
||||
std::mt19937 rng(dev());
|
||||
std::uniform_int_distribution<std::mt19937::result_type> dist5(1,5); // distribution in range [1, 6]
|
||||
|
||||
//initialize array
|
||||
int **strip;
|
||||
int **world, *worldData;
|
||||
if(rank == 0){
|
||||
worldData = (int *)malloc(sizeof(int)*N*N);
|
||||
world = (int **)malloc(sizeof(int*) * N);
|
||||
for(int i = 0; i < N; i++) {
|
||||
world[i] = &(worldData[i*N]);
|
||||
}
|
||||
|
||||
//Sets up world
|
||||
for(int i = 0; i < N; i++){
|
||||
for( int j =0; j < N; j++){
|
||||
if(dist5(rng) == 1){
|
||||
world[i][j] = 1;
|
||||
}else{
|
||||
world[i][j] = 0;
|
||||
}
|
||||
cout << world[i][j] << " ";;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
cout << endl << endl;
|
||||
finished = false;
|
||||
}
|
||||
MPI_Barrier(MCW);
|
||||
|
||||
|
||||
|
||||
do{
|
||||
//Give everyone the current state of 2d array.
|
||||
// MPI_Bcast (&&world, N, MPI_INT, 0, MCW);
|
||||
|
||||
int from = rank * N/size;
|
||||
int to = ((rank+1) * N/size);
|
||||
|
||||
//Do Computations.
|
||||
for(int i = 0; i < N; i++){
|
||||
// Scatter the random numbers to all processes
|
||||
MPI_Scatter (worldData, N/size, MPI_INT, C, N/size, MPI_INT, 0, MCW);
|
||||
for(int j = from; j < to; j++){
|
||||
// cout << "From " << from<<" TO: " << to <<" process: " << rank <<" j: " << j << " i: " << i<< endl;
|
||||
int neighbors = 0;
|
||||
//Above 3 cells
|
||||
if(i - 1 >= 0)
|
||||
if(world[i-1][j]==1)
|
||||
neighbors++;
|
||||
if(j-1 >= 0)
|
||||
if(world[i-1][j-1]==1)
|
||||
neighbors++;
|
||||
if(j+1 < N)
|
||||
if(world[i-1][j+1]==1)
|
||||
neighbors++;
|
||||
//Below 3 Cells
|
||||
if(i + 1 < N)
|
||||
if(world[i+1][j]==1)
|
||||
neighbors++;
|
||||
if(j-1 >= 0)
|
||||
if(world[i+1][j-1]==1)
|
||||
neighbors++;
|
||||
if(j+1 < N)
|
||||
if(world[i+1][j+1]==1)
|
||||
neighbors++;
|
||||
//To the side of us same row
|
||||
if(j + 1 < N)
|
||||
if(world[i][j+1]==1)
|
||||
neighbors++;
|
||||
if(j - 1 >= 0)
|
||||
if(world[i][j-1]==1)
|
||||
neighbors++;
|
||||
//If neighbors are to many or few i die.
|
||||
if(neighbors > 3 || neighbors <2)
|
||||
C[0]=0;
|
||||
//If my neighbors = 2/3 I live, or if I am dead and neighbors = 3 I come alive.
|
||||
else if(neighbors == 3){
|
||||
C[0]=1;
|
||||
}else{
|
||||
C[0]=world[i][j];
|
||||
}
|
||||
}
|
||||
//Gather all of it back up.
|
||||
MPI_Gather (&C[0], N/size, MPI_INT, worldData, N/size, MPI_INT, 0, MCW);
|
||||
|
||||
|
||||
}
|
||||
if(rank == 0){
|
||||
for(int x = 0; x < N; x++){
|
||||
for( int y = 0; y < N; y++){
|
||||
cout << world[x][y] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
cout << endl << endl << endl;
|
||||
finished = true;
|
||||
for( int i = 0; i<N*N; i++){
|
||||
if(worldData[i]!=0)
|
||||
finished = false;
|
||||
}
|
||||
}
|
||||
}while(!finished);
|
||||
|
||||
MPI_Finalize();
|
||||
}
|
||||
33
Mandelbrot/gather.cpp
Normal file
33
Mandelbrot/gather.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
#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 bigData[16];
|
||||
MPI_Init(&argc, &argv);
|
||||
MPI_Comm_rank(MCW, &rank);
|
||||
MPI_Comm_size(MCW, &size);
|
||||
data = rank;
|
||||
|
||||
MPI_Gather(&data,1,MPI_INT,bigData,1,MPI_INT,0,MCW);
|
||||
if(!rank)for(int i=0;i<size;++i)cout<<bigData[i];
|
||||
cout<<endl;
|
||||
|
||||
|
||||
|
||||
|
||||
MPI_Finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
136
Mandelbrot/main.cpp
Normal file
136
Mandelbrot/main.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <mpi.h>
|
||||
#include <string>
|
||||
#include <tclDecls.h>
|
||||
#include <vector>
|
||||
|
||||
#define MCW MPI_COMM_WORLD
|
||||
using namespace std;
|
||||
|
||||
const int Master = 0;
|
||||
|
||||
struct Color {
|
||||
int red;
|
||||
int green;
|
||||
int blue;
|
||||
};
|
||||
|
||||
struct MandelbrotConfig {
|
||||
int width;
|
||||
int height;
|
||||
double xComplexMin;
|
||||
double xComplexMax;
|
||||
double yComplexMin;
|
||||
double yComplexMax;
|
||||
double maxIterations;
|
||||
Color colorOne;
|
||||
Color colorTwo;
|
||||
string outputFileName;
|
||||
};
|
||||
|
||||
MandelbrotConfig readConfig(string configFile){
|
||||
ifstream fin;
|
||||
MandelbrotConfig config;
|
||||
|
||||
fin.open(configFile);
|
||||
if (fin){
|
||||
fin >> config.width >> config.height;
|
||||
fin >> config.xComplexMin >> config.xComplexMax;
|
||||
fin >> config.yComplexMin >> config.yComplexMax;
|
||||
fin >> config.maxIterations;
|
||||
fin >> config.colorOne.red >> config.colorOne.green >> config.colorOne.blue;
|
||||
fin >> config.colorTwo.red >> config.colorTwo.green >> config.colorTwo.blue;
|
||||
fin >> config.outputFileName;
|
||||
fin.close();
|
||||
|
||||
}
|
||||
if(!fin){
|
||||
cout << "Could not open File";
|
||||
}
|
||||
return config;
|
||||
}
|
||||
Color getPixelColor(Color color1, Color color2, double iterations, double maxIterations) {
|
||||
Color colorReturn;
|
||||
double myColorR = static_cast<double>((color2.red - color1.red) / maxIterations);
|
||||
double myColorG = static_cast<double>((color2.green - color1.green) / maxIterations);
|
||||
double myColorB = static_cast<double>((color2.blue - color1.blue) / maxIterations);
|
||||
colorReturn.red = (color1.red + (iterations * myColorR));
|
||||
colorReturn.green = (color1.green + (iterations * myColorG));
|
||||
colorReturn.blue = (color1.blue + (iterations * myColorB));
|
||||
return colorReturn;
|
||||
}
|
||||
|
||||
void writeFile(MandelbrotConfig config, std::vector<std::vector<Color>> array){
|
||||
ofstream fout;
|
||||
fout.open(config.outputFileName);
|
||||
fout << "P3" << endl;
|
||||
fout << config.width << " " << config.height << endl;
|
||||
fout << "255" << endl;
|
||||
for(int i = 0; i < config.height; i++){
|
||||
for(int j = 0; j < config.width; j++){
|
||||
Color Pixel = array[i][j];
|
||||
fout << Pixel.red << " " << Pixel.green << " " << Pixel.blue << " ";
|
||||
}
|
||||
fout << endl;
|
||||
}
|
||||
fout.close();
|
||||
}
|
||||
|
||||
void drawMandelbrot(MandelbrotConfig config, int world_rank){
|
||||
double pixelWidth = ((config.xComplexMax-config.xComplexMin)/config.width);
|
||||
double pixelHeight = ((config.yComplexMax-config.yComplexMin)/config.height);
|
||||
std::vector<std::vector<Color>> pixels(config.height, std::vector<Color> (config.width));
|
||||
std::vector<Color> sub_pixels;
|
||||
for (int i = 0; i < config.height; i++){
|
||||
if(world_rank == 0){
|
||||
MPI_Scatter(*pixels, config.width, MPI_Vector, sub_pixels,
|
||||
config.width, MPI_Vector, 0, MCW);
|
||||
}
|
||||
else{
|
||||
for (int j = 0; j< config.width; j++) {
|
||||
double x0 = config.xComplexMin + j * pixelWidth;
|
||||
double y0 = config.yComplexMin + i * pixelHeight;
|
||||
double x = 0;
|
||||
double y = 0;
|
||||
double iteration = 0;
|
||||
while ((x * x) + (y * y) < (2 * 2) &&
|
||||
iteration < config.maxIterations) {
|
||||
double xtemp = (x * x) - (y * y) + x0;
|
||||
y = 2 * x * y + y0;
|
||||
x = xtemp;
|
||||
iteration = iteration + 1;
|
||||
}
|
||||
Color Pixel = getPixelColor(config.colorOne, config.colorTwo,
|
||||
iteration, config.maxIterations);
|
||||
pixels[i][j] = Pixel;
|
||||
}
|
||||
}
|
||||
}
|
||||
writeFile(config, pixels);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
string configFile;
|
||||
MandelbrotConfig config;
|
||||
|
||||
// Read in config file location from user
|
||||
cout << "Mandelbrot Config File: ";
|
||||
cin >> configFile;
|
||||
// Read config file contents into MandelbrotConfig struct instance
|
||||
config = readConfig(configFile);
|
||||
// Compute and write specified mandelbrot image to PPM file
|
||||
// drawMandelbrot(config);
|
||||
int rank , size;
|
||||
int data;
|
||||
MPI_Init (&argc , &argv);
|
||||
MPI_Comm_rank(MCW , &rank);
|
||||
MPI_Comm_size(MCW , &size);
|
||||
|
||||
|
||||
drawMandelbrot(config);
|
||||
MPI_Finalize();
|
||||
return 0;
|
||||
}
|
||||
2
Parallel_Mandelbrot/.idea/Parallel_Mandelbrot.iml
generated
Normal file
2
Parallel_Mandelbrot/.idea/Parallel_Mandelbrot.iml
generated
Normal file
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module classpath="CMake" type="CPP_MODULE" version="4" />
|
||||
5
Parallel_Mandelbrot/.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
Parallel_Mandelbrot/.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>
|
||||
7
Parallel_Mandelbrot/.idea/misc.xml
generated
Normal file
7
Parallel_Mandelbrot/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
|
||||
<component name="JavaScriptSettings">
|
||||
<option name="languageLevel" value="ES6" />
|
||||
</component>
|
||||
</project>
|
||||
8
Parallel_Mandelbrot/.idea/modules.xml
generated
Normal file
8
Parallel_Mandelbrot/.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/Parallel_Mandelbrot.iml" filepath="$PROJECT_DIR$/.idea/Parallel_Mandelbrot.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
78
Parallel_Mandelbrot/.idea/workspace.xml
generated
Normal file
78
Parallel_Mandelbrot/.idea/workspace.xml
generated
Normal file
@@ -0,0 +1,78 @@
|
||||
<?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="433d4815-90d2-4f07-b6e7-1be1c938fd77" 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="tEvmtquu" />
|
||||
</component>
|
||||
<component name="ProjectId" id="1Xs1G1e6LWQK7dokdx2n2NRYwiX" />
|
||||
<component name="PropertiesComponent">
|
||||
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||
<property name="cf.advertisement.text.overridden" value="true" />
|
||||
<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="settings.editor.selected.configurable" value="configurable.group.editor" />
|
||||
</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="RunManager" selected="GDB Remote Debug.test">
|
||||
<configuration name="test" type="CLion_Remote" remoteCommand="" symbolFile="" sysroot="">
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<configuration name="Unnamed" type="CMakeRunConfiguration" factoryName="Application" nameIsGenerated="true" PASS_PARENT_ENVS_2="true">
|
||||
<method v="2">
|
||||
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<list>
|
||||
<item itemvalue="CMake Application.Unnamed" />
|
||||
<item itemvalue="GDB Remote Debug.test" />
|
||||
</list>
|
||||
</component>
|
||||
<component name="SvnConfiguration">
|
||||
<configuration />
|
||||
</component>
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="433d4815-90d2-4f07-b6e7-1be1c938fd77" name="Default Changelist" comment="" />
|
||||
<created>1581819888474</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1581819888474</updated>
|
||||
<workItem from="1581819892578" duration="3674000" />
|
||||
<workItem from="1582065771176" duration="11561000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="1" />
|
||||
</component>
|
||||
</project>
|
||||
BIN
Parallel_Mandelbrot/a.out
Executable file
BIN
Parallel_Mandelbrot/a.out
Executable file
Binary file not shown.
33
Parallel_Mandelbrot/gather.cpp
Normal file
33
Parallel_Mandelbrot/gather.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
#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 bigData[16];
|
||||
MPI_Init(&argc, &argv);
|
||||
MPI_Comm_rank(MCW, &rank);
|
||||
MPI_Comm_size(MCW, &size);
|
||||
data = rank;
|
||||
|
||||
MPI_Gather(&data,1,MPI_INT,bigData,1,MPI_INT,0,MCW);
|
||||
if(rank == 0)for(int i=0;i<size;++i)cout<<bigData[i];
|
||||
cout<<endl;
|
||||
|
||||
|
||||
|
||||
|
||||
MPI_Finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
155
Parallel_Mandelbrot/main.cpp
Normal file
155
Parallel_Mandelbrot/main.cpp
Normal file
@@ -0,0 +1,155 @@
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <mpi.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
///
|
||||
/// http://wili.cc/blog/mandelbrot-mpi.html
|
||||
///
|
||||
#define MCW MPI_COMM_WORLD
|
||||
using namespace std;
|
||||
|
||||
const int Master = 0;
|
||||
|
||||
struct Color {
|
||||
int red;
|
||||
int green;
|
||||
int blue;
|
||||
};
|
||||
|
||||
struct MandelbrotConfig {
|
||||
int width;
|
||||
int height;
|
||||
double xComplexMin;
|
||||
double xComplexMax;
|
||||
double yComplexMin;
|
||||
double yComplexMax;
|
||||
double maxIterations;
|
||||
Color colorOne;
|
||||
Color colorTwo;
|
||||
string outputFileName;
|
||||
};
|
||||
|
||||
MandelbrotConfig readConfig(string configFile){
|
||||
ifstream fin;
|
||||
MandelbrotConfig config;
|
||||
|
||||
fin.open(configFile);
|
||||
if (fin){
|
||||
fin >> config.width >> config.height;
|
||||
fin >> config.xComplexMin >> config.xComplexMax;
|
||||
fin >> config.yComplexMin >> config.yComplexMax;
|
||||
fin >> config.maxIterations;
|
||||
fin >> config.colorOne.red >> config.colorOne.green >> config.colorOne.blue;
|
||||
fin >> config.colorTwo.red >> config.colorTwo.green >> config.colorTwo.blue;
|
||||
fin >> config.outputFileName;
|
||||
fin.close();
|
||||
|
||||
}
|
||||
if(!fin){
|
||||
cout << "Could not open File";
|
||||
}
|
||||
return config;
|
||||
}
|
||||
Color getPixelColor(Color color1, Color color2, double iterations, double maxIterations) {
|
||||
Color colorReturn;
|
||||
double myColorR = static_cast<double>((color2.red - color1.red) / maxIterations);
|
||||
double myColorG = static_cast<double>((color2.green - color1.green) / maxIterations);
|
||||
double myColorB = static_cast<double>((color2.blue - color1.blue) / maxIterations);
|
||||
colorReturn.red = (color1.red + (iterations * myColorR));
|
||||
colorReturn.green = (color1.green + (iterations * myColorG));
|
||||
colorReturn.blue = (color1.blue + (iterations * myColorB));
|
||||
return colorReturn;
|
||||
}
|
||||
|
||||
void writeFile(MandelbrotConfig config, std::vector<std::vector<Color> > array){
|
||||
ofstream fout;
|
||||
fout.open(config.outputFileName);
|
||||
fout << "P3" << endl;
|
||||
fout << config.width << " " << config.height << endl;
|
||||
fout << "255" << endl;
|
||||
for(int i = 0; i < config.height; i++){
|
||||
for(int j = 0; j < config.width; j++){
|
||||
Color Pixel = array[i][j];
|
||||
fout << Pixel.red << " " << Pixel.green << " " << Pixel.blue << " ";
|
||||
}
|
||||
fout << endl;
|
||||
}
|
||||
fout.close();
|
||||
}
|
||||
|
||||
void drawMandelbrot(MandelbrotConfig config, int rank, int &worldsize){
|
||||
double pixelWidth = ((config.xComplexMax-config.xComplexMin)/config.width);
|
||||
double pixelHeight = ((config.yComplexMax-config.yComplexMin)/config.height);
|
||||
std::vector<std::vector<Color> > pixels(config.height, std::vector<Color> (config.width));
|
||||
std::vector<Color> sub_pixels;
|
||||
|
||||
int *displace;
|
||||
displace = (int *)calloc(worldsize,sizeof(int));
|
||||
int *dim_list;
|
||||
dim_list = (int *)calloc(worldsize,sizeof(int));
|
||||
int j = 0;
|
||||
for (int i=0; i<worldsize; i++) {
|
||||
displace[i] = j;
|
||||
cout << "displace[" << i << "] = " << displace[i] << endl;
|
||||
j += config.width;
|
||||
dim_list[i] = config.width;
|
||||
}
|
||||
|
||||
|
||||
MPI_Scatterv(&(pixels), sendcounts, displs, MPI_INT, &sub_pixels,
|
||||
100, MPI_INT, 0, MCW);
|
||||
for(int i = 0; i < config.height; i++) {
|
||||
int _i = i * (rank + 1);
|
||||
|
||||
for (int j = 0; j < config.width; j++) {
|
||||
double x0 = config.xComplexMin + j * pixelWidth;
|
||||
double y0 = config.yComplexMin + _i * pixelHeight;
|
||||
double x = 0;
|
||||
double y = 0;
|
||||
double iteration = 0;
|
||||
while ((x * x) + (y * y) < (2 * 2) && iteration < config.maxIterations) {
|
||||
double xtemp = (x * x) - (y * y) + x0;
|
||||
y = 2 * x * y + y0;
|
||||
x = xtemp;
|
||||
iteration = iteration + 1;
|
||||
}
|
||||
Color Pixel = getPixelColor(config.colorOne, config.colorTwo, iteration,
|
||||
config.maxIterations);
|
||||
pixels[i][j] = Pixel;
|
||||
}
|
||||
}
|
||||
if (!rank) {
|
||||
MPI_Gatherv(&sub_pixels,config.width,MPI_INT,&pixels,&dim_list[rank],&displace[rank],MPI_INT,0,MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
|
||||
writeFile(config, pixels);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
string configFile;
|
||||
MandelbrotConfig config;
|
||||
int rank , size;
|
||||
int data;
|
||||
MPI_Init (&argc , &argv);
|
||||
MPI_Comm_rank(MCW , &rank);
|
||||
MPI_Comm_size(MCW , &size);
|
||||
if(rank == 0) {
|
||||
// Read in config file location from user
|
||||
cout << "Mandelbrot Config File: ";
|
||||
cin >> configFile;
|
||||
// Read config file contents into MandelbrotConfig struct instance
|
||||
config = readConfig(configFile);
|
||||
// Compute and write specified mandelbrot image to PPM file
|
||||
// drawMandelbrot(config);
|
||||
}
|
||||
|
||||
|
||||
|
||||
drawMandelbrot(config, rank, size);
|
||||
MPI_Finalize();
|
||||
return 0;
|
||||
}
|
||||
35
Parallel_Mandelbrot/scatter.cpp
Normal file
35
Parallel_Mandelbrot/scatter.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
|
||||
#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 bigData[16];
|
||||
cout << rank;
|
||||
if(!rank)cout << endl << rank;for(int i=0;i<16;++i)bigData[i]=i;
|
||||
|
||||
MPI_Init(&argc, &argv);
|
||||
MPI_Comm_rank(MCW, &rank);
|
||||
MPI_Comm_size(MCW, &size);
|
||||
|
||||
MPI_Scatter(bigData,1,MPI_INT,&data,1,MPI_INT,0,MCW);
|
||||
cout<<"rank"<<rank<<" "<<data<<endl;
|
||||
|
||||
|
||||
|
||||
|
||||
MPI_Finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
7
Parallel_Mandelbrot/seahorse.txt
Normal file
7
Parallel_Mandelbrot/seahorse.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
512 512
|
||||
- 0.75 -0.74
|
||||
0.1 0.11
|
||||
1000
|
||||
255 165 0
|
||||
0 0 64
|
||||
seahorse.ppm
|
||||
0
Parallel_Mandelbrot/testGather.cpp
Normal file
0
Parallel_Mandelbrot/testGather.cpp
Normal file
1
cs5500.s20
Symbolic link
1
cs5500.s20
Symbolic link
@@ -0,0 +1 @@
|
||||
/Users/bradybodily/Google Drive File Stream/My Drive/cs5500.s20
|
||||
BIN
example/a.out
Executable file
BIN
example/a.out
Executable file
Binary file not shown.
70
example/cubeICN.cpp
Normal file
70
example/cubeICN.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
|
||||
|
||||
#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;
|
||||
|
||||
void allPrint(int data){
|
||||
int array[64];
|
||||
int rank, size;
|
||||
|
||||
MPI_Comm_rank(MCW, &rank);
|
||||
MPI_Comm_size(MCW, &size);
|
||||
|
||||
MPI_Gather(&data,1,MPI_INT,array,1,MPI_INT,0,MCW);
|
||||
if(!rank){
|
||||
for(int i=0;i<size;++i)cout<<i<<" ";
|
||||
cout<<endl;
|
||||
for(int i=0;i<size;++i)cout<<array[i]<<" ";
|
||||
cout<<endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void cube(int f, int *data){
|
||||
int rank, size;
|
||||
int dest;
|
||||
int mask=1;
|
||||
mask <<= f;
|
||||
|
||||
MPI_Comm_rank(MCW, &rank);
|
||||
MPI_Comm_size(MCW, &size);
|
||||
|
||||
dest = rank ^ mask;
|
||||
|
||||
MPI_Send(data,1,MPI_INT,dest,0,MCW);
|
||||
MPI_Recv(data,1,MPI_INT,MPI_ANY_SOURCE,0,MCW,MPI_STATUS_IGNORE);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
int rank, size;
|
||||
int data;
|
||||
MPI_Init(&argc, &argv);
|
||||
MPI_Comm_rank(MCW, &rank);
|
||||
MPI_Comm_size(MCW, &size);
|
||||
|
||||
data = rank;
|
||||
|
||||
allPrint(data);
|
||||
cube(2,&data);
|
||||
cout<<endl;
|
||||
allPrint(data);
|
||||
|
||||
|
||||
|
||||
MPI_Finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
5
example/pachinco/.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
example/pachinco/.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
example/pachinco/.idea/misc.xml
generated
Normal file
6
example/pachinco/.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
example/pachinco/.idea/modules.xml
generated
Normal file
8
example/pachinco/.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/pachinco.iml" filepath="$PROJECT_DIR$/.idea/pachinco.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
8
example/pachinco/.idea/pachinco.iml
generated
Normal file
8
example/pachinco/.idea/pachinco.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>
|
||||
68
example/pachinco/.idea/workspace.xml
generated
Normal file
68
example/pachinco/.idea/workspace.xml
generated
Normal file
@@ -0,0 +1,68 @@
|
||||
<?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="1ec8baf7-c36e-415f-96a3-9219f74f3144" 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="nlumVDio" />
|
||||
</component>
|
||||
<component name="ProjectId" id="1WPqoAEvmJQAG3ylPB23Icr232G" />
|
||||
<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="preferences.pluginManager" />
|
||||
</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="1ec8baf7-c36e-415f-96a3-9219f74f3144" name="Default Changelist" comment="" />
|
||||
<created>1579061749869</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1579061749869</updated>
|
||||
<workItem from="1579061753840" duration="812000" />
|
||||
<workItem from="1579236356017" duration="351000" />
|
||||
<workItem from="1579842846262" duration="3379000" />
|
||||
<workItem from="1581113414207" duration="10085000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="1" />
|
||||
</component>
|
||||
</project>
|
||||
BIN
example/pachinco/a.out
Executable file
BIN
example/pachinco/a.out
Executable file
Binary file not shown.
55
example/pachinco/pachinko.cpp
Normal file
55
example/pachinco/pachinko.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <mpi.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <time>
|
||||
|
||||
//#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;
|
||||
}
|
||||
}
|
||||
|
||||
33
example/parallelRoundRobin.cpp
Normal file
33
example/parallelRoundRobin.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
#include <mpi.h>
|
||||
|
||||
#define MCW MPI_COMM_WORLD
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char **argv){
|
||||
int rank;
|
||||
int size;
|
||||
int data;
|
||||
|
||||
MPI_Init(&argc, &argv);
|
||||
|
||||
//returns my rank in the MCW.
|
||||
MPI_Comm_rank(MCW, &rank);
|
||||
//how many things there are in this communicator.
|
||||
MPI_Comm_size(MCW, &size);
|
||||
if(rank == 0){
|
||||
data = rand()%100;
|
||||
cout << "Process " << rank << "gerated " << data << "\n";
|
||||
|
||||
MPI_Send(&rank, 1, MPI_INT, (rank+1)%size, 0, MCW);
|
||||
|
||||
MPI_Recv(&data, 1, MPI_INT, MPI_ANY_SOURCE, 0, MCW, MPI_STATUS_IGNORE);
|
||||
}
|
||||
|
||||
|
||||
MPI_Recv(&data, 1, MPI_INT, MPI_ANY_SOURCE, 0, MCW, MPI_STATUS_IGNORE);
|
||||
cout << "I am " << rank << " of " << size << "; got a message from " << data <<endl;
|
||||
|
||||
MPI_Finalize();
|
||||
return 0;
|
||||
}
|
||||
42
example/parallellHello.cpp
Normal file
42
example/parallellHello.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <iostream>
|
||||
#include <mpi.h>
|
||||
|
||||
#define MCW MPI_COMM_WORLD
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char **argv){
|
||||
int rank;
|
||||
int size;
|
||||
int data;
|
||||
|
||||
MPI_Init(&argc, &argv);
|
||||
|
||||
//returns my rank in the MCW.
|
||||
MPI_Comm_rank(MCW, &rank);
|
||||
//how many things there are in this communicator.
|
||||
MPI_Comm_size(MCW, &size);
|
||||
|
||||
//Sends info
|
||||
//&rank- location of send buffer.
|
||||
//1- how many things in the buffer.
|
||||
//MPI_INT- tells what type to turn the data into..
|
||||
//(rank+1)%size- return number.
|
||||
//0- tag
|
||||
//MCW- communicator and other things.
|
||||
MPI_Send(&rank, 1, MPI_INT, (rank+1)%size, 0, MCW);
|
||||
|
||||
//Recieves information
|
||||
//&data where to put the return data.
|
||||
//1- how many.
|
||||
//MPI_INT- type.
|
||||
//MPI_ANY_SOURCE- can come from any process.
|
||||
//0- tag.
|
||||
//mcw- communicator type
|
||||
//MPI_STATUS_IGNORE-
|
||||
MPI_Recv(&data, 1, MPI_INT, MPI_ANY_SOURCE, 0, MCW, MPI_STATUS_IGNORE);
|
||||
|
||||
cout << "I am " << rank << " of " << size << "; got a message from " << data <<endl;
|
||||
|
||||
MPI_Finalize();
|
||||
return 0;
|
||||
}
|
||||
9
example/serialHello.cpp
Normal file
9
example/serialHello.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char ** argv){
|
||||
cout << "hello World/n";
|
||||
return 0;
|
||||
}
|
||||
10
example/test.cpp
Normal file
10
example/test.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char ** argv){
|
||||
cout << "hello World/n";
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user