commit a3b893f971cfc7006af51fbbecbe4117740ef91b Author: bbod Date: Sat Feb 29 02:21:45 2020 -0700 first commit diff --git a/HW2/.idea/HW2.iml b/HW2/.idea/HW2.iml new file mode 100644 index 0000000..bc2cd87 --- /dev/null +++ b/HW2/.idea/HW2.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/HW2/.idea/codeStyles/codeStyleConfig.xml b/HW2/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..8f1a3b7 --- /dev/null +++ b/HW2/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/HW2/.idea/misc.xml b/HW2/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/HW2/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/HW2/.idea/modules.xml b/HW2/.idea/modules.xml new file mode 100644 index 0000000..d5ad6c9 --- /dev/null +++ b/HW2/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/HW2/.idea/workspace.xml b/HW2/.idea/workspace.xml new file mode 100644 index 0000000..36a04e1 --- /dev/null +++ b/HW2/.idea/workspace.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1579920470301 + + + + + + \ No newline at end of file diff --git a/HW2/Bomb.cpp b/HW2/Bomb.cpp new file mode 100644 index 0000000..ae0aad8 --- /dev/null +++ b/HW2/Bomb.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include + +//#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 "< +#include +#include +#include +#include + +//#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 +#include +#include +#include +#include +#include +#include + + +//#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 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 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; +} + diff --git a/HW3/test.cpp b/HW3/test.cpp new file mode 100644 index 0000000..00d7188 --- /dev/null +++ b/HW3/test.cpp @@ -0,0 +1,160 @@ +#include +#include +#include +#include +#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); +} \ No newline at end of file diff --git a/HW4/bitonic.cpp b/HW4/bitonic.cpp new file mode 100644 index 0000000..96f86e3 --- /dev/null +++ b/HW4/bitonic.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include +#include +#include + + +//#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; +} + + diff --git a/HW5/a.out b/HW5/a.out new file mode 100755 index 0000000..f59b3bc Binary files /dev/null and b/HW5/a.out differ diff --git a/HW5/main.cpp b/HW5/main.cpp new file mode 100644 index 0000000..e4ec15b --- /dev/null +++ b/HW5/main.cpp @@ -0,0 +1,127 @@ +#include +#include +#include +#include +#include +#include +#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 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 +#include +#include +#include + +//#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 +#include +#include +#include +#include +#include +#include +#include + +#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((color2.red - color1.red) / maxIterations); + double myColorG = static_cast((color2.green - color1.green) / maxIterations); + double myColorB = static_cast((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> 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> pixels(config.height, std::vector (config.width)); + std::vector 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; +} diff --git a/Parallel_Mandelbrot/.idea/Parallel_Mandelbrot.iml b/Parallel_Mandelbrot/.idea/Parallel_Mandelbrot.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/Parallel_Mandelbrot/.idea/Parallel_Mandelbrot.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/Parallel_Mandelbrot/.idea/codeStyles/codeStyleConfig.xml b/Parallel_Mandelbrot/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..8f1a3b7 --- /dev/null +++ b/Parallel_Mandelbrot/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/Parallel_Mandelbrot/.idea/misc.xml b/Parallel_Mandelbrot/.idea/misc.xml new file mode 100644 index 0000000..8822db8 --- /dev/null +++ b/Parallel_Mandelbrot/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/Parallel_Mandelbrot/.idea/modules.xml b/Parallel_Mandelbrot/.idea/modules.xml new file mode 100644 index 0000000..c6fda71 --- /dev/null +++ b/Parallel_Mandelbrot/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Parallel_Mandelbrot/.idea/workspace.xml b/Parallel_Mandelbrot/.idea/workspace.xml new file mode 100644 index 0000000..ffde803 --- /dev/null +++ b/Parallel_Mandelbrot/.idea/workspace.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1581819888474 + + + + + + \ No newline at end of file diff --git a/Parallel_Mandelbrot/a.out b/Parallel_Mandelbrot/a.out new file mode 100755 index 0000000..757f837 Binary files /dev/null and b/Parallel_Mandelbrot/a.out differ diff --git a/Parallel_Mandelbrot/gather.cpp b/Parallel_Mandelbrot/gather.cpp new file mode 100644 index 0000000..dfc7ef4 --- /dev/null +++ b/Parallel_Mandelbrot/gather.cpp @@ -0,0 +1,33 @@ + +#include +#include +#include +#include + +//#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 +#include +#include +#include +#include +#include +#include +/// +/// 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((color2.red - color1.red) / maxIterations); + double myColorG = static_cast((color2.green - color1.green) / maxIterations); + double myColorB = static_cast((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 > 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 > pixels(config.height, std::vector (config.width)); + std::vector 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> 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; +} diff --git a/Parallel_Mandelbrot/scatter.cpp b/Parallel_Mandelbrot/scatter.cpp new file mode 100644 index 0000000..17bad38 --- /dev/null +++ b/Parallel_Mandelbrot/scatter.cpp @@ -0,0 +1,35 @@ + + +#include +#include +#include +#include + +//#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"< +#include +#include +#include + +//#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 + + + \ No newline at end of file diff --git a/example/pachinco/.idea/misc.xml b/example/pachinco/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/example/pachinco/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/example/pachinco/.idea/modules.xml b/example/pachinco/.idea/modules.xml new file mode 100644 index 0000000..d63645e --- /dev/null +++ b/example/pachinco/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/example/pachinco/.idea/pachinco.iml b/example/pachinco/.idea/pachinco.iml new file mode 100644 index 0000000..bc2cd87 --- /dev/null +++ b/example/pachinco/.idea/pachinco.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/example/pachinco/.idea/workspace.xml b/example/pachinco/.idea/workspace.xml new file mode 100644 index 0000000..3c889ec --- /dev/null +++ b/example/pachinco/.idea/workspace.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1579061749869 + + + + + + \ No newline at end of file diff --git a/example/pachinco/a.out b/example/pachinco/a.out new file mode 100755 index 0000000..7a4ef03 Binary files /dev/null and b/example/pachinco/a.out differ diff --git a/example/pachinco/pachinko.cpp b/example/pachinco/pachinko.cpp new file mode 100644 index 0000000..172eccf --- /dev/null +++ b/example/pachinco/pachinko.cpp @@ -0,0 +1,55 @@ + +#include +#include +#include +#include +#include