added logic for getting number of cpus
git-svn-id: svn://anubis/gvsu@316 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
83ae452669
commit
3937191f37
@ -13,7 +13,7 @@ using namespace std;
|
|||||||
|
|
||||||
bool createWindow(int width, int height,
|
bool createWindow(int width, int height,
|
||||||
SDL_Surface ** screen, Uint32 ** pixels);
|
SDL_Surface ** screen, Uint32 ** pixels);
|
||||||
void getSizes(int * rank, int * size);
|
void getSizes(int * rank, int * size, int * nprocs);
|
||||||
|
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
@ -21,37 +21,45 @@ int main(int argc, char * argv[])
|
|||||||
int height = 600;
|
int height = 600;
|
||||||
int my_rank;
|
int my_rank;
|
||||||
int world_size;
|
int world_size;
|
||||||
|
int nprocs;
|
||||||
|
|
||||||
SDL_Surface * screen;
|
SDL_Surface * screen;
|
||||||
Uint32 * pixels;
|
Uint32 * pixels;
|
||||||
|
|
||||||
MPI_Init(&argc, &argv);
|
MPI_Init(&argc, &argv);
|
||||||
|
getSizes(&my_rank, &world_size, &nprocs);
|
||||||
|
|
||||||
for (int y = 0; y < height; y++)
|
if (my_rank == 0)
|
||||||
{
|
{
|
||||||
for (int x = 0; x < width; x++)
|
createWindow(width, height, &screen, &pixels);
|
||||||
|
|
||||||
|
for (int y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
*pixels++ = (((x * 255 / width) & 0xFF) << 8)
|
for (int x = 0; x < width; x++)
|
||||||
+ ((y * 255 / height) & 0xFF);
|
{
|
||||||
|
*pixels++ = (((x * 255 / width) & 0xFF) << 8)
|
||||||
|
+ ((y * 255 / height) & 0xFF);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
SDL_UpdateRect(screen, 0, 0, 0, 0);
|
||||||
SDL_UpdateRect(screen, 0, 0, 0, 0);
|
|
||||||
|
|
||||||
bool going = true;
|
bool going = true;
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (going && SDL_WaitEvent(&event) != 0)
|
while (going && SDL_WaitEvent(&event) != 0)
|
||||||
{
|
|
||||||
switch (event.type)
|
|
||||||
{
|
{
|
||||||
case SDL_QUIT:
|
switch (event.type)
|
||||||
going = false;
|
{
|
||||||
break;
|
case SDL_QUIT:
|
||||||
case SDL_KEYDOWN:
|
|
||||||
if (event.key.keysym.sym == SDLK_q)
|
|
||||||
going = false;
|
going = false;
|
||||||
break;
|
break;
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
if (event.key.keysym.sym == SDLK_q)
|
||||||
|
going = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MPI_Finalize();
|
MPI_Finalize();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -80,8 +88,35 @@ bool createWindow(int width, int height,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void getSizes(int * rank, int * size)
|
void getSizes(int * rank, int * size, int * nprocs)
|
||||||
{
|
{
|
||||||
MPI_Comm_rank(MPI_COMM_WORLD, rank);
|
MPI_Comm_rank(MPI_COMM_WORLD, rank);
|
||||||
MPI_Comm_size(MPI_COMM_WORLD, size);
|
MPI_Comm_size(MPI_COMM_WORLD, size);
|
||||||
|
|
||||||
|
*nprocs = sysconf(_SC_NPROCESSORS_CONF);
|
||||||
|
|
||||||
|
int displs[*size];
|
||||||
|
int counts[*size];
|
||||||
|
for (int i = 0; i < *size; i++)
|
||||||
|
{
|
||||||
|
displs[i] = i;
|
||||||
|
counts[i] = 1;
|
||||||
|
}
|
||||||
|
int all_nprocs[*size];
|
||||||
|
MPI_Gatherv(nprocs, 1, MPI_INT,
|
||||||
|
&all_nprocs[0], &counts[0], &displs[0], MPI_INT,
|
||||||
|
0, MPI_COMM_WORLD);
|
||||||
|
|
||||||
|
if (*rank == 0)
|
||||||
|
{
|
||||||
|
int total_nprocs = 0;
|
||||||
|
cout << "Number of cores on each MPI node:" << endl;
|
||||||
|
for (int i = 0; i < *size; i++)
|
||||||
|
{
|
||||||
|
cout << all_nprocs[i] << " ";
|
||||||
|
total_nprocs += all_nprocs[i];
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
cout << "Total number of cores: " << total_nprocs << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user