Primary job terminated normally, but 1 process returned
a non-zero exit code. Per user-direction, the job has been aborted.
mpirun noticed that process rank 0 with PID 0 on node dyn-118-139-43-116 exited on signal 11 (Segmentation fault: 11).
C语言运行MPI的时候出现的,不知道怎么解决,求大神帮忙瞅瞅。
这个是什么情况呢?
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include "mpi.h"
int main(int argc, char** argv)
{
int iX,iY;
const int iXmax = 8000; // default
const int iYmax = 8000; // default
double Cx, Cy;
const double CxMin = -2.5;
const double CxMax = 1.5;
const double CyMin = -2.0;
const double CyMax = 2.0;
double PixelWidth = (CxMax - CxMin)/iXmax;
double PixelHeight = (CyMax - CyMin)/iYmax;
const int MaxColorComponentValue = 255;
static unsigned char color[3];
double Zx, Zy;
double Zx2, Zy2; /* Zx2 = Zx*Zx; Zy2 = Zy*Zy */
int Iteration;
const int IterationMax = 2000; // default
const double EscapeRadius = 400;
double ER2 = EscapeRadius * EscapeRadius;
unsigned char color_array[iYmax*iXmax*3]; //8000*8000*3 array
clock_t start, end;
double cpu_time_used;
int my_rank, processors, rows_per_procs,tag=0;
MPI_Status stat;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &processors);
if(my_rank == 0){
printf("Computing Mandelbrot Set. Please wait...\n");
}
start = clock();
if(my_rank == 0){
rows_per_procs = iYmax / processors;
MPI_Bcast(& rows_per_procs, 1, MPI_INT, 0, MPI_COMM_WORLD);
}
else
{
int counter = 0;
for(iY = rows_per_procs*my_rank; iY < rows_per_procs*(my_rank+1); iY++)
{
Cy = CyMin + (iY * PixelHeight);
if (fabs(Cy) < (PixelHeight / 2))
{
Cy = 0.0; /* Main antenna */
}
for(iX = 0; iX < iXmax; iX++)
{
Cx = CxMin + (iX * PixelWidth);
/* initial value of orbit = critical point Z= 0 */
Zx = 0.0;
Zy = 0.0;
Zx2 = Zx * Zx;
Zy2 = Zy * Zy;
/* */
for(Iteration = 0; Iteration < IterationMax && ((Zx2 + Zy2) < ER2); Iteration++)
{
Zy = (2 * Zx * Zy) + Cy;
Zx = Zx2 - Zy2 + Cx;
Zx2 = Zx * Zx;
Zy2 = Zy * Zy;
};
/* compute pixel color (24 bit = 3 bytes) */
if (Iteration == IterationMax)
{
// Point within the set. Mark it as black
color[0] = 0;
color[1] = 0;
color[2] = 0;
}
else
{
// Point outside the set. Mark it as white
double c = 3*log((double)Iteration)/log((double)(IterationMax) - 1.0);
if (c < 1)
{
color[0] = 0;
color[1] = 0;
color[2] = 255*c;
}
else if (c < 2)
{
color[0] = 0;
color[1] = 255*(c-1);
color[2] = 255;
}
else
{
color[0] = 255*(c-2);
color[1] = 255;
color[2] = 255;
}
}
color_array[counter*iX*3] = color[0];
color_array[counter*iX*3+1] = color[1];
color_array[counter*iX*3+2] = color[2];
}
counter++;
}
}
if(my_rank == 0)
{ //unsigned char color_array[iYmax*iXmax*3]; //8000*8000*3 array
FILE * fp;
char *filename = "Mandelbrot.ppm";
char *comment = "# "; /* comment should start with # */
fp = fopen(filename, "wb"); /* b - binary mode */
fprintf(fp,"P6\n %s\n %d\n %d\n %d\n", comment, iXmax, iYmax, MaxColorComponentValue);
printf("File: %s successfully opened for writing.\n", filename);
for(int i = 0; i<processors;i++)
{
MPI_Recv(color_array, rows_per_procs*iXmax*3,MPI_UNSIGNED_CHAR, i, tag, MPI_COMM_WORLD, &stat);
}
fwrite(color_array, 1, sizeof(color_array), fp);
fclose(fp);
printf("Completed Computing Mandelbrot Set.\n");
printf("File: %s successfully closed.\n", filename);
}
else
{
MPI_Send(color_array, sizeof(color_array),MPI_UNSIGNED_CHAR, 0, tag, MPI_COMM_WORLD);
}
// Get the clock current time again
// Subtract end from start to get the CPU time used.
end = clock();
cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
printf("%dMandelbrot computational process time: %lf\n", my_rank,cpu_time_used);
MPI_Finalize();
return 0;
}