Categories
Mastering Development

Stack Overflow for Fractional Knapsack

I am fairly new to C++. I have implemented the fractional knapsack problem in c++ for the course “Algorithmic Toolbox” on Coursera: #include <iostream> #include <iomanip> using namespace std; int get_max_index(double A[], double B[],int l) { /* int A = array of value int B = array of weights int l = length of the […]

Categories
Development

2D matrix vector multiplication using mpi in C

I’m new to parallel programming, and my project is the two-dimensional matrix vector multiplication using mpi in C programming language. I have this multiplication function, but I don’t know exactly how to run it with mpi. Can you help me, please? I write these commands, $ mpicc -g -Wall -o matrix2d matrix2d.c -lm -c $ […]

Categories
C++ Development

Comparing double in C++, peer review

I have always had the problem of comparing double values for equality. There are functions around like some fuzzy_compare(double a, double b), but I often enough did not manage to find them in time. So I thought on building a wrapper class for double just for the comparison operator: typedef union { uint64_t i; double […]

Categories
Development

how to create loop to go though the array

#include <stdio.h> #include <iostream> #include <conio.h> #include <locale> using namespace std; class Equation { private: double a, b, c, d; public: double fun[4]; Equation() {} Equation(double a, double b, double c, double d) { fun[0] = a; fun[1] = b; fun[2] = c; fun[3] = d; } }; int main(int argc, char** argv) { for […]

Categories
Development

C intro – How to pass a parameter by reference in function?

I’m working on my intro C course assignment and I’m tasked with the following… Write code for a function that receives two parameters (a,and b) by value and has two more parameters (c and d) by reference. All parameters are double. From main, use scanf to get two numbers, then call the function, and then […]

Categories
Development

Can’t compile with gcc-7

I am trying to compile some code with GCC-7 on MacOS Catalina. The GCC-7 was installed using homebrew brew install gcc@7 The code is the following: #include <stdlib.h> #include <math.h> double distance(double *a, double *b, int d) { double dist = 0; for(int i = 0; i < d; i++) { dist += pow(a[i]-b[i],2); } […]

Categories
Development

Reading Data Files

I am writing a program in my AP java class and I am very confused. The program is supposed to read a data file using another program called EasyReader. The program consists of an Object class that finds the largest number, medium number, and smallest number. The Test class is supposed to read the data […]

Categories
Development

SUMMA matrix multiplication

I am trying to implement summa algorithm for matrix multiplication. I am using mpi library to implement it. My code looks like following: #include <stdio.h> #include <time.h> #include <stdlib.h> #include <math.h> #include “mpi.h” #include <string.h> #define min(a, b) ((a < b) ? a : b) #define SZ 4000 //Each matrix of entire A, B, and […]

Categories
Development

How to translate this Javascript snippet to C# [on hold]

Javascript: function bounds(a, b, c) { null != b && (a = Math.max(a, b)); null != c && (a = Math.min(a, c)); return a } Honestly, I don’t even understand what is going on here. If b isn’t null, then a gets set Math.max(a, b). if c isn’t null, a gets set from Math.min(a, c)? […]