MPI Sorting and Prefix Sum

This is a discussion on MPI Sorting and Prefix Sum within the C Programming forums, part of the General Programming Boards category; New to MPI and C, I have used the pseudo code for the sorting algorithms and this is what I ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    1

    MPI Sorting and Prefix Sum

    New to MPI and C, I have used the pseudo code for the sorting algorithms and this is what I have constructed. I know its not perfect but I'm searching for help on how to fix it.

    Code:
    #include <stdio.h>
    #include <mpi.h>
    void PrefixSum();
    int id, rank, nprocs;
    int size;
    int main(int argc, char** argv)
    {  
     MPI_Init(&argc, &argv);
        MPI_Comm_rank(MPI_COMM_WORLD, &rank);
        MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
        MPI_Status status;
     
     size = rank/nprocs;
     
     if (id == 0)
     {
      for(i=0;i<nprocs;i++)
      MPI_Send(id, size, MPI_INT, i, 0, MPI_COMM_WORLD);
     }
     else
     {
      MPI_Recv(id, size, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
     }
      MPI_Barrier(MPI_COMM_WORLD);
       
      size = rank/nprocs;
            partner_id = id + size(log(2));
            MPI_Reduce(&result, &rank, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
            if (id == 0)
            MPI_Barrier(MPI_COMM_WORLD);
      
     return 0;
        MPI_Finalize();
     
    }
    void PrefixSum(int id, int number, partner_id, result)
    {
     int d, partner_id, id, number, result;
     
     int size;
     result = number;
     message = result;
     
     for (i=0; i<=(size/log(2)); i++)
     {
      MPI_Recv(partner_id, 1, MPI_INT, predec, 0, MPI_COMM_WORLD, &status);
     
      if (partner_id == 0)
      {
       MPI_Send(partner_id, message, MPI_INT, i, 0, MPI_COMM_WORLD);
      
       else (partner_id == 1)
       {
        MPI_Recv(number, partner_id, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
       }
      }
     
      message += number;
      
      if(partner_id < id)
      {
       result += number;
       MPI_Send(partner_id, result, MPI_INT, i, 0, MPI_COMM_WORLD);
      }
     }
    }

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by Newby2012 View Post
    New to MPI and C
    How about learning the basics of C before trying to learn MPI?

    Even without knowing anything about MPI, I've noticed several syntax errors. Take a look at a C Tutorial (e.g. the one on this site) and come back with specific questions.

    Include all the errors/warnings you get when compiling the code in your posts too.

    Bye, Andreas

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MPI Prefix Sum
    By NewToC12 in forum C Programming
    Replies: 0
    Last Post: 11-23-2012, 01:26 PM
  2. Underscore prefix
    By Petike in forum C Programming
    Replies: 5
    Last Post: 11-23-2008, 10:32 AM
  3. which to prefix with std:: ??
    By wakish in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2005, 02:58 PM
  4. postfix and prefix...???
    By matheo917 in forum C++ Programming
    Replies: 8
    Last Post: 04-20-2002, 01:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21