473,395 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

threads in Win32 using C++

11
if I haveto multiply two matrices one 3x2 and the other 2x3, what threads I have to create . I know that there are 10 of them.
#include <stdio.h>
#include <iostream.h>
/* Allocate memory for a matrix of given order */
void create_matrix( int ***mat, int m, int n)
{
int **la = NULL;
int i;

//la = (int**)malloc(m* sizeof(int*));

for ( i=0; i <m; i++ )
la[i] = (int *)malloc( n* sizeof(int));

*mat = la;

return;
}


/* free memory of matrix allocated in create_matrix() */

void free_matrix( int ***mat, int m)
{
int **la = NULL;
int i;

la = *mat;

for ( i=0; i <m; i++ )
free (la[i] );

free ( la );

*mat=NULL;

return;
}


/* Print a matrix of order (mxn) */

void print_matrix( int **mat, int m, int n)
{
int i,j;

printf("Matrix of order(%dx%d)\n",m,n);
printf("\n");
for ( i=0; i <m; i++ )
{
for ( j=0; j <n; j++ )
printf("%4d",mat[i][j]);
printf("\n");
}
return;
}

/* Read a matrix of order (mxn) */
void read_matrix( int **mat, int m, int n)
{
int i,j;

printf("\nEnter %d elemnts for row, %d times\n",n,m);

for ( i=0; i <m; i++ )
{
for ( j=0; j <n; j++ )
scanf("%d",&mat[i][j]);
}
return;
}
int main()
{
int i,j,k;
int **a,**b,**c;

int m1,n1; /* A of m1xn1 */
int m2,n2; /* B of m2xn2 */

int m3,n3; /* C of m3xn3 => m1Xn2 (?) */

while(1) {

printf("\nEnter order of the First matrix: ");
scanf("%d%d",&m1,&n1);

printf("\nEnter order of the Second matrix: ");
scanf("%d%d",&m2,&n2);

/* Check if n1 == m2 */
if ( m2 == n1 )
break;

printf("\nMatrices can not be multiplied.. Try again.. ");

}

m3 = m1;
n3 = n2;

/* Allocate memory for all three matrices */

create_matrix( &a, m1, n1 );
create_matrix( &b, m2, n2 );
create_matrix( &c, m3, n3 );

/* Read the matrices to be multiplied */

read_matrix( a, m1, n1 );
read_matrix( b, m2, n2 );

print_matrix( a, m1, n1 );
print_matrix( b, m2, n2 );

/* Multyply the matrices */

for ( i = 0; i < m3; i++ )
{
for ( j = 0; j < n3; j++ )
{
c[i][j] = 0;

for ( k = 0; k < m2; k ++ )
c[i][j] += a[i][k]*b[k][j] ;
}
}

print_matrix( c, m3, n3 );

free_matrix( &a, m1 );
free_matrix( &b, m2 );
free_matrix( &c, m3 );

return 0;

}
Oct 10 '06 #1
1 2313
Banfa
9,065 Expert Mod 8TB
if I haveto multiply two matrices one 3x2 and the other 2x3, what threads I have to create . I know that there are 10 of them.
a. There are rather more than 10 threads on any running Windows system.

b. But you should only need 1 to perform any sort of mathematical operation including matrix multiplication.
Oct 11 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: mic | last post by:
I'm stuck with following problem. Using webbrowser control I try to make custom-made request. I found working example of this written in VBS but porting it to Python doesn't seem to work. The key...
2
by: Jerry He | last post by:
Hi, I was trying to build a C++ extension on Win32 with distutils. The extension worked on Cygwin but when I tried it with the Win32-build python, it complained that I don't have .NET Framework...
2
by: Jagadish | last post by:
Hi, My application requires to create a few threads on the occurance of an event E1 and the same threads need to be aborted on the occurance of another event E2. Iam not using .Net thread pool...
9
by: Beeeeeeeeeeeeves | last post by:
Hi I have a service which starts extra threads which take a long time, this is so it can respond to events while long processes are running. I was just wondering, a) if an exception is thrown...
6
by: Can Balioglu | last post by:
Hi everyone, My question is not a technical one. I'm just curious about the future of Win32 (and Win64) programming. Most of the books about Win32 from MS Press (like Programming Windows,...
3
by: bygandhi | last post by:
Hi - I am writing a service which will check a process and its threads for their state ( alive or dead ). The process has 5 .net managed threads created using thread.start and each have been...
10
by: cj | last post by:
I'm writing a TCP/IP server app that will have many simultaneous connections. The main thread listens for new connections and starts a thread to handle each requested connection. These are short...
3
by: michdoh | last post by:
Hi All I'm looking for some help on creating a basic multi threaded application. i'n new to threads in this environment so for test purposes I've produced a very basic program. (which doesn't...
5
by: Henaro | last post by:
Hello~ I am having trouble setting environment variables in C++ on win32. The code that is not working is: char prxy; char pf_cmd1 = "set http_proxy="; ....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.