There's a bank with 5 tellers and 1 queue. Customers arrive randomly at the bank like this :
- between 10 minutes before the hour and 10 minutes past the hour arrive on average 10 customers (random number between 1-19)
- at all other times arrive on average 2 customers (random between 0-4)
The customer at the front of the queue goes to the first available teller and spends on average 5 minutes on his transaction.
I need to simulate this for a period of 100 days, 9 hrs each day. Here's my code so far:
#include <mpi.h>
#include <iostream>
#include <fstream>
#include <queue>
#include <ctime>
using namespace std;
int main(int argc, char *argv[])
{
int rank, nproc, tellers[10] = { 0, 0, 0, 0, 0, 0 }, last_client = 0;
queue<int> q; //the queue of customers
ofstream ofile("out.txt");
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &nproc);
srand(time(NULL)+rank*nproc);
if (rank == 0) //Master
{
for (int i = 1; i <= 100; i++) //100 days
{
for (int p = 1; p <= 5; p++) // tellers are available at the start of each day
{
tellers[p] = 0;
}
while (!q.empty()) // queue is empty at the start of each day
{
q.pop();
}
for (int j = 1; j <= 540; j++) //540 minutes = 9 hrs
{
//-/flag
int minute = j % 60, rng;
if (minute >= 50 || minute <= 10) //avg 10 per min
{
rng = rand() % 19 + 1; //clients arriving this minute (1-19)
}
else //avg 2 per min
{
rng = rand() % 5;
}
for (int k = 1; k <= rng; k++)
{
q.push(last_client + 1); // put customers in queue
last_client++;
}
cout << "no clients = " << last_client << endl;
int min_time_teller = 0;
//flag
for (int m = 1; m <= 5; m++)
{
if (tellers[m] <= j)
{
min_time_teller = m;
break;
}
}
while (!q.empty() && min_time_teller > 0)
{
int tmp;
int cl = q.front();
MPI_Send(&cl, 1, MPI_INT, min_time_teller, 0, MPI_COMM_WORLD); // send the first customer in the queue
MPI_Send(&j, 1, MPI_INT, min_time_teller, 1, MPI_COMM_WORLD); // also send the minute the transaction begins ?
//cout << "send " << cl << " to teller " << p << " minute = " << j << endl;
q.pop(); // remove client from queue
MPI_Recv(&tmp, 1, MPI_INT, min_time_teller, cl, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
cout << "received " << tmp << " from " << min_time_teller << endl;
tellers[min_time_teller] = tmp;
min_time_teller = 0;
for (int m = 1; m <= 5; m++)
{
if (tellers[m] <= j)
{
min_time_teller = m;
break;
}
}
}
}
}
}
else //Slaves
{
int client = NULL, start_time, end_time;
MPI_Recv(&client, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
MPI_Recv(&start_time, 1, MPI_INT, 0, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
//cout << "teller " << rank << " received " << client << ", " << start_time;
if (client != NULL)
{
int time = rand() % 9 + 1; // time to serve the client
end_time = start_time + time;
MPI_Send(&end_time, 1, MPI_INT, 0, client, MPI_COMM_WORLD);
//cout << "Processing client " << client << " start= " << start_time << " for " << time << " minutes.";
}
}
MPI_Finalize();
return 0;
}
My program works ok up to a point where it just freezes with no errors (running it in cmd with the mpiexec -n 6 command) and i have to manually abort the execution. for example when i try running it for 1 day and 10 minutes(for easier debugging) i get something like this
Quote
no clients = 6
received 3 from 1
3 0 0 0 0
received 5 from 2
3 5 0 0 0
received 6 from 3
3 5 6 0 0
received 8 from 4
3 5 6 8 0
received 9 from 5
3 5 6 8 9
no clients = 9
no clients = 24
mpiexec aborting job...
job aborted:
[ranks] message
[0-5] process exited without calling finalize
---- error analysis -----
[0-5] on ASUS-PC
ConsoleApplication10.exe ended prematurely and may have crashed. exit code -1
---- error analysis -----
received 3 from 1
3 0 0 0 0
received 5 from 2
3 5 0 0 0
received 6 from 3
3 5 6 0 0
received 8 from 4
3 5 6 8 0
received 9 from 5
3 5 6 8 9
no clients = 9
no clients = 24
mpiexec aborting job...
job aborted:
[ranks] message
[0-5] process exited without calling finalize
---- error analysis -----
[0-5] on ASUS-PC
ConsoleApplication10.exe ended prematurely and may have crashed. exit code -1
---- error analysis -----
Am I approaching this right ? Is there a better way of keeping track of which tellers are available at the current time in the root(0) process ?
Also, I'm developing this under visual studio 2013 and I'm having trouble with it because i can't debug it because it's using multiple processes.. and from what I've found on google they had a tool for debugging mpi programs in 2010 but not in the 2013 version so is there any other way i can actually debug this program ?

New Topic/Question
Reply


MultiQuote



|