-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmend.c
More file actions
263 lines (254 loc) · 7.22 KB
/
mend.c
File metadata and controls
263 lines (254 loc) · 7.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
//
// Torbert, 26 November 2013
//
#include <stdio.h>
#include <GL/glut.h>
#include <time.h>
#include "mpi.h"
#include <stdlib.h>
#include <unistd.h>
//
#define M 800
#define N 600
#define maxIt 100
//
int count = 0 ;
int ascii = 48 ;
double globalscale = 1;
int max = maxIt;
double xpos = 0;
double ypos = 0;
int xxpos = 0;
int yypos = 0;
int rank ;
int size ;
MPI_Status status ;
int tag ;
int k , j ;
double xpp;
int* values;
int* worker(int xpp, int max);
int madle(int xpp,int ypp, int max, double scale, double xpos, double ypos){
double xp = (2.0/scale)/(400.0)*(xpp )-((2/scale) - xpos) ;
double yp = (1.5/scale)/(300.0)*(ypp)-((1.5/scale) - ypos) ;
double zx = 0;
double zy = 0;
int x = max;
if(xpp == 400 && ypp == 300)
printf("%f\n",scale);
while( x ){
double oldzx = zx;
double oldzy = zy;
zx = (oldzx*oldzx)-(oldzy*oldzy) + xp;
zy = 2*oldzx*oldzy + yp;
if(((zx*zx)+(zy*zy)) > 4)
{
return max - x;
}
x--;
}
return max;
}
//
void idlefunc(void)
{
++count ;
//
if( count == 1000000 )
{
count = 0 ;
//
++ascii ;
//
if( ascii == 58 ) ascii = 65 ;
if( ascii == 91 ) ascii = 97 ;
if( ascii == 123 ) ascii = 48 ;
//
glutPostRedisplay() ;
}
}
//
void displayfunc(void)
{
int xp , xpp , ypp , q;
//
glClear(GL_COLOR_BUFFER_BIT);
for( j = 1 ; j < size ; j++ )
{
int p = j - 1;
MPI_Send( &p, 1 , MPI_INTEGER , j , tag , MPI_COMM_WORLD ) ;
MPI_Send( &globalscale, 1 , MPI_DOUBLE , j , tag , MPI_COMM_WORLD ) ;
MPI_Send( &xpos, 1 , MPI_DOUBLE , j , tag , MPI_COMM_WORLD ) ;
MPI_Send( &ypos, 1 , MPI_DOUBLE , j , tag , MPI_COMM_WORLD ) ;
MPI_Send( &max, 1 , MPI_INTEGER , j , tag , MPI_COMM_WORLD ) ;
}
for( xp = size-2 ; xp < M ; xp++ )
{
int* values;
MPI_Recv( &xpp , 1 , MPI_INTEGER , MPI_ANY_SOURCE , tag , MPI_COMM_WORLD , &status ) ;
j = status.MPI_SOURCE;
for ( ypp = 0 ; ypp < 600 ; ypp++) {
int x;
MPI_Recv( &x , 1 , MPI_INTEGER , j , tag , MPI_COMM_WORLD , &status ) ;
// if(x == max)
// glColor3f( 0 , 0 , 0 );
// else
glColor3f( 0 +(x*.01), 0+ (x*.001) , 0 + (x*.0001) );
glBegin(GL_POINTS);
glVertex2f(xpp,ypp);
glEnd();
}
MPI_Send( &xp, 1 , MPI_INTEGER , j , tag, MPI_COMM_WORLD ) ;
MPI_Send( &globalscale, 1 , MPI_DOUBLE , j , tag , MPI_COMM_WORLD ) ;
MPI_Send( &xpos, 1 , MPI_DOUBLE , j , tag , MPI_COMM_WORLD ) ;
MPI_Send( &ypos, 1 , MPI_DOUBLE , j , tag , MPI_COMM_WORLD ) ;
MPI_Send( &max, 1 , MPI_INTEGER , j , tag , MPI_COMM_WORLD ) ;
}
for( q = 1 ; q < size-1 ; q++ )
{
int* values;
MPI_Recv( &xpp , 1 , MPI_INTEGER , MPI_ANY_SOURCE , tag , MPI_COMM_WORLD , &status ) ;
j = status.MPI_SOURCE;
for ( ypp = 0 ; ypp < 600 ; ypp++) {
int x;
MPI_Recv( &x , 1 , MPI_INTEGER , j , tag , MPI_COMM_WORLD , &status ) ;
if(x == max)
glColor3f( 0 , 0 , 0 );
else
glColor3f( 0 +(x*.1), 0+ (x*.01) , 0 + (x*.001) );
glBegin(GL_POINTS);
glVertex2f(xpp,ypp);
glEnd();
}
}
glutSwapBuffers() ;
}
void mousefunc(int button,int state,int xscr,int yscr)
{
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
{
globalscale *= 1.99;
printf("Zoom in 20. Scale : %f %d\n",globalscale*100,xscr);
xxpos = 400+xscr ;
yypos = 300-yscr ;
xpos += (2.0/globalscale)/(400.0)*(xscr)-((2/globalscale));
ypos += (1.5/globalscale)/(300.0)*(yscr)-((1.5/globalscale));
printf("\n%d %d %f %f\n",xxpos,yypos,xpos,ypos);
}
else if(button==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
{
globalscale /= 1.5;
printf("Zoom out 20. Scale : %f\n",globalscale*100);
xxpos = 400+xscr ;
yypos = 300-yscr ;
xpos += (2.0/globalscale)/(400.0)*(xscr)-((2/globalscale));
ypos += (1.5/globalscale)/(300.0)*(yscr)-((1.5/globalscale));
printf("\n%d %d %f %f\n",xxpos,yypos,xpos,ypos);
}
}
void motionfunc(int xscr,int yscr)
{
printf("Motion ( %d , %d ).\n" , xscr , yscr ) ;
}
void keyfunc(unsigned char key,int xscr,int yscr)
{
printf("Key %c pressed at %d %d.\n" , key, xscr, yscr);
}
void specialfunc(int key,int xscr,int yscr)
{
if( key == GLUT_KEY_UP )
{
max *= 2;
printf("Max interations = %d\n",max);
}if( key == GLUT_KEY_DOWN )
{
max /= 2;
if (max == 0)
max = 1;
printf("Max interations = %d\n",max);
}
}
void closefunc(void)
{
printf("Window closed.\n");
}
int main( int argc , char* argv[] )
{
//
// MPI variables
//
//
// other variables
//
//
// boilerplate
//
MPI_Init( &argc , &argv ) ;
MPI_Comm_size( MPI_COMM_WORLD , &size ) ; // same
MPI_Comm_rank( MPI_COMM_WORLD , &rank ) ; // different
//
// manager has rank = 0
//
if( rank == 0 )
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(M,N);
glutInitWindowPosition(100,50);
glutCreateWindow("");
glClearColor(1.0,1.0,1.0,0.0);
glShadeModel(GL_SMOOTH);
//
glViewport(0,0,(GLsizei)M,(GLsizei)N); // reshape
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,1.0*M,1.0*N,0.0); // invert y-coords
glMatrixMode(GL_MODELVIEW);
//
glutIdleFunc(idlefunc);
glutDisplayFunc(displayfunc);
glutReshapeFunc(NULL);
glutMouseFunc(mousefunc);
glutMotionFunc(motionfunc);
glutKeyboardFunc(keyfunc);
glutSpecialFunc(specialfunc);
glutWMCloseFunc(closefunc);
//
glutMainLoop();
//
return 0;
}
//
// workers have rank > 0
//
else
{
while(1){
int xpp,max;
double scale,xpos,ypos;
MPI_Recv( &xpp , 1 , MPI_INTEGER , 0 , tag , MPI_COMM_WORLD , &status ) ;
MPI_Recv( &scale , 1 , MPI_DOUBLE , 0 , tag , MPI_COMM_WORLD , &status ) ;
MPI_Recv( &xpos , 1 , MPI_DOUBLE , 0 , tag , MPI_COMM_WORLD , &status ) ;
MPI_Recv( &ypos , 1 , MPI_DOUBLE , 0 , tag , MPI_COMM_WORLD , &status ) ;
MPI_Recv( &max , 1 , MPI_INTEGER , 0 , tag , MPI_COMM_WORLD , &status ) ;
int boogie[N];
int ypp;
for( ypp = 0 ; ypp < N ; ypp++ ){
boogie[ypp] = madle(xpp,ypp, max ,scale, xpos, ypos);
}
int x;
MPI_Send(&xpp , 1 , MPI_INTEGER , 0 , tag , MPI_COMM_WORLD ) ;
for( x = 0; x < N ; x++){
MPI_Send(&boogie[x] , 1 , MPI_INTEGER , 0 , tag , MPI_COMM_WORLD ) ;
}
}
}
//
// boilerplate
//
//
return 0;
}
//
// end of file
//