first commit
This commit is contained in:
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
Reference in New Issue
Block a user