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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:25:01+00:00 2026-05-17T22:25:01+00:00

In this homework, two matrices should be added using a different thread for each

  • 0

In this homework, two matrices should be added using a different thread for each quadrant. This is my attempt so far, it generates a seg fault that I haven’t been able to identify.

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define N 4  //matrix dimension

int c[4][4];


int a[4][4]={1 ,3, 4, 5, 3, 4, 5, 6,7, 8, 9, 0, 2, 10, 3, 5};//test matrices

int b[4][4]={3, 4, 5, 6, 11, 7, 9, 3, 1, 1, 4, 5,1, 0, 0, 6};



void *cuadrante(void *argv[1]){

    int t,i,j,k;

    int opcion;

    opcion = atoi(argv[1]);      //meant to cast the quadrant number 


    switch (opcion){

    case 1:
        k=((N/2)-1); //A11 position 

        for (i=k;i=0;i--){          //1st quadrant
                for (j=k;j=0;j--){

                    c[i][j]=a[i][j]+b[i][j];
                }
            }
    break;

    case 2:

        k=((N/2)-1); //next to A11

        for (i=k-1;i=0;i--){            //2nd quadrant
            for (j=k;j<N;j++){

                c[i][j]=a[i][j]+b[i][j];
                }
            }

    break;

    case 3:

        t=N/2; //

        for (i=t;i<N;i++){          //3rd quadrant
                for (j=(t-1);j=0;j--){

                    c[i][j]=a[i][j]+b[i][j];
                }
        }

    break;

    case 4:

        t=N/2;      //position A22 
        for (i=t;i<N;i++){          //4th quadrant
                for (j=t;j<N;j++){

                c[i][j]=a[i][j]+b[i][j];
                 }
            }

    break;


    default: 
        printf("\n Opcion erronea. Intente de nuevo");

    }//fsw




}//end cuadrante






int main(int argc,char * argv[])
{
    int rc, t;

    pthread_t threads[4];

    for(t=0;t<4;t++){

        rc = pthread_create(&threads[t], NULL, cuadrante, (void *)argv[1]);
          if (rc){
             printf("ERROR; return code from pthread_create() is %d\n",rc);
             return -1;
          }//end if

        }//end for

   printf("Created %d threads.\n", t);
   pthread_exit(NULL);
   return 0;


}//end main
  • 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-17T22:25:02+00:00Added an answer on May 17, 2026 at 10:25 pm

    You’re passing argv[1] as the parameter to all 4 threads; so won’t they all end up taking the same route through the switch statement?

    Also, your function declares its argument as a void **, but you’re passing in a char * cast to a void *. This is bound to cause issues. You probably want this:

    void *cuadrante(void *arg){
    
        int t,i,j,k;
    
        int opcion;
    
        opcion = atoi((char *)arg);      //meant to cast the quadrant number 
    
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a homework question, binary search has already been introduced: Given two arrays,
(This is no homework and no work issue. It's just my personal interest/occupation and
Disclaimer: This is for a homework assignment, but the question is not regarding the
This one is a case of not doing your homework.:-) Apart from dynamic loading
I'm doing a basic homework assignment which looks like this: While input <> -1
I have this homework problem where I need to use regex to remove every
Although I tagged this homework, it is actually for a course which I am
I'm not asking for anyone to do this homework for me, but I bring
I am a student this is homework... I have one table with four columns:
I am a student this is homework. I'm getting tired and confused. Any advice

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.