C++ :: Eliminating False Sharing With TBB

Nov 9, 2013

So, as the title says, I'm trying to eliminate false sharing, or, eliminate sharing writes between threads with TBB. The question is how.

Normally I'd make an array whose size is equal to the number of threads, then locally write to a local variable and update the array only at the end of the thread.

But, of course, I cannot seem to get either thread id or total number of threads TBB uses. I found a reference to tbb::enumerable_thread_specific, which as I understand, is supposed to work for exactly this. But as soon as I added it, it hurt performance by ~60% instead of making it better.

How to do this properly? You don't really need to look so hard on how the algorithm works (I don't know either). I know it's not quite right right now due to race conditions, but I'll fix that later. I used a reference implementation that I copied™, and my task is to parallelize it.

The parts where the problem is right now is in red (of course, it's not all problems; it's only a subset of them).

Code:
#include <iostream>
#include <vector>
#include <fstream>
#include <ctime>
#include <algorithm>

[Code] ....

View 11 Replies


ADVERTISEMENT

C++ :: Eliminating Jumping Repetitions Of Different Orders

Feb 26, 2014

I wrote a program for class. It did its job, but I want to make it better. The program finds all of the Pythagorean triples between 1 and 100.

As you can see, the program will repeat the same Pythagorean triples but in different orders.

What I want to do is have the program repeat each Pythagorean triple once, regardless of whether the ordering is different. I have tried, but only came up with the solution to solving repetition that is consecutive. But the repetition for Pythagorean triples jump around.

I got stuck on how to eliminate jumping repetitions. I only know how to make it not repeat on consecutive entries.

View 5 Replies View Related

C/C++ :: Eliminating Jumping Repetitions Of Different Orders?

Feb 25, 2014

I wrote a program that finds the Pythagorean triples for class. It did its job, but I want to make it better. The program below finds all of the Pythagorean triples between 1 and 100.

As you can see, the program will repeat the same Pythagorean triples but in different orders.

What I want to do is have the program repeat each Pythagorean triple once, regardless of whether the ordering is different. I have tried, but only came up with the solution to solving repetition that is consecutive. But the repetition for Pythagorean triples jump around.

E.g., Pythagorean triple (6, 8, 10) appears. Then two Pythagorean triples later, (8, 6, 10) appears.

I got stuck on how to eliminate jumping repetitions. I only know how to make it not repeat on consecutive entries.

I nested one for loop, in another for loop that is nested in another for loop. One for loop for each of the values in the triple. The most nested loop is for the c value in a^2 + b^2 = c^2, and has an if statement: if( ((a*a)+(b*) == (c*c) ) , and then the program prints the numbers.

#include <iostream>
#include <cmath>
using namespace std;
int main() {
unsigned int a, b, c;
char con;
cout << "This program finds the pythagorean triples between 1 and 200.

[code].....

View 5 Replies View Related

C++ :: Eliminating Vowels From Text - Error In Program

May 11, 2013

I am trying this program for eliminating the vowels from a text.

#include <iostream>
#include <vector>
#include <ctype.h>
bool isVowel(char c, int indx) {
c = tolower(c);
if ((c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u'))

[Code] ....

Here is an error while debugging that while trying to match the argument list '(std::istream, std::string).

View 7 Replies View Related

C :: Eliminating Use Of Malloc / Free When Copying Char Arrays

Apr 6, 2014

This program works as expected:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
unsigned long long int address;
float current;
unsigned char pressure_units;
}

[code]....

But I don't like how I had to use malloc and free. Is there a different way to accomplish copying the string into a char pointer without resorting to dynamic memory allocation?

View 1 Replies View Related

C++ :: Sharing Data Between 2 Files

Aug 30, 2013

The problem is I have a function which sets some variables and I want to access the variables, but myfunc() is nested too deeply for me to pass a data structure all the way down and to return all the way up. The functions reside in different files. I'm not allowed to use extern structs (i.e. a global variable).

How to use a class and instantiate it in myfunc(). My solutions are:

- using the singleton class method
- static variables and function residing in the class (but I'm suspicious of this way. seems like it's just class variables masquerading as global variables.

View 2 Replies View Related

Visual C++ :: 2 Programs - 1 Dll Sharing Variable?

Mar 16, 2014

my goal:

have 1 program handle the UI

have that program store variables to a DLL

have the 2nd program grab the stored variables to reform some number crunching, without interfering with the UI program, and once done, have it drop the answers back into that DLL, so that the UI can grab it when it's ready.

I have made the 2 programs, + dll

What I've Achieved:

the first program accesses the dll, and loads up a variable (and stays connected to the dll, so that the Dll instance doesn't reset)

I've gotten the DLL to output the variable to make sure it's received it, and stored it to it's own global variable.

the second program connects to the dll successfully, but when it tries to retrieve the data, it returns 0's (NULL's)

My research:from what I've read, so long the dll is connected to a program, all additional programs will attach to the same instance.

how do I make the global variable in the dll be accessible to both programs? (without resorting to saving it to the HDD Idealy)

View 7 Replies View Related

C++ :: Sharing A Program - Sending Executable Files

May 22, 2013

I am just wondering if it is possible to send a project to someone via email - In a simple way, almost like you would install software from the internet, maybe a setup file, or something. The compiler I use "Dev C++" creates a .cpp file and an executable. Unfortunately, I cannot send that .exe file. How would you recommend sharing a program?

View 5 Replies View Related

C# :: Sharing Item List Object Between Two Forms

Nov 4, 2014

I've changed up my code to the retail checkout WFA I am trying to make. I have an item list filled with objects of the now globally accessible 'Item' class, but I'm having trouble.

Essentially, I want to send an object of the item class chosen from a dropdown menu to form2, where I will fill in certain blank attributes with data entered in form2's text boxes and comboboxes. The problem, it seems, is I need another itemlist in form2 that will hold the object being passed to form 2, so I can then pass all the information to textboxes on form3 (the receipt/review page). It's been more than a year since I coded with C#, and I've forgotten quite a bit. I was also not able to find any tutorials on building an item list without an associated combobox or droplist, which is what I need.

This is my item class (minus most of its properties so the page doesn't stretch).

class Item {
public string prodName;
public string fName;
public string lName;
public string ccNum;
public string ccProv;
public string shipAddr;

[code] ....

For anyone who didn't see my last question, I'm in a User Interface Design class, not a C# class. I know this probably isn't the best code out there, but for my purposes the program just needs to compile beginning to end and pass the data like it should.

View 1 Replies View Related

C :: 3 Students Sharing Their Meals - Settle Bills Equally

Sep 28, 2013

There are 3 students (0=John, 1=Peter, 2=William) sharing their meals. Who does the cooking, does the shopping and pays for the bills. End of the month they sum it all up and settle the bills equally. Who must pay the most is outputted at the top, while the person that collects most is at the bottom. Students that have to pay the same amount are listed in the same order as they are ordered in the input. (receiving same amount, the same). Total of the settlement are rounded to whole cents. Sometimes they loose a cent, sometimes they gain one.

So I started making a plan what the program is supposed to do. Pen and paper:

1. Sum of the total amount from all the meals.
JohnPaid+PeterPaid+WilliamPaid=Total
Total / 3 = FairShare

calculate difference of all three the students

if JohnPaid == FairShare
print John receives 0.00

if JohnPaid > FairShare
print John receives difference

if JohnPaid < FairShare
print John pays difference

etc. (same for Peter and William)

Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

/* type definition of student */
typedef struct student {
int who; /* 0=John, 1=Peter, 2=William */
float paid; /* amount that student paid */

[Code] .....

Example in/outputs:

<0 39.85>
<1 30.83>
<2 35.43>
Peter pays 4.54
William receives 0.06
John receives 4.48

<1 106.32>
<0 88.14>
<2 88.14>
John pays 6.06
William pays 6.06
Peter receivers 12.12

Looking at this code, I see a lot of global (general) variables. Do I need to adjust this skeleton code I received or should I just add code?

View 6 Replies View Related

C++ ::  if Statement Always False

Jun 26, 2013

i am trying to make a ticktacktoe game. I made a simple one with no ai but i decide to add an option to play against computer. And i code like that(i know this is really bad):

/*
Name: TickTackToeFinal
Copyright:
Author:
Date: 26.06.13 20:41
Description:
*/
#include <iostream>
#include <string>

[code].....

when i run the game its always play randomly(last if statements in bilgisayar functions.

not:bilgisayar means computer
zor means hard
orta means medium
kolay means easy
oyuncu means player
tur means round
oyun means game

View 7 Replies View Related

C++ :: True / False About Function Parameter

Sep 11, 2014

is it true or false

a function like void myfun(int num){} can receive type "int var" but can't receive type "const int var"

AND

a function like void myfun(const int num){} can receive both type "int var" and also type "const int var"

View 3 Replies View Related

C++ :: Boolean Function Not Returning False

Mar 24, 2014

I have a bool type function and set it to explicitly return false, but I am still getting true as the return.

#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[]){
double coeffs[3];
double roots[2];

[code].....

View 7 Replies View Related

C/C++ :: Palindrome Function Only Return False?

Apr 29, 2015

I have a text file that consists of:

1457887541
Madam
Able was I ere I saw Elba
Straw? No, too stupid a fad. I put soot on warts.
Class is cancelled today

And all of them are returning false as a palindrome and am not sure why that is so.

bool isPalindrome(const char *input){
int first = 0;
int last = strlen(input) - 1;

//begin loop to compare first position with last
while(last > first){

[Code] .....

View 3 Replies View Related

C++ :: How To Differentiate False Statements In A Function

Apr 2, 2013

I'm havin trouble outputing different false statements in a boolean function... I'm currently working on a "secret number game" program which must generate a secret number and inform the user if his/her guess number is to high, to low or correct. I know boolean return true and false.. If the number is correct, the true statement will appear, if false... THAT'S where my problem starts cause now I have TWO statements to output..In a Function.. How do I make my program able to tell if the number guessed is "too high" or "too low" ?

View 6 Replies View Related

C :: Comparison Is Always False Due To Limited Data Type Error

Feb 16, 2013

Code:

do {
printf("Edit the entry's cellphone number:");
scanf("%s", addressbook[4][num]);
length = strlen(addressbook[4][num]); //gets the length of the input (should be 10)
//checks if the input is composed of 11 elements wherein the first 2 are 0 and 9 respectively
for(i=0; i<11; i++){

[Code] ....

why do I get an error here?

Code:
if ((addressbook[4][num][0] == '0') && (addressbook[4][num][1] == '9') || (addressbook[4][num][i]>='0') && (addressbook[4][num][i]<='9') && (length=='11'))

And how do I fix this?

The error message is: comparison is always false due to limited data type

View 1 Replies View Related

C++ :: How To Switch Between Boolean True / False Logic Within Do / While Loop

Mar 25, 2014

I have a hit a snag in a number guessing game program. I was given a half-completed program and told to use functions to complete the missing pieces. It looks unwieldy, but this is how it is supposed to be. I have temporarily made the random guess value visible for troubleshooting purposes.

#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;
int welcome() {
cout << " Welcome to the hi-low game!" << endl;

[code]....

The issue lies within this piece of code:

checkGuess(guess, correct); done = false; //either true or false
} while (!done);
cout << "Congratulations, you got it!" << endl;
return 0;
}

I need to manipulate the Boolean variable done so that it registers as false when the user inputs a number higher or lower than the randomly selected value. However, if the user guesses correctly, done will become true and the program will end.

As it stands now, the program will not terminate, and if I set done equal to true like so:

checkGuess(guess, correct); done = true; //either true or false
} while (!done);
cout << "Congratulations, you got it!" << endl;
return 0;
}

Every number the user inputs will register as correct instead of the one right guess.

View 4 Replies View Related

C++ :: Palindrome That Takes A Vector Parameter And Returns True Or False

Apr 26, 2014

Write a function palindrome that takes a vector parameter and returns true or false according to whether the vector does or does not read the same forward as backward (e.g., a vector containing 1, 2, 3, 2, 1 is a palindrome, but a vector containing 1, 2, 3, 4 is not).

Code :
#include <vector>
#include <iostream>
using namespace std;
void palindrome(vector<int>);

[Code] .....

View 4 Replies View Related

C :: Program That Grades A True / False Quiz - Data Available In Text File

Oct 14, 2014

You are to write a C program that grades a true-false quiz. The quiz data will be available in a text file; here is an example:

Quiz #8 (09/22/14) (corrected version)
TTFTTFTFTF
0080 TTFTTFTFTF
0340 TTFTFFTFTF

The first line in the data file is a comment that you may assume can be up to 80 charac- ters long; it cannot be blank. The second line contains the answer key for the 10-question true-false quiz. The following lines in the data file contain a student's id number in column 1 followed by their answers for the quiz in column 2. A 0 (zero) on a line by itself indicates that there are no more students to process.

Write a program that first reads in (from standard input; more on this in a moment) the comment line and answer key as strings followed by each student's data. Store the student's id numbers in an array. You are to "grade" each student's quiz using the key provided fol- lowed by recording their scores (in a second array) in order to be able to print them out later. You do not need to use an array of strings or characters in your program. Write your program allowing for up to 100 students, and you may assume that at least 1 student will have taken the quiz.

You should create test data text files and provide the data to your program using redirection from the command line (see the sample run below). Your program should output the number of students who took the quiz, the average score, the best score, and a table showing each student's id, score, and grade. The formatting, spacing, and labels in your output should 1 match the sample run below exactly.

Your program should determine each student's grade as follows: if the score is equal to the best score b or b−1, give an A. If it is b−2, award a B. Give C's for any score that is equal to b−3 or b−4, a D for b−5 and an F for all others.

Alright So I'm just stuck at comparing the key answer with student answer here is my code comparing one student's answer with the answer key . is that right ?? One more thing for some reason when i try to print answer[0] the result is nothing why is that

Code:
#include<stdio.h>
int main(void) {
char comment[80];
char answer [10];
char studentans [10];
int n=0,i=0,x=0;
int ID[10];

[Code] .....

View 1 Replies View Related

C++ :: How To Create True False And Multiple Choice Questions Using Text Files

Jan 7, 2015

So im trying to create a quiz using c++ that incorporates three different types of questions. These are the standard one answer question, true false questions and multiple choice questions.

How to create the true false and multiple choice questions?

One way that i came up with looks like this

Question A answer1 B answer2;

View 2 Replies View Related

C++ :: Binary Search Function - Return True If Element Inputted By User Found In Array And False If Not

Nov 9, 2014

I was instructed to write a binary search function which would return true if an element, inputted by the user, was found in the array, and false if it was not. I'm not sure why, but my function always returns false. My code is as follows.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
//binary search function
bool search (int array[], int item)

[Code] ....

Why my code does not fulfill it's purpose???

View 7 Replies View Related

C# :: Sharing Variables From Login Form To Another Form

Mar 10, 2015

I have a form with 2 text boxes (Email and Password)

The user fills in the text boxes and clicks on the Log in button. The code behind the log in button does the following, First connects to a table (Users) in phpmyadmin. Next runs a SQL query (SELECT * FROM `users` WHERE Email = '" + sEmail + "' AND Password = '" + sPassword + "'") sEmail being the variable created from the text entered in Email text box and the same for password.

Next if the record count == to 1 it opens up the main menu form and if the record count == 0 it fails and the user does not get to the main menu.

All of the above is fine and working however what I want to do is take over a variable from the log in form to the other forms.

The code is below for the sign in button as all my code is behind that (I think this may be where I'm going wrong).

public partial class WelcomeForm : Form{
public static string connStr = "server = localhost; " +
"database = ppw5; " +
"uid = James; " +
"pwd = buster;";

[Code] .....

And the Main menu form where I'd like to take a variable over with me, lets assume the variable is the UserID from the database table that I pull from the dTable I created.

public partial class MenuForm : Form {
//Call the CloseProgram class and create a new method called ClassClose.
CloseProgram ClassClose = new CloseProgram();
WelcomeForm User = new WelcomeForm();
public MenuForm() {
InitializeComponent();

[Code] .....

View 7 Replies View Related

C++ :: Two Date Structures Sharing Same Date

Mar 28, 2014

I have two date/time structures which I'm populating, but when I populate the second one it sets the same values in the first. This is what I've got so far

tm *FirstDate = gmtime(&now);
tm *SecondDate = gmtime(&now);

cout <<"Enter your first date in the format dd/mm/yyyy" << endl <<">";
getline (cin,tempstring);

[Code] .....

View 2 Replies View Related

C++ :: Null Terminator Same As Null And Through False Value?

Feb 18, 2014

I am looking at one of the functions of an exercise:

void escape(char * s, char * t) {
int i, j;
i = j = 0;
while ( t[i] ) {
/* Translate the special character, if we have one */
switch( t[i] ) {

[code]...

Notice the while loop evaluates the current value in t to true or false. When we hit the null terminator, does that get evaluated as 0 and hence evaluates as a falsy value so the while loop exits?

View 1 Replies View Related







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