C++ :: Solving Linear System Of Equations Using Threads

Dec 14, 2014

I am trying to write a code that solves a system of linear equations such as A*B=C. My system has a dimension equal to 1600. The matrix A cab be separated into 4 sub matrices and each can be handled by a different thread. I tried to solve this using the following code:

int main() {
int count = 0;
//Inputing matrix A
ifstream matrix;
matrix.open("example.txt");

[Code] ....

Although the above code gives the correct answer, the time needs to find the solution is bigger than that needed without using threads.

View 1 Replies


ADVERTISEMENT

Visual C++ :: Pthreads - Solve System Of Equations By Gauss-Jordan Method

Dec 15, 2012

I have a problem: solve the system of equations by the Gauss-Jordan methods with pthreads. I have a big matrix A (for example 2000x2000), so i must solve Ax = b. Before I devide matrix to number of threads and each thread must work only with his peace of matrix.

Code:
#include <iostream>
#include "synchronize.h"
#include <pthread.h>
using namespace std;
typedef struct _ARGS {
int thread_count;
int thread_number;

[Code] .....

I write it on Ubuntu, and when I compile [g++ main.cpp -o main -lpthread -lm] the it works good(for example, if in 1 thread I get time_of_working = 10 sec, on 2 threads time_of_working = 5.4, i.e. about 2 times faster ), if I compile like this [g++ main.cpp -o main -lpthread -lm -O3] it is only 1.2-1.3 times faster.

View 1 Replies View Related

Visual C++ :: Linear Program For Matrices - System Cannot Find Path Specified

Dec 8, 2012

I have two pieces of code:

Code:
#include <cmath>;
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <iomanip>

[Code] ....

I am using the gnu glpk library to calculate a linear program for my matrices. Why I get the error message exit code 3 which apparently means "The system cannot find the path specified"?

View 12 Replies View Related

C++ :: Anagram Solver Not Solving All Words

Dec 17, 2013

I'm working on an anagram solver, and started with words 3 characters big. But it can solve some words and not others.

std::string str = "enp";
std::string match = "";
int chk = 0;

[Code].....

With the string "enp", it knows it matches "pen". But if I use "mum", it doesn't match it with "mum".

Is there something flawed with my algroithm?

View 4 Replies View Related

Visual C++ :: Solving Factorials - Large Numbers?

Nov 21, 2013

If i m writing a code for a program to solve factorials, what is the best approach if i have large numbers in mind?

If i use int, i can only go upto 4bytes and if i use double i can go upto 8bytes. so should i create new type or is there any other way to get this done.

View 14 Replies View Related

C++ :: Trigonometry Programming - Solving Triangle By Using Cosine And Sine Law

Jun 3, 2013

I am writing a program to solve a triangle. Given any three pieces of information, find the other three. I am having trouble with SSA. I use the cosine law to find the unknown side. Then I use the sine law to find the other two angles. The sine law will give me each of the other angles. If one of the unknown angles is over 90 degrees, my program gives an angle as under 90 degrees. Not surprisingly, the correct angle and my wrong angle add up to 180 degrees. If you draw out the triangle you can deduce the right answer. How to have my program find out when the angle needs to be over 90 degrees.

View 5 Replies View Related

C :: Working With Equations

Nov 19, 2013

I need to find out all the possible equations which are same of a given equation. For eg. a+b+c-d and b+c+a-d are same. So if the user inputs a+b+c-d then the output will be all the possible equations that can be formed from the given equation, viz:

a+c+b-d
c+a+b-d
-d+a+c+b

etc

i.e the program should rearrange the operands and operators in such a way that it should give the same result.

View 5 Replies View Related

C++ :: Equations And Intersection Point

Aug 17, 2013

Program which accepts two lines and and determines their intersection point and whether they lie within a circle, also given interactively. I'm racing against time and I've racked my skull to no avail

View 2 Replies View Related

C :: Calculate The Solutions Of Quadratic Equations

Oct 22, 2014

I have a task to find errors in this long line of code in order to correctly calculate the solutions of quadratic equations.

Code:
int main(int argc, char *argv[]) {
int validInput, solution_type;
double a, b, c, root_1, root_2, q;

/***********************
* Input / Validation
***********************/

/* Check numbers of arguments, and read input */
validInput = (argc = 4);

[Code] ....

Is a section of the code (the first section). And as you can probably guess, it goes on to calculate for a > 0 etc...

I dont really understand what the validinput section is saying? And a, b and c are never defined so Xcode is just saying a,b,c,root1,root2 are uninitialized and I also dont know what means. Do I need to define these values?

Code:
int main(int argc, char *argv[]) {
int validInput, solution_type;
double a, b, c, root_1, root_2, q;

[Code] ......

View 9 Replies View Related

C :: Calculate Equations Just Like A Standard Calculator

Oct 23, 2013

The main point of the program is to calculate equations just like a standard calculator but I wanted to do it myself. I don't understand what the problem is right now but I've managed to create a program that asks for both values but somehow it doesn't want to ask for an operator (*, /, + etc). What's wrong with my code that the terminal skips the scanning part for the operator?

Code:

#include <stdio.h>
int main() {
int value1, value2, answer;
char operator;

[code]....

View 12 Replies View Related

C :: Program That Solves Math Equations

Apr 30, 2013

I wrote a program that solves an equation of two numbers, but in addition to that, I want it to be able to continue to solve longer equations. Ex: ( solves 2 * 4, or 2 * 4 - 5).I want to put this part of the program's result into a variable and go from there. How do I place the result of the calculation into a variable, and where would it go?

Code:

#include <stdio.h>
#include <string.h>
int main(void) {
int a;
scanf("%d", &a);
char s[2];
scanf("%s", s);
int b;
scanf("%d", &b);
}

[code]....

View 4 Replies View Related

C :: Scanning Equations / Functions Into Program

Nov 15, 2014

I have to make a numerical integration program, how I can write my code so that the user is able to write their own function that they want to integrate?

E.g. they would see the message: 'please enter your function' and would be able to write whatever they wanted e.g. 'x +5' then this would then be integrated by the program.

I have already written a program that can integrate a known function but would prefer that the user could choose their own.

View 2 Replies View Related

C++ :: Determine Roots Of Quadratic Equations?

May 23, 2013

I have given following exercise in my cpp book: Determine the roots of quadratic equations

ax^2 + bx + c = 0

using formula

x = -b +(plus-minus) (root)b^2 - 4ac/2a

i don't now how to write such code...

View 6 Replies View Related

C++ :: Finite Difference Method For Partial Differential Equations?

Nov 10, 2013

Calculated by the explicit scheme. Produces some very large numbers.

task:

[math] U_t = 3 (1,1-0,5 x) U_ {xx} + e ^ t-1 [/ math]
[math] U (0, t) = 0 [/ math]
[math] U (1, t) = 0 [/ math]
[math] U (x, 0) = 0.01 (1-x) x [/ math]

Need to find a solution with accuracy [math] 0.0001 [/ math] on the interval [math] T = 1 / a ^ *, where a ^ * = max a (x, t) [/ math] Plot graphs of functions [math] u (x ^ *, t), u (x, jt ^ *) [/ math] where [math] x ^ * = 0.6, t ^ * = T/10, j = 1,2,4 [/ math]

explicit difference scheme is as follows:

([math] $ u_t ^ {j +1}-u_i ^ j) / tau = 3 (1,1-0,5 x_i) (u_ {i +1} ^ {j}-2u_i ^ j + u_ {i -1} ^ j) / h ^ 2 + e ^ {t_j} +1 $ $ [/ math]

code of the program:

int main ( void ) {
setlocale(LC_ALL, "rus");
int I = 10, J = 30, i, j;
double T = 1.0/ pow(3.3, 0.5), h_x = 1.0/ I, h_t = T/ J, epsilon = h_t + pow(h_x, 2), c;
double **u = new double *[I + 1];
for (i = 0; i <= I; i++) u[i] = new double [J + 1];

[code]....

displays the following:

[URL]

View 2 Replies View Related

C++ :: Linear And Binary Summation?

Feb 6, 2015

I am trying to write a program that will output the contents of an array A into a sum hence title.

Here is my code so far...

#include <iostream>
using namespace std;
int LinearSum(int A[], int);

[Code]....

View 1 Replies View Related

C :: Use SIGNALS To Control Threads

Nov 11, 2013

I've to use SIGNALS to control threads. Here's my code without the use of signals as I'm no good at that

Code:

#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
}

[code]....

View 4 Replies View Related

C++ ::  threads To Take Sequential Turns

Jun 30, 2014

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

int turn = 1;
int counter = 0;
int t, n;

[Code] ....

I found this program in a forum and it creates 1 to t threads with each thread pointing to the next and the last thread pointing to the first thread and it allows each thread to sequentially take a turn until all threads have taken n turns. That is when the program ends.

My doubt is if we see in void *tFunc(void *arg) function, first thread locks the mutex and then wait there forever till it's turn comes.Lets say if I spwan 1000 threads and they have take 10 turns each sequentially and what if a 550th thread locks the mutex as soon as the program starts and waiting for its turn which will never happen because still (turn=1) which means it's first thread's turn and first 549 threads have to complete their 1st turn before this 550 threda's turn comes.Doesnt this result in deadlock?

View 2 Replies View Related

C++ :: Encapsulate Two Threads In A Class?

Apr 29, 2014

how to encapsulate two threads in a class?

View 1 Replies View Related

C++ :: Stopping Threads Without Using Local Var?

Aug 31, 2014

Here's my code,

#include <iostream>
#include <unistd.h>
#include <thread>
using namespace std;
void Blink();

[Code] .....

The problem is i don't want to use local vars , is ther anyway do end the loop safely(removing all the vars used in function and etc) without using a local var ?

View 3 Replies View Related

C/C++ :: Suspending And Resuming Threads

Apr 18, 2014

#include <stdio.h>
#include <pthread.h>
int i; // loop control variable
int *id; // array used to pass parameter of id
int nThreads; // #threads

[Code]....

I want to know where I am going wrong. I am strong in java but not in c so that may be my problem.

View 9 Replies View Related

C++ :: Creating And Terminating Threads?

Aug 31, 2014

I had a requirement where i needed to create a thread and if the execution of thread is not completed in 5 minutes i needed to terminate its execution and continue with other part of the code.

I used the below code to create the thread

_beginthread(FuncnCall,0,NULL);

HANDLE hThread = GetCurrentThread();

Then after this code, I used the below code to check for 5 minutes

for (int i=1;i<=0;i++) {
printf("Value of i=%d
",i);
if(threadFinished) {
break;
} else {
Sleep(1000);
}
}

After this if the value of "threadFinished" is false then i am terminating the thread like below

if(threadFinished == false) {
TerminateThread(hThread,0);
CloseHandle(hThread);
}

The Problem here is, after terminating the thread, the program abruptly closes by giving fatal error. Looks like memory leakage is happening after terminating the thread. Is it not the right way to safely exit the thread?

View 2 Replies View Related

C :: Running Linear Actuator Without Feedback

Jan 4, 2014

I am trying to do single axis solar tracker with linear actuator /rtc/ UNO. I have already done with feedback sensor.

Now Here I am trying to without feedback. Linear actuator specification: 24v , 3.2mm/sec as speed , 600mm stoke.

Desired angle calculation:
tracking start from 7am to 18PM, 11hours
Assumed degree: 7AM as -45 deg , 12.30 as 0 degree and 18 pm as 45 degree.
static float slope= 0.00227272727273;
static float intercept=- 102.272727273;

[Code] ....

How can i put time here. Coding for calculating Ton time and solve above equation. below i posted my code . I need it has to be modified little bit. i need to implement ton time actuator here.

I need function takes desired and actual angle , where actuator try to move to its actual desired position.

Code below in arduino version

Code:
double Desire_Degree;
unsigned int TS;
static float slope= 0.00227272727273;
static float intercept=- 102.272727273;
static int length;
double Actual_Degree;

[Code] .....

View 1 Replies View Related

C++ :: Merging Sets In Linear Time

Jan 5, 2014

I have two std::sets S1 and S2 which I need to merge.

I know that the largest element of S1 is less than the smallest element of S2.

the additional information about S1 and S2 should enable me to do the insertion of each element in costant time instead of log(N).

what is the fastest way to calculate the union of the two sets?

View 6 Replies View Related

C/C++ :: Binary And Linear Search Program

Mar 30, 2014

// ***This program uses a binary search and a linear search to see if a 3-digit lottery number matches the number on any of the player's tickets.***//

#include <iostream>
using namespace std;

[Code].....

bunch of errors and completely lost. what it's supposed to look like.

View 4 Replies View Related

C/C++ :: Continuous Linear Linked List

Feb 11, 2015

I'm trying to write a continuous linear linked list. But whenever I run my program and enter an option from my list, my switch statement gets highlighted in green and says "Thread 1: breakpoint 3.1. And then my program just stops. I'm wondering what part of the switch statement I've gotten wrong.

Here's my code.
#include <iostream>
using namespace std;
struct node
{
int key; node *next; };
node *l;
void print(node*list)

[Code] .....

View 13 Replies View Related

C/C++ :: Linear Search Not Found Output

Jul 3, 2014

How to return a message saying that the value searched for is not found. We had to pull the data in from a .dat, i won't let me attach it as a .dat so I attached it as .txt. I know my it's sloppy. I usually clean up what I can once it is working properly.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
int ccnt;
int size = 10;

[Code] ....

Attached File(s) : dat45.txt (273bytes)

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved