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 8750045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:47:49+00:00 2026-06-13T12:47:49+00:00

I’ve been having trouble with this parallel matrix multiplication code, I keep getting an

  • 0

I’ve been having trouble with this parallel matrix multiplication code, I keep getting an error when trying to access a data member in my structure.

This is my main function:

struct arg_struct
{
  int* arg1;
  int* arg2;
  int arg3;
  int* arg4;
};


int main()
{
  pthread_t allthreads[4];
  int A [N*N];
  int B [N*N];
  int C [N*N];
  randomMatrix(A);
  randomMatrix(B);
  printMatrix(A);
  printMatrix(B);
  struct arg_struct *args = (arg_struct*)malloc(sizeof(struct arg_struct));
  args.arg1 = A;
  args.arg2 = B;
  int x;
  for (int i = 0; i < 4; i++)
  {
     args.arg3 = i;
     args.arg4 = C;
     x = pthread_create(&allthreads[i], NULL, &matrixMultiplication, (void*)args); 
     if(x!=0)
     exit(1);
  }

  return 0;
}

and the matrixMultiplication method used from another C file:

void *matrixMultiplication(void* arguments)
{
     struct arg_struct* args = (struct arg_struct*) arguments;
     int block = args.arg3;
     int* A = args.arg1;
     int* B = args.arg2;
     int* C = args->arg4;
     free(args);
     int startln = getStartLineFromBlock(block);
     int startcol = getStartColumnFromBlock(block);
     for (int i = startln; i < startln+(N/2); i++)
     {
        for (int j = startcol; j < startcol+(N/2); j++)
        {
          setMatrixValue(C,0,i,j);
          for(int k = 0; k < N; k++)
          {
             C[i*N+j] += (getMatrixValue(A,i,k) * getMatrixValue(B,k,j));
             usleep(1);
          } 
        }
     }
}

Another error I am getting is when creating the thread: “invalid conversion from ‘void ()(int, int*, int, int*)’ to ‘void* ()(void)’ [-fpermissive]
“

Can anyone please tell me what I’m doing wrong?

  • 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-13T12:47:51+00:00Added an answer on June 13, 2026 at 12:47 pm

    Big Boss is right in the sense that he has identified the problem, but to add to/augment the reply he made.

    Option 1:
    Just create an arg_struct in the loop and set the members, then pass it through:

    for(...)
    {
        struct arg_struct *args = (arg_struct*)malloc(sizeof(struct arg_struct)); 
        args->arg1 = A;
        args->arg2 = B;    //set up args as now...
        ...
        x = pthread_create(&allthreads[i], NULL, &matrixMultiplication, (void*)args);
        ....
    }
    

    keep the free call in the thread, but now you could then use the passed struct directly rather than creating locals in your thread.

    Option 2:
    It looks like you want to copy the params from the struct internally to the thread anyway so you don’t need to dynamically allocate.

    Just create an arg_struct and set the members, then pass it through:

    arg_struct args;
    //set up args as now...
    for(...)
    {
       ...
       x = pthread_create(&allthreads[i], NULL, &matrixMultiplication, (void*)&args);
    }
    

    Then remove the free call.

    However as James pointed out you would need to synchronize in the thread/parent on the structure to make sure that it wasn’t changed. That would mean a Mutex or some other mechanism. So probably the move of the allocation to the for loop is easier to begin with.

    Part 2:

    I’m working on windows (so I can’t experiment currently), but pthread_create param 3 is referring to the thread function matrixMultiplication which is defined as void* matrixMultiplication( void* ); – it looks correct to me (signature wise) from the man pages online, void* fn (void* )

    I think I’ll have to defer to someone else on your second error. Made this post a comunnity wiki entry so answer can be put into this if desired.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a jquery bug and I've been looking for hours now, I can't
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,

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.