Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8118119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:23:04+00:00 2026-06-06T04:23:04+00:00

I am currently working on a project where I need to implement a parallel

  • 0

I am currently working on a project where I need to implement a parallel fft algorithm using openmpi. I have a compiling piece of code, but when I run it over the cluster I get segmentation faults.

I have my hunches about where things are going wrong, but I don’t think I have enough of an understanding about pointers and references to be able to make a efficient fix.

The first chunk that could be going wrong is in the passing of the arrays to the helper functions. I believe that either my looping is inconsistent, or I am not understanding how the to pass these pointers and get back the things I need.

The second possible spot would be within the actual mpi_Send/Recv commands. I am sending a type that is not supported by the openmpi c datatypes, so I am using the mpi_byte type to send the raw data instead. Is this a viable option? Or should I be looking into an alternative to this method.

/* function declarations */
double complex get_block(double complex c[], int start, int stop);

double complex put_block(double complex from[], double complex to[], 
            int start, int stop);

void main(int argc, char **argv)
{
  /* Initialize MPI */
  MPI_Init(&argc, &argv);

  double complex c[N/p];
  int myid;
  MPI_Comm_rank(MPI_COMM_WORLD, &myid);
  //printf("My id is %d\n",myid);

  MPI_Status status;

  int i;
  for(i=0;i<N/p;i++){
    c[i] = 1.0 + 1.0*I;
  }

  int j = log(p)/log(2) + 1;
  double q;
  double complex z;
  double complex w = exp(-2*PI*I/N);
  double complex block[N/(2*p)]; // half the size of chunk c
  int e,l,t,k,m,rank,plus,minus;
  int temp = (log(N)-log(p))/log(2);
  //printf("temp = %d", temp);

  for(e = 0; e < (log(p)/log(2)); e++){
    /* loop constants */
    t = pow(2,e); l = pow(2,e+temp);
    q = n/2*l; z = cpow(w,(complex)q); 
    j = j-1; int v = pow(2,j);

    if(e != 0){
      plus = (myid + p/v)%p;
      minus = (myid - p/v)%p;
    } else {
      plus = myid + p/v;
      minus = myid - p/v;
    }

    if(myid%t == myid%(2*t)){
      MPI_Recv((char*)&c, 
           sizeof(c),
           MPI_BYTE,
           plus,
           MPI_ANY_TAG,
           MPI_COMM_WORLD,
           &status);

      /* transform */
      for(k = 0; k < N/p; k++){
    m = (myid * N/p + k)%l;
    c[k] = c[k] + c[k+N/v] * cpow(z,m);
    c[k+N/v] = c[k] - c[k + N/v] * cpow(z,m); 
    printf("(k,k+N/v) = (%d,%d)\n",k,k+N/v);
    }*/
      printf("\n\n");
      /* end transform */

      *block = get_block(c, N/v, N/v + N/p + 1);
      MPI_Send((char*)&block,
           sizeof(block),
           MPI_BYTE, 
           plus,
           1, 
           MPI_COMM_WORLD);
    } else {
      // send data of this PE to the (i- p/v)th PE
      MPI_Send((char*)&c,
           sizeof(c),
           MPI_BYTE,
           minus,
           1, 
           MPI_COMM_WORLD);
      // after the transformation, receive data from (i-p/v)th PE
      //      and store them in c:
      MPI_Recv((char*)&block,
           sizeof(block),
           MPI_BYTE,
           minus, 
           MPI_ANY_TAG, 
           MPI_COMM_WORLD,
              &status);

      *c = put_block(block, c, N/v, N/v + N/p - 1);
      //printf("Process %d send/receive %d\n",myid, plus);
    }
  }
  /* shut down MPI */
  MPI_Finalize();
}

/* helper functions */
double complex get_block(double complex *c, int start, int stop)
{
  double complex block[stop - start + 1];
  //printf("%d = %d\n",sizeof(block)/sizeof(double complex), sizeof(&c)/sizeof(double  complex));
  int j = 0;
  int i;
  for(i = start; i < stop+1; i++){
    block[j] = c[i];
    j = j+1;
  }
  return *block;
}


double complex put_block(double complex from[], double complex to[], int start, int stop)
{  
  int j = 0;
  int i;
  for(i = start; i<stop+1; i++){
    to[i] = from[j];
    j = j+1;
  }
  return *to;
}

I really appreciate the feedback!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:23:05+00:00Added an answer on June 6, 2026 at 4:23 am

    You are using arrays / pointers to arrays in the wrong way. For example you declare an array as double complex block[N], which is fine (although uncommon, in most cases it is better to use malloc) and then you receive into it via MPI_Recv(&block). However “block” is already a pointer to that array, so by writing “&block” you are passing the pointer of the pointer to MPI_Recv. That’s not what it expects. If you want to use the “&” notation you have to write &block[0], which would give you the pointer to the first element of the block-array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a project I'm currently working on I need to implement object versioning. Unfortunately
I'm currently working on a project where I need to implement several classes to
I need to implement several application-level behavior in a project I'm currently working on.
I am currently working on a project where I need to generate multiple values
I am currently working on a large project and will relatively soon need a
Currently we are working on a project in which we need to come up
Currently I am working with the project in which I need to parse complex
I'm working on a project that is using code from an OpenSource project. One
I am currently working on a project where I need to format a string
I'm currently working on a project where I need to print out a lesson

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.