The all task is: Implement the deterministic mass ranking algorithm.
The task should be prepared using the MPI standard in C programming language. Run times should be measured during runs on 1, 2, and 4 threads and plotted on a graph. The input N should always be 2 powers and this should be given on the horizontal x-axis, but only the exponents. For example, in the case of 1024, the scale is 10, because the 10th power of 2 is 1024. This is the so-called logarithmic scale. Thus, the scale of the x-axis remains linear, and the result can be easily plotted even with larger inputs. In all cases, the malloc function must be used, otherwise they will get a segmentation error! Whenever possible, input should be generated randomly.
My problem is, how can I measure the MPI threads, without the following error: MPI_Init_thread(517): Cannot call MPI_INIT or MPI_INIT_THREAD more than once
My second problem is, how can I visualize the measured numbers?
My code is following:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <stdbool.h>
#include <stdlib.h>
#include <assert.h>
#include <time.h>
#include <dos.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
#include <mpi.h>
#include <string.h>
#include <omp.h>
#include "mpi.h"
int egyszal(int szomsz[], int rang[], int p, int x);
int ketszal(int szomsz[], int rang[], int p, int x);
int negyszal (int szomsz[], int rang[], int p, int x);
int egyszal(int szomsz[], int rang[], int p, int x)
{
int i, j;
MPI_Init_thread( 0, 0, MPI_THREAD_MULTIPLE, &x );
for(i = 0; i < p; ++i)
{
if(szomsz[i] == 0)
{
rang[i] = 0;
}
else
{
rang[i] = 1;
}
}
for(j = 0; j < log10(p); ++j)
{
//printf("j valtozo erteke: %d\n", j);
for(i = 0; i < p; ++i)
{
//printf("i valtozo erteke: %d\n", i);
if( szomsz[i] != 0)
{
rang[i] = rang[i] + rang[szomsz[i]];
szomsz[i] = szomsz[szomsz[i]];
}
}
}
double ido_1 = MPI_Wtime();
MPI_Finalize();
MPI_Abort;
return ido_1;
}
int ketszal(int szomsz[], int rang[], int p, int x)
{
int i, j;
MPI_Init_thread( 0, 0, MPI_THREAD_MULTIPLE, &x );
for(i = 0; i < p; ++i)
{
if(szomsz[i] == 0)
{
rang[i] = 0;
}
else
{
rang[i] = 1;
}
}
for(j = 0; j < log10(p); ++j)
{
//printf("j valtozo erteke: %d\n", j);
for(i = 0; i < p; ++i)
{
//printf("i valtozo erteke: %d\n", i);
if( szomsz[i] != 0)
{
rang[i] = rang[i] + rang[szomsz[i]];
szomsz[i] = szomsz[szomsz[i]];
}
}
}
double ido_1 = MPI_Wtime();
MPI_Finalize();
MPI_Abort;
return ido_1;
}
int negyszal(int szomsz[], int rang[], int p, int x)
{
int i, j;
MPI_Init_thread( 0, 0, MPI_THREAD_MULTIPLE, &x );
for(i = 0; i < p; ++i)
{
if(szomsz[i] == 0)
{
rang[i] = 0;
}
else
{
rang[i] = 1;
}
}
for(j = 0; j < log10(p); ++j)
{
//printf("j valtozo erteke: %d\n", j);
for(i = 0; i < p; ++i)
{
//printf("i valtozo erteke: %d\n", i);
if( szomsz[i] != 0)
{
rang[i] = rang[i] + rang[szomsz[i]];
szomsz[i] = szomsz[szomsz[i]];
}
}
}
double ido_1 = MPI_Wtime();
MPI_Finalize();
MPI_Abort;
return ido_1;
}
int main(int argc, char** argv)
{
int i, j;
int x = 1;
int szomsz[] = {5, 4, 2, 0, 3, 1};
int rang[] = {1, 1, 1, 0, 1, 1};
int seged_1 = sizeof(szomsz);
int seged_2 = sizeof(int);
int p = seged_1/seged_2;
egyszal(szomsz, rang, p, x);
x = 2;
ketszal(szomsz, rang, p, x);
x = 4;
negyszal(szomsz, rang, p, x);
return 0;
}