Skip to content

Conversation

gouthamdeepak1705
Copy link

#include
#include
#include
#include
#include
#include
#include // For rand() and srand()

using namespace std;

void parsec_roi_begin()
{
// Start of Region of Interest
}

void parsec_roi_end()
{
// End of Region of Interest
}

struct Result {
vector< vector > A;
};

Result read(string filename) {
vector< vector > A;
Result ab;
string line;
ifstream infile;
infile.open(filename.c_str());

int i = 0;
while (getline(infile, line) && !line.empty()) {
    istringstream iss(line);
    A.resize(A.size() + 1);
    int a, j = 0;
    while (iss >> a) {
        A[i].push_back(a);
        j++;
    }
    i++;
}

infile.close();
ab.A = A;
return ab;

}

vector gather(const vector< vector >& A) {
int n = A.size();
vector gathered_values; // To store gathered values

// Generate 1,000 random indices and gather the elements from those indices
for (int i = 0; i < 1000; i++) {
    int row = rand() % n;   // Random row index
    int col = rand() % n;   // Random column index

    // Gather the value from the matrix and store it in the result vector
    gathered_values.push_back(A[row][col]);
}

return gathered_values;

}

int main(int argc, char* argv[]) {
srand(time(0)); // Seed the random number generator
string filename;
if (argc < 3) {
filename = "2000.in";
} else {
filename = argv[2];
}
Result result = read(filename);
parsec_roi_begin();
vector gathered = gather(result.A); // Gather operation
parsec_roi_end();

// Optional: Print gathered values (for debugging or verification)
for (int value : gathered) {
    cout << value << " ";
}
cout << endl;

return 0;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant