0

I am learning how to program with MPI and I can't seem to find an example anywhere about scattering two different arrays. Can someone point me in the right direction?

I'll post some of my code below, that way you'll have an idea about what I'm trying to do.

Thanks!

unsigned int* assignStarsToClusters(double *stars, double *clusters, unsigned int *azimuth)
{
    double start = 0;

    if(my_rank == 0)
        start = MPI_Wtime();

    int slice_size = NUMOFSTARS / comm_sz;  

    // Assign a star to the closest cluster
    double smallDistance;
    double tmpDistance;
    int indice = 0;
    for(unsigned int i = 0; i <= NUMOFSTARS; i+=3)
    {
        smallDistance = sqrt(sqr(stars[i] - clusters[0]) + sqr(stars[i+1] - clusters[0]) + sqr(stars[i+2] - clusters[0]));

        for(int j = 0; j <= (NUMOFCLUSTERS * 3); j+=3)
        {
            tmpDistance = sqrt(sqr(stars[i] - clusters[j]) + sqr(stars[i+1] - clusters[j+1]) + sqr(stars[i+2] - clusters[j+2]));

            if(tmpDistance < smallDistance)
            {
                smallDistance = tmpDistance;
                indice = j;
            }

        }
        azimuth[i/3] = indice / 3;

    }

    return azimuth;
}

Edited by singularity~: Fix

2
Contributors
1
Reply
11
Views
3 Years
Discussion Span
Last Post by rubberman
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.