Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
16 changed files
with
491 additions
and
0 deletions.
There are no files selected for viewing
BIN
+105 KB
Concurrency/portfolio
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
#include <cstdlib> | ||
#include <thread> | ||
#include <fstream> | ||
#include <vector> | ||
#include <mutex> | ||
#include <condition_variable> | ||
|
||
int pos = 0; | ||
|
||
std::mutex mutx; | ||
std::condition_variable cv; | ||
bool ready = false; | ||
|
||
void printArray(std::vector<std::string> array, int pos){ | ||
|
||
std::unique_lock<std::mutex> lck (mutx);//critical section | ||
while(!ready) cv.wait(lck); | ||
|
||
std::cout << array.at(pos) << std::endl; | ||
std::this_thread::sleep_for(std::chrono::seconds(2)); | ||
|
||
} | ||
void increasePos(){ | ||
pos++; | ||
} | ||
|
||
void start(){ | ||
std::unique_lock<std::mutex> lck (mutx);//critical section | ||
ready = true; | ||
cv.notify_all(); | ||
} | ||
int main(){ | ||
|
||
std::string line; | ||
std::vector<std::string> poemLines = {}; | ||
std::ifstream poem("ritmo_rhythm.txt"); | ||
std::thread t1, t2; | ||
|
||
|
||
while(getline(poem, line)){ | ||
poemLines.emplace_back(line); | ||
} | ||
start(); | ||
while(pos < poemLines.size()){ | ||
t2 = std::thread(printArray, poemLines, pos); | ||
t2.join();//prevents unpredictable behaviour | ||
t1 = std::thread(increasePos); | ||
t1.join(); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Mad has decided to catch a vulture, | ||
the biggest bird she can find. | ||
|
||
She is so determined, and so inventive, | ||
that by stringing together a rickety trap | ||
of ropes and sticks, she creates | ||
a puzzling structure that just might | ||
be clever enough to trick a buzzard, | ||
once the trap�s baited with leftover pork | ||
from supper. | ||
|
||
Mad and I used to do everything together, | ||
but now I need a project all my own, | ||
so I roam the green fields, | ||
finding bones. | ||
|
||
The skull of a wild boar. | ||
The jawbone of a mule. | ||
|
||
Older cousins show me | ||
how to shake the mule�s quijada, | ||
to make the blunt teeth | ||
rattle. | ||
|
||
Guitars. | ||
Drums. | ||
Gourds. | ||
Sticks. | ||
|
||
A cow bell. | ||
A washboard. | ||
Pretty soon, we have | ||
a whole orchestra. | ||
|
||
On Cuban farms, even death | ||
can turn into | ||
music. |
BIN
+115 KB
Distributed/arith
Binary file not shown.
BIN
+135 KB
Distributed/data
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include "mpi.h" | ||
#include <list> | ||
#include <time.h> | ||
#include <stdlib.h> | ||
#include <iostream> | ||
#include <thread> | ||
|
||
std::list<int> unavailableNodes = {}; | ||
int current_val; | ||
std::string lastUsedOp = ""; | ||
|
||
bool isNodeAvailable(int node){ | ||
if (node != unavailableNodes.front() && node != unavailableNodes.back())return true; | ||
return false; | ||
} | ||
|
||
void removeNode(int node){ | ||
unavailableNodes.pop_front(); | ||
} | ||
void addNode(int node){ | ||
unavailableNodes.push_back(node); | ||
} | ||
int determineArith(int randNum, int numPassed){ | ||
if (randNum < 3 && lastUsedOp != "+"){ | ||
lastUsedOp = "+"; | ||
current_val += numPassed; | ||
return current_val + numPassed; | ||
} | ||
if (randNum < 6 && lastUsedOp != "-"){ | ||
lastUsedOp = "-"; | ||
current_val -= numPassed; | ||
return current_val - numPassed; | ||
} | ||
if (randNum < 9 && lastUsedOp != "*"){ | ||
lastUsedOp = "*"; | ||
current_val *= numPassed; | ||
return current_val * numPassed; | ||
} | ||
} | ||
int determineNextNode(int currentNode, int mpiSize){ | ||
int destination; | ||
do{ | ||
destination = rand()%mpiSize; | ||
}while(!isNodeAvailable(destination)); | ||
return destination; | ||
} | ||
int main(){ | ||
|
||
srand(time(NULL)); | ||
MPI_Init(NULL, NULL); | ||
char node_name[MPI_MAX_PROCESSOR_NAME]; | ||
int rank,size, namelen; | ||
MPI_Comm comm; | ||
comm = MPI_COMM_WORLD; | ||
int passNum = 6; | ||
int current_node = 0; | ||
|
||
MPI_Comm_rank(MPI_COMM_WORLD, &rank); | ||
MPI_Comm_size(MPI_COMM_WORLD, &size); | ||
MPI_Get_processor_name(node_name, &namelen); | ||
|
||
while(true){ | ||
if(rank == 0){ | ||
addNode(current_node); | ||
int nextNode = determineNextNode(current_node, size); | ||
addNode(nextNode); | ||
int operatorDet = rand()%10; | ||
int updatedVal = determineArith(operatorDet, passNum); | ||
std::cout << "New value is: " << updatedVal << " on node " << nextNode << std::endl; | ||
removeNode(current_node); | ||
current_node = nextNode; | ||
std::this_thread::sleep_for(std::chrono::seconds(2)); | ||
} | ||
} | ||
|
||
MPI_Finalize(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include <vector> | ||
#include "mpi.h" | ||
#include <fstream> | ||
#include <omp.h> | ||
#include <algorithm> | ||
#include <string> | ||
|
||
std::vector<std::string> make_sentence(std::string s){ | ||
std::string word = ""; | ||
std::vector<std::string> sentence; | ||
for(int i = 0; i<s.size(); ++i){ | ||
if (s[i] != ' '){ | ||
word += s[i]; | ||
} | ||
else if (s[i] == ' '){ | ||
sentence.push_back(word); | ||
word = ""; | ||
} | ||
} | ||
if (word != ""){ | ||
sentence.push_back(word); | ||
} | ||
return sentence; | ||
} | ||
int main(){ | ||
|
||
MPI_Init(NULL, NULL); | ||
char node_name[MPI_MAX_PROCESSOR_NAME]; | ||
int rank,size, namelen; | ||
MPI_Comm comm; | ||
comm = MPI_COMM_WORLD; | ||
|
||
|
||
MPI_Comm_rank(MPI_COMM_WORLD, &rank); | ||
MPI_Comm_size(MPI_COMM_WORLD, &size); | ||
MPI_Get_processor_name(node_name, &namelen); | ||
|
||
std::string line; | ||
std::vector<std::string> poemLines = {}; | ||
std::vector<std::string> jumbledUpPoem = {}; | ||
std::ifstream poem("ritmo_rhythm.txt"); | ||
|
||
while(getline(poem, line)){ | ||
poemLines.emplace_back(line); | ||
} | ||
|
||
jumbledUpPoem = poemLines; | ||
if (rank == 0){ | ||
std::vector<std::string> originalPoem = poemLines; | ||
} | ||
#pragma omp parallel for num_threads(1) | ||
for (int i = 0; i < poemLines.size(); i++){ | ||
if (rank == i){ | ||
std::string j_line = jumbledUpPoem[i]; | ||
//std::cout << j_line << std::endl; | ||
std::vector<std::string> sentence = make_sentence(j_line); | ||
std::random_shuffle(sentence.begin(), sentence.end()); | ||
for(auto word : sentence){ | ||
std::cout << word << " "; | ||
} | ||
std::cout << std::endl; | ||
} | ||
} | ||
MPI_Finalize(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <iostream> | ||
#include "mpi.h" | ||
#include <string> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
int main(int argc, char** argv) { | ||
|
||
// Initialize the MPI environment | ||
MPI_Init(NULL, NULL); | ||
char node_name[MPI_MAX_PROCESSOR_NAME]; | ||
int rank,size, namelen,*buf; | ||
MPI_File fh; | ||
MPI_Comm comm; | ||
MPI_Status status; | ||
comm = MPI_COMM_WORLD; | ||
|
||
|
||
MPI_Comm_rank(MPI_COMM_WORLD, &rank); | ||
MPI_Comm_size(MPI_COMM_WORLD, &size); | ||
MPI_Get_processor_name(node_name, &namelen); | ||
|
||
FILE *pPipeProc, *pPipeClock, *pPipeRAM; | ||
pPipeProc = popen("grep 'cpu cores' /proc/cpuinfo | head -n 1", "r"); | ||
pPipeClock = popen("grep 'cpu MHz' /proc/cpuinfo | tail -n 1", "r"); | ||
pPipeRAM = popen("free -m | grep 'Mem'", "r"); | ||
char bufCore[1024],bufClock[1024], bufRAM[1024]; | ||
|
||
fgets(bufCore, 1024, pPipeProc); | ||
fgets(bufClock, 1024, pPipeClock); | ||
fgets(bufRAM, 1024, pPipeRAM); | ||
|
||
std::cout << bufCore << std::endl; | ||
std::cout << bufClock << std::endl; | ||
std::cout << "RAM for node_name " << node_name << " = " << bufRAM << std::endl; | ||
|
||
if (rank==0) { | ||
std::cout << "Node Count = " << size << std::endl; | ||
|
||
std::string sCore(bufCore); | ||
int cores_per = sCore[12] - '0'; | ||
|
||
std::cout << "total cores = " << cores_per* size << std::endl; //implies single digit core number, since stoi does not work | ||
|
||
|
||
} | ||
MPI_Finalize(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
node2 | ||
node3 | ||
node4 | ||
node5 | ||
node6 | ||
node7 | ||
node8 | ||
node9 | ||
node10 | ||
node11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Mad has decided to catch a vulture, | ||
the biggest bird she can find. | ||
|
||
She is so determined, and so inventive, | ||
that by stringing together a rickety trap | ||
of ropes and sticks, she creates | ||
a puzzling structure that just might | ||
be clever enough to trick a buzzard, | ||
once the trap�s baited with leftover pork | ||
from supper. | ||
|
||
Mad and I used to do everything together, | ||
but now I need a project all my own, | ||
so I roam the green fields, | ||
finding bones. | ||
|
||
The skull of a wild boar. | ||
The jawbone of a mule. | ||
|
||
Older cousins show me | ||
how to shake the mule�s quijada, | ||
to make the blunt teeth | ||
rattle. | ||
|
||
Guitars. | ||
Drums. | ||
Gourds. | ||
Sticks. | ||
|
||
A cow bell. | ||
A washboard. | ||
Pretty soon, we have | ||
a whole orchestra. | ||
|
||
On Cuban farms, even death | ||
can turn into | ||
music. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
if [".$1" == ""]; then | ||
echo "Positional paramter 1 is empty" | ||
else | ||
mpirun -machinefile /home/370user30/370CT/Distributed/machines --map-by ppr:4:node $1 | ||
|
||
fi |
BIN
+105 KB
Distributed/status
Binary file not shown.
Oops, something went wrong.