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

  • Home
  • SEARCH
  • 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 4559912
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:51:22+00:00 2026-05-21T17:51:22+00:00

For my homework I have to test for several large matrices using this Conjugate

  • 0

For my homework I have to test for several large matrices using this Conjugate Gradient Program with MPI (see code below). I copied the program from my book and it is supposed to compile but I get the errors:

In function ‘main’:

37:warning: passing argument 1 of read_replicated_vector makes pointer from integer without a cast

37: warning: passing argument 2 of read_replicated_vector makes pointer from integer without a cast

37: warning: passing argument 3 of read_replicated_vector makes integer from pointer without a cast

37: warning: passing argument 4 of read_replicated_vector from incompatible pointer type

37: error: void value not ignored as it ought to be

44: warning: passing argument 1 of print_replicated_vector makes pointer from integer without a cast

44: warning: passing argument 3 of print_replicated_vector makes integer from pointer without a cast

44: error: too many arguments to function print_replicated_vector

#include <stdlib.h>
#include <stdio.h>
#include "mpi.h"
#include "MyMPI.h"

main (int argc, char *argv[])
{
  double **a;                /* Solving Ax = b for x */
  double *astorage;          /* Holds elements of A */
  double *b;                 /* Constant vector */
  double *x;                 /* Solution vector */
  int     p;                 /* MPI Processes */
  int     id;                /* Process rank */
  int     m;                 /* Rows in A */
  int     n;                 /* Columns in A */
  int     n1;                /* Elements in b */

  /* Initialize a and b so that solution is x[i] = i */

  MPI_Init (&argc, &argv);
  MPI_Comm_size (MPI_COMM_WORLD, &p);
  MPI_Comm_rank (MPI_COMM_WORLD, &id);

  read_block_row_matrix (id, p, argv[1], (void *) &a,
  (void *) &astorage, MPI_DOUBLE, &m, &n);
  n1 = read_replicated_vector (id, p, argv[2], (void **) &b, MPI_DOUBLE);
  if ((m != n) || (n != n1)) 
  {
      if (!id)
          printf ("Incompatible dimensions (%d x %d) x (%d)\n", m, n, n1);
  } 
  else {
      x = (double *) malloc (n * sizeof(double));
      cg (p, id, a, b, x, n);
      print_replicated_vector (id, p, x, MPI_DOUBLE, n); // here
  }
  MPI_Finalize();
}

id and p are not pointers, so I do think I need to pass them by reference in the calls to MPI_Comm_size and MPI_Comm_rank, though I tried doing that.

Edit

//Input Function

void read_replicated_vector (
char        *s,      /* IN - File name */
void       **v,      /* OUT - Vector */
MPI_Datatype dtype,  /* IN - Vector type */
int         *n,      /* OUT - Vector length */
MPI_Comm     comm)   /* IN - Communicator */
{
  int        datum_size; /* Bytes per vector element */
  int        i;
  int        id;         /* Process rank */
  FILE      *infileptr;  /* Input file pointer */
  int        p;          /* Number of processes */

  MPI_Comm_rank (comm, &id);
  MPI_Comm_size (comm, &p);
  datum_size = get_size (dtype);
  if (id == (p-1)) 
  {
    infileptr = fopen (s, "r");
    if (infileptr == NULL) *n = 0;
    else fread (n, sizeof(int), 1, infileptr);
  }
  MPI_Bcast (n, 1, MPI_INT, p-1, MPI_COMM_WORLD);
  if (! *n) terminate (id, "Cannot open vector file");

  *v = my_malloc (id, *n * datum_size);

  if (id == (p-1)) 
  {
    fread (*v, datum_size, *n, infileptr);
    fclose (infileptr);
  }
 
  MPI_Bcast (*v, *n, dtype, p-1, MPI_COMM_WORLD);
}

// Output Function

void print_replicated_vector (
void        *v,      /* IN - Address of vector */
MPI_Datatype dtype,  /* IN - Vector element type */
int          n,      /* IN - Elements in vector */
MPI_Comm     comm)   /* IN - Communicator */
{
   int id;              /* Process rank */

   MPI_Comm_rank (comm, &id);

   if (!id)
   {
     print_subvector (v, dtype, n);
     printf ("\n\n");
   }
}
  • 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-05-21T17:51:22+00:00Added an answer on May 21, 2026 at 5:51 pm

    Your warnings are because you’re calling the function

    void print_replicated_vector (void *, MPI_Datatype, int, MPI_Comm);
    

    with a first parameter of type int:

    print_replicated_vector (id, p, x, MPI_DOUBLE, n); // here
    

    C code will sometimes store a pointer in an int, and that’s what the compiler is assuming you want to do and it’s doing the appropriate type conversions (but warning you of them). But to make the code correct you’d have to make the types match up. I.e. pass a pointer to id with &id or whatever the appropriate argument is (I don’t know what print_replicated_vector does or what you want it to do).

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

Sidebar

Related Questions

I'm doing a homework project that requires this: Below you will find the code
This is for homework but please know that I have looked online for help
First of all this is homework. I have been trying to get rid of
(Before anyone asks, this is not homework.) I have a set of workers with
This is part of a homework assignment. What we have to do is write
I have developed a java program as a part of my homework and have
For homework, I was given the following 8 code fragments to analyze and give
(This is no homework and no work issue. It's just my personal interest/occupation and
I'm doing a basic homework assignment which looks like this: While input <> -1
Disclaimer: This is for a homework assignment, but the question is not regarding the

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.