@@ -814,6 +814,7 @@ class AMSMessage
814814 _data(nullptr ),
815815 _total_size(0 )
816816 {
817+ CALIPER (CALI_MARK_BEGIN (" AMS_MESSAGE" );)
817818 AMSMsgHeader header (_rank,
818819 domain_name.size (),
819820 _num_elements,
@@ -832,10 +833,11 @@ class AMSMessage
832833 domain_name.size ());
833834 current_offset += domain_name.size ();
834835 current_offset +=
835- encode_data (reinterpret_cast <TypeValue*>( _data + current_offset) ,
836- inputs,
837- outputs);
836+ encode_data (_data + current_offset,
837+ inputs,
838+ outputs);
838839 DBG (AMSMessage, " Allocated message %d: %p" , _id, _data);
840+ CALIPER (CALI_MARK_END (" AMS_MESSAGE" );)
839841 }
840842
841843 /* *
@@ -881,26 +883,25 @@ class AMSMessage
881883 * @return The number of bytes in the message or 0 if error
882884 */
883885 template <typename TypeValue>
884- size_t encode_data (TypeValue * data_blob,
886+ size_t encode_data (uint8_t * data_blob,
885887 const std::vector<TypeValue*>& inputs,
886888 const std::vector<TypeValue*>& outputs)
887889 {
888- size_t x_dim = _input_dim + _output_dim;
889890 if (!data_blob) return 0 ;
890- // Creating the body part of the messages
891- for (size_t i = 0 ; i < _num_elements; i++) {
892- for (size_t j = 0 ; j < _input_dim; j++) {
893- data_blob[i * x_dim + j] = inputs[j][i];
894- }
891+ size_t offset = 0 ;
892+
893+ // Creating the body part of the message
894+ for (size_t i = 0 ; i < _input_dim; i++) {
895+ std::memcpy (data_blob + offset, inputs[i], _num_elements * sizeof (TypeValue));
896+ offset += (_num_elements * sizeof (TypeValue));
895897 }
896898
897- for (size_t i = 0 ; i < _num_elements; i++) {
898- for (size_t j = 0 ; j < _output_dim; j++) {
899- data_blob[i * x_dim + _input_dim + j] = outputs[j][i];
900- }
899+ for (size_t i = 0 ; i < _output_dim; i++) {
900+ std::memcpy (data_blob + offset, outputs[i], _num_elements * sizeof (TypeValue));
901+ offset += (_num_elements * sizeof (TypeValue));
901902 }
902903
903- return (x_dim * _num_elements) * sizeof (TypeValue);
904+ return ((_input_dim + _output_dim) * _num_elements) * sizeof (TypeValue);
904905 }
905906
906907 /* *
0 commit comments